I have been looking online for some time now, but I still haven't figured out how to print a PDF file in Delphi without showing the document itself, or a print dialog. I just want to open a file without showing it, and print it to the default printer.
I'm trying to print a batch of PDF documents, and there is no need for user interference.
When you want to print a document without opening it, simply drag the document file to the correct printer icon on your desktop. You can drag multiple files simultaneously and they will print, but not in any particular order. Next week's tip will explain how to set up a drag and drop PDF creator.
There are some different possibilities to print PDFs... it depends whether you can require Adobe Reader to be installed (I don't know if you want to distribute your tool or just use it yourself).
1) It is possible to load the ActiveX control of Adobe Reader and use it for printing
pdfFile.src := 'filename.pdf';
pdfFile.LoadFile('filename.pdf');
pdfFile.print;
2) You can print PDFs with Adobe Reader itself (could be done with FoxIt too)
ShellExecute(0, 'open', 'acrord32', PChar('/p /h ' + FileName), nil, SW_HIDE);
3) You could also use Ghostview and Ghostprint
ShellExecute(Handle, 'open', 'gsprint.exe', PChar('"' + filename + '"'), '', SW_HIDE);
4) Or you could use a third party library... There are some available, but not all of them are free
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With