AccessBlog.net

News, links, downloads, tips and tricks on Microsoft Access and related

About Me Search
Alex
Name:Alex Dybenko

Location:Moscow, Russia

Thursday, January 24, 2008

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.

 

Technorati tags:

11 Comments:

Anonymous Anonymous said...

This report to PDF code works well. It uses DLLs that convert from snapshot format to PDF.

9:37 PM  
Blogger grovelli said...

Ciao Alex!!! :-)
When you call the PrintPDF function, what do you use as FileName, an exe file, an snp file or a pdf file?

2:24 PM  
Blogger Alex Dybenko said...

Ciao Giorgio!
Should be pdf file

2:26 PM  
Anonymous Anonymous said...

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

12:25 AM  
Blogger Alex Dybenko said...

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

7:41 AM  
Anonymous Anonymous said...

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

8:07 PM  
Blogger Alex Dybenko said...

Sorry, this i don't know

9:06 AM  
Blogger DataPlus - Custom Data Services said...

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

11:25 PM  
Anonymous Anonymous said...

Many-2 Thanks for this code....

2:06 PM  
Blogger ALioune Badara Tall said...

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?

2:27 AM  
Blogger Alex Dybenko said...

Hi,
you have to use this library to save filed to disk, and then print: http://www.lebans.com/oletodisk.htm

7:32 AM  

Post a Comment

Links to this post:

Create a Link

<< Home