Results 1 to 17 of 17

Thread: Using "ShellExecute" to Print PDF File

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276

    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

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    You could try something as simple as sendkeys ...

    eg:

    VB Code:
    1. 'Print code
    2.     DoEvents
    3.     'send Alt + F4 to shutdown the Adobe app.
    4.     SendKeys "%{F4}"

    just a suggestion...
    -= a peet post =-

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276
    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:
    1. ShellExecute Me.hwnd, "Print", sFile, vbNullString, vbNullString, 1
    2.  'Print code
    3.  DoEvents
    4.  'send Alt + F4 to shutdown the Adobe app.
    5.  SendKeys "%{F4}"

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    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 ?
    -= a peet post =-

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276
    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.

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276
    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:
    1. Pdf1.LoadFile("c:/index.pdf")
    2. 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.

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Use the PrintAll method instead.

  9. #9
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Damn, Joacim!! that was a great tip.

    JemimaChadwick, I'v tested it using printall like this

    VB Code:
    1. Private Sub Command1_Click()
    2.     Pdf1.src = "C:\TEST.PDF"
    3.     Pdf1.printAll
    4. End Sub

    way better than using shellExecute

    Thanks Joacim.
    -= a peet post =-

  10. #10
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Joacim, do u know if we are free to distribute this ocx ?
    -= a peet post =-

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    No problem! The reason that the Print method doesn't work from VB is because Print is a reserved keyword.

  12. #12
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Joacim, do u know if we are free to distribute this ocx ?

    I'm getting all excited here
    -= a peet post =-

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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.

  14. #14
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Yes u'r right, I could probably put the original setup file for the AR onto my CD when distributing.

    Thanks again for this great tip... Well I'm off to play with my new OCX then

    See u chaps later
    -= a peet post =-

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276
    Wow, it works fine...i messed up with the .loadfile instead of the src property of the component.
    Thanks again.
    - Jemima.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276

    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.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    276

    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
  •  



Click Here to Expand Forum to Full Width