Print a pdf from asp

M

moony marouane

Hi Everybody

I have a problem opening a file with ADODB.Stream when <HTML> exists on the
same page

here is the code I use :

===================================
<HTML>
<%
Response.ContentType = "application/pdf"
Const adTypeBinary = 1
Dim strFilePath
strFilePath = PathOfTheFile
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
Response.BinaryWrite objStream.Read
%>
<BODY onLoad="javascript:window.self.print();">
</BODY>
</HTML>
<%objStream.Close
Set objStream = Nothing%>
===================================

I specially use this code to open pdf files and print them after, when I
remove all html tags and leave just the asp code, the pdf fileget opened
correctly, but when I add thez html to code to print it I got page full of :

===================================
I¼îRw4?¾³?*^E,>?Oµàb?vàX?>ê7??#?-?ô?bp[^?·9?>?´£1ô?m?`\ ?LJ÷ô
1??M}ô?¤?o"?,??c3?î/f{T­ùù´??â'³³? .<?±à?u?l(8?î??
?pk~û?é'A?>M¼÷~³i¤>?Ka?OxP!¹?
?"c?f?eCù-»??ç#{/?zô??,r?>²i+¹´<i§?.?8:¸sp¤s?P??¯???/@e?Q??",
'-?½a;?`?<êJZ?@ ??5??? ?r?r?¦?j?>"? dq?vT ?HgC½T¶\Nf;????-ec?=?³z
2<¦X¨Q}c H?#>?8¨E})fc!?ê5??R?^o¦"¸Hü?G?,è?^mU6?"??M$?? /6J?U..Ae?
??%??¬???T?²m??fAca?#?B­?sQ?î»??1wO~??E?¥²éwJé"¹?`?}
x??P?|"?,O¼?V$?#?.<?¦oXF¥Ol?J,??®¬¢²????ë???'
T?*./H£&?¾±·V!b?.?8??׫l?Z?´??·S??· S,è<«U?^dI>fè? IC~??x[3?¨?&h²
u?çlpck&^M-«l?dhP¶?Y׫?e#ê9?¯B?K+? ?¼~??{???6?O sH???A?~
",?g?R®Wµ?¦?f?è??D??(?OP7??²?zB×O?[`;,???¦?4?]?]?"M??`"
j÷"Zd{!>±??oO?ü@'?H|{l¨n?!?>??1âµ?·Wlx.?R{lI"??1, 
'??çk=_¶l?¶*°$?v²6\>9EcN??h´½cè <>jI.??®9>9?<?!l.'
mïz?????L?k?5"?b³sb?p??<´½cè JRj©]6??wX0>¹(û?9?+¶$b+?¬?"?³
?ü½H??K6?Wu?~?½9>bY?Jo,-??ô? T??@-°A???????6? 6³?.??`¯½??r°x?b¥?A?
b°uZ=c??¨6g?a;,T²??/s?½Ce{?f>'¬??" ?°¥?¦26o'
?~¹½C?>ir?eDf{"´9?4??JS(â2?Y ×??³?De?j'??rS?e?l(ïl?}???
©?2e?A`???K?j¨¤?A?>;?? @S6\?¸r3?¾??.?9»¸°wl'O
??.@³.C?8?b½]¢T1??_?y¥.|?\h??¶ mT<-?"÷0qd²?L>lü¯«ï?
¨V??????fpd9t¦¤<?h×_¼?O·%{Oe±??2%÷-b<O ?v¼5}???µST?*90??âc³â'?b??"??-:¤
¶µz6c)?????%,·?é?·>?O¸N?mx?³à?Z?%îüP'{QTZd3?¨¼??µ.k@P5?5­)3??d??b î????
'?vr´§?¾?T>?M¬??IH ?Lb?.??c?&?¶vè?V?j6«??V>?+?NI[?1£,?^I")¤9'
#A9??:6H?9?ü?d­Ae¶Kë'.?s?V???V ¸?Cp1?qg?h
'??÷b¯Q1¾V?´ôaô?4¢KG!&½J"®??WF½V«7?%{?6u' ??" ?j"
?ç³??ë³=D@S¶c??N¯??
*ZI>o??fK¦T$Tdxr¼z+¨?¶¹???²6^}?yü]!?ü©y©???yé?¸c{¤?f £?.?¢^tU)!¶d >
1 ?3<¥W??e?µfWag«deTM³qâ ?­?A}üü?¸±[ac1?]X?l?6??l0?Hï?Gn½NWz??U5û¤?°
U¶?Xlè?ê???&êV?£m ??F???\XClO®?ë?M<??
TKLSe?®x3?^??·,N?¶²?×P?"?????a?s(©6e?ùô?L²3?h<;C??"
?b¶????:6[?AU¾"
??8?êg6CJ-??b«"y±?o³pa?¶^â"*?QBù????R¹£÷f3??M½`»?t?d-³T?³_}[J-ûa??
??"~2C"^l?????7µ.^*ü??????· )??T?4lm?B?¹??u²U#?é >9r?¾"?´??¹|¹?P\¸??"
2[!/¶u9r?3x^ü?U9.1???3<|E?-L"i???¯².-y?o? ûQ"ק?8j-??¯xî?¶. ?'P#F
'?0??¤½?b¥{??$??²)'????|G???[?l?*¶·\¦x?H'?>¸
gIh?|Z??¬?bL¬??m?<F"!¨·.7ü??..~¶$
===================================

and the print dialog box.

what's wrong with my code.

Thanks in advance

Moony
 
R

Ray Costanzo [MVP]

You can either return the binary PDF file, or an ordinary HTML file. You
can't mix them together like that. I believe that Acrobat Reader supports
javascript itself and you can put some sort of "print on load" statement in
the PDF (if that's an option for you), but that would be something for the
Acrobat experts to explain, I reckon. Or, just rely on the fact that most
people know how to click a print button and just give the PDF. Even if what
you were trying to do would work, the user would still have to confirm that
he wants the document to print.

Ray at work
 
M

moony marouane

Many thanks Ray for your reply..
I got it now, but what if I want to print the pdf file without opening it,
using his path (the path I use to open it, in the code I put in my first
post.), could it be possible??
Thanks again.
Moony
 
R

Ray Costanzo [MVP]

~Perhaps~ it's possible with scripting in the PDF, but I doubt it,
especially considering that you'd have to open the pdf to get the scripts to
run. Even if you can do this, do you really want to just assume that your
visitors wants jobs being sent to their printers without their knowledge?
What happens when someone's default printer is print-to-text-file or
something?

Ray at home
 
M

moony marouane

Actually I have in front of each file name (in the asp page that lists those
files) 3 links (download / open / print), the 2 first links work fine
(download / open), now I'm working on the third link (print), that means
that my visitors do know that they're going to print that file when clicking
on the print link.
Now what about the possibility to print without opening.
I guess that's impossible.

Thanks again Ray.
 
K

Kyle Peterson

if you want to do that you need away from web page technology and consider
making a little application that the user runs on their local system. It
would grab the files over the internet and print them out automatically.

its not a topid for this newgroup... its desktop app programming..
 
M

moony marouane

You mean, an application that visitors should install on their local
machines before printing???
If yes, I think it's impossible coz it's a hosted website not an intranet,
and I can't know all visitors...
correct me if I'm wrong.

Moony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,037
Messages
2,570,371
Members
47,013
Latest member
JewellChes

Latest Threads

Top