|
-
Aug 7th, 2001, 02:27 AM
#1
Thread Starter
Hyperactive Member
Using "ShellExecute" to Print PDF File
I am using the ShellExecute API to Print PDF Files. This is printing fine but it leaves the Acrobat Application Open. I want to print the files without opening the Acrobat Application or atleast be able to close the Application myself...
Can someone help?
- Jemima
-
Aug 7th, 2001, 03:49 AM
#2
-= B u g S l a y e r =-
You could try something as simple as sendkeys ...
eg:
VB Code:
'Print code
DoEvents
'send Alt + F4 to shutdown the Adobe app.
SendKeys "%{F4}"
just a suggestion...
-
Aug 7th, 2001, 04:16 AM
#3
Thread Starter
Hyperactive Member
thanks Peet, but i didn't get a solution. I pasted the code you suggested right beneath the ShellExecute Call....Nothing happened....The Appln is still open...Am i wrong somewhr?
- Jemima
My code :
VB Code:
ShellExecute Me.hwnd, "Print", sFile, vbNullString, vbNullString, 1
'Print code
DoEvents
'send Alt + F4 to shutdown the Adobe app.
SendKeys "%{F4}"
-
Aug 7th, 2001, 04:23 AM
#4
-= B u g S l a y e r =-
Jemima,
no u'r probl. right... tested it my self. It works from time to time.. so its not a good solution.. sorry... maybe we can find another way to do it...
anyone ?
-
Aug 7th, 2001, 11:24 PM
#5
Thread Starter
Hyperactive Member
Peet, the last argument to the ShellExecute method SW_SHOWNORMAL or any other is not accepted in my Project. In the sense that in my actual Project Application it says "Variable Not Defined"....but its confusing when the constant is accepted in a new VB project file. I hope i am makin sense to u...
Moreover, i borrowed this code from ur contribution to one another poster (gegangen)...he replies to u that it worked fine...yes it does! But in a New Project.
Also, is thr something i have to include to get the handle to the window using GetDesktopWindow() ? The Compiler doesn't recognise the method....Right now i am using Me.hwnd. But i think i can do without it also...
Pls find time to reply to this query .....
- Jemima.
-
Aug 7th, 2001, 11:39 PM
#6
You must declare the SW_xxx.. constants yourself if you want to use them.
But you really don't have to since VB has its own:
vbNormalFocus
vbHide
vbMinimizedFocus
... and so on... See MSDN Library about the Shell function to see them all.
Using SendKeys will only work if you give the application, Acrobat in this case, enough time to start and execute the print command.
An other suggestion is to use the Acrobat Control for ActiveX instead of using ShellExecute.
If you can't find it in your Components dialog have a search thru your disk after PDF.OCX and use the Browse button in the Components dialog.
By adding this control to a form you actually turn the form into a Acrobat Reader. Now you can simply open a PDF file, print it and close your form.
Best regards
-
Aug 7th, 2001, 11:56 PM
#7
Thread Starter
Hyperactive Member
JA,
thanks for the reference to the Constants...i found them...
Reg. the PDF Component, i did try it earlier but it seems to be a Container component and doesn't print the PDF. Infact the Print method raises a runtime exception: "Object doesn't support this property or method".
The code that i used is here:
VB Code:
Pdf1.LoadFile("c:/index.pdf")
Pdf1.Print
Can you gimme some code samples to go about the use of this component?
Peet,
The ShellExecute doesn't open the Acrobat Application Window... but leaves an instance of its EXE running...How do i kill this? For all this, wouldn't it be better to use a PDF Component Object itself. Pls help.
thanks,
Jemima.
-
Aug 8th, 2001, 12:03 AM
#8
Use the PrintAll method instead.
-
Aug 8th, 2001, 12:08 AM
#9
-= B u g S l a y e r =-
Damn, Joacim!! that was a great tip.
JemimaChadwick, I'v tested it using printall like this
VB Code:
Private Sub Command1_Click()
Pdf1.src = "C:\TEST.PDF"
Pdf1.printAll
End Sub
way better than using shellExecute 
Thanks Joacim.
-
Aug 8th, 2001, 12:09 AM
#10
-= B u g S l a y e r =-
Joacim, do u know if we are free to distribute this ocx ?
-
Aug 8th, 2001, 12:09 AM
#11
No problem! The reason that the Print method doesn't work from VB is because Print is a reserved keyword.
-
Aug 8th, 2001, 12:11 AM
#12
-= B u g S l a y e r =-
Joacim, do u know if we are free to distribute this ocx ?
I'm getting all excited here
-
Aug 8th, 2001, 12:13 AM
#13
I don't think you can distribute the component by itself. But Acrobat reader is free (and most people that's on the Net has it) and the component is a part of that.
-
Aug 8th, 2001, 12:17 AM
#14
-
Aug 8th, 2001, 12:34 AM
#15
Thread Starter
Hyperactive Member
Wow, it works fine...i messed up with the .loadfile instead of the src property of the component.
Thanks again.
- Jemima.
-
Aug 8th, 2001, 02:52 AM
#16
Thread Starter
Hyperactive Member
Another one
Peet, JA,
Now, as the next step, I need to trace the Printer Queue n figure out if all the files that were spooled have been successfully printed. At any point of time thr can be atmost 4 PDF Files(from my application). If so, i should update a Flag in the database ... if not i need to prompt to the user.
I dunno how to trace the Printer Queue. Is thr a way out?
thanks,
Jemima.
-
Aug 9th, 2001, 11:02 PM
#17
Thread Starter
Hyperactive Member
Solved
hey this was solved by a code given to me by John. It is done using a list of APIs. The Link is at
Accessing the Printer Queue
- Jemima
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|