Printing PDF from code
Normally you can print document using ShellExecute API with Print parameter. This also works for PDF, but leaves Acrobat Reader open. Imagine what can you get on a screen after multiple document printing? But fortunately - there is a way to close it after print, using old technology - DDE (remember this one? It was the only way to communicate with external program before OLE Automation). Here a procedure to print PDF files from VBA code. Originally I found some parts this code on internet, but can't find source anymore. So if you saw parts of it somewhere - please let me know, I will put a link and reference message.
Now I am posting VBA code in separate HTML pages on PointLtd site, after several tries to find a good way to post code here this way looks more attractive for me, and hopefully for readers also.
11 Comments:
This report to PDF code works well. It uses DLLs that convert from snapshot format to PDF.
Ciao Alex!!! :-)
When you call the PrintPDF function, what do you use as FileName, an exe file, an snp file or a pdf file?
Ciao Giorgio!
Should be pdf file
Hi Alex,
Thank you for your code.
It works fine and helped me a lot
I still have one question.
Is it also possible to set the number of copies that must be printed in the code?
If you could post that code it would be great.
Thankx in advance
Ronny
Hi Ronny,
i think you can run FilePrintSilent command required number of times
strCmd = "[FilePrintSilent(" & Chr(34) & FileName & Chr(34) & ")]"
DDEExecute lngChanel, strCmd
DDEExecute lngChanel, strCmd
DDEExecute lngChanel, strCmd
Alex,
Thankx for your reply. I will test it later.
One question of a co worker of me popped up:
If a pdf file exist out of several pages. Is it then possible with your code to print some of the pages?
For example: a pdf file exist out of 10 pages. In adobe it is possible to say print from page 3 till page 8 by typing "3-8" into the pages box of the print window.
So hopefully you have also a solution for this
Greetz
Ronny
Sorry, this i don't know
Thank you Alex, this is exactly what I needed. Amazing how difficult such a simple thing like printing an external PDF can be.
Sincerely appreciate this.
Bonnie
Many-2 Thanks for this code....
Hello,
I am new in Access
However, I have a field that contains files Ole and I would print a button that pdf files that are in this field
I Quanq inserts the code in a module, he writes: The object does not contain automation object "print"
What should I do?
Hi,
you have to use this library to save filed to disk, and then print: http://www.lebans.com/oletodisk.htm
Post a Comment
<< Home