[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
Re: Printing pdf or doc files
Is all you want to do is print it as your thread title indicates?
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.
Re: Printing pdf or doc files
Re: Printing pdf or doc files
Try the ShellExecute API with "Print:" instead of "Open:" or "mailto:" ;)
Re: Printing pdf or doc files
Quote:
Originally Posted by Hack
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.
Re: Printing pdf or doc files
Do you know the caption of the window?
Re: Printing pdf or doc files
Quote:
Originally Posted by Hack
Do you know the caption of the window?
It's "Setting work".
Paul.
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. :D
VB Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const WM_CLOSE = &H10
Private Sub cmdCloseApp_Click()
Dim lngCloseIt As Long
lngCloseIt = FindWindow(vbNullString, "Adobe Reader - [Progress Reports]")
PostMessage lngCloseIt, WM_CLOSE, CLng(0), CLng(0)
End Sub
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.
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. :)
Re: Printing pdf or doc files
Thanks to everyone who read and/or answered this thread. This forum is an amazing resource!
Paul.