Results 1 to 12 of 12

Thread: [RESOLVED] Printing pdf or doc files

  1. #1

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Resolved [RESOLVED] Printing pdf or doc files

    Is getting VB to use Acrobat the only approach to doing this? (it's a shame users would then need to have or install an extra programme).

    If it *is* the only way, will Acrobat Reader (and/or Word Reader, or whatever it's called) do the job or would the user have to have the full, expensive versions for it to work?

    Thanks in advance,
    Paul

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printing pdf or doc files

    Is all you want to do is print it as your thread title indicates?

  3. #3

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Printing pdf or doc files

    Quote Originally Posted by Hack
    Is all you want to do is print it as your thread title indicates?
    Yes.

    Paul.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printing pdf or doc files

    Have a look here

  5. #5
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Printing pdf or doc files

    Try the ShellExecute API with "Print:" instead of "Open:" or "mailto:"
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  6. #6

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Printing pdf or doc files

    Quote Originally Posted by Hack
    Have a look here
    Yes, that works a treat, many thanks, but it gives the focus to Acrobat and doesn't close it when it's finished. Is there a way to stop the former and do the latter?

    Paul.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printing pdf or doc files

    Do you know the caption of the window?

  8. #8

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Printing pdf or doc files

    Quote Originally Posted by Hack
    Do you know the caption of the window?
    It's "Setting work".

    Paul.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printing pdf or doc files

    My test document is called "Progress Reports". Change as approrpriate. You will need to feed this the exact caption and it will work like a charm.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    4. (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    5.  
    6. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
    7. (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    8. ByVal lParam As Long) As Long
    9.  
    10. Private Const WM_CLOSE = &H10
    11.  
    12. Private Sub cmdCloseApp_Click()
    13. Dim lngCloseIt As Long
    14. lngCloseIt = FindWindow(vbNullString, "Adobe Reader - [Progress Reports]")
    15. PostMessage lngCloseIt, WM_CLOSE, CLng(0), CLng(0)
    16. End Sub

  10. #10

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Printing pdf or doc files

    Thanks for that!

    This is most odd, though - I pasted in your new declarations but not the actual code for cmdCloseApp_Click and I now find that my app prints the pdf without losing focus to Acrobat! An instance of Acrobat is still loaded, though (but I can live with that because users will typically print out 5 or 6 docs at a time - what I didn't want was for Acrobat to be the topmost window after the print call).

    I wonder why your first code appeared not to behave how I wanted but now it does!

    Paul.

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printing pdf or doc files

    Quote Originally Posted by paulorton
    I wonder why your first code appeared not to behave how I wanted but now it does!
    Without being able to look at your program and see how it does what it does, this is diffcult to determine.

    However, if you consider this resolved, would you please pull down the Thread Tools menu and click the Mark Thread Resolved menu item? That will let everyone know that you have your answer.

    Thank you.

  12. #12

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Printing pdf or doc files

    Thanks to everyone who read and/or answered this thread. This forum is an amazing resource!

    Paul.

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