Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: How to print a PDF without showing it?

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.

like image 288
Liezzzje Avatar asked Jan 13 '10 08:01

Liezzzje


People also ask

How do I print directly without opening a PDF?

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.


1 Answers

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

  • http://www.wpcubed.com/products/pdfviewer/index.htm
  • http://www.quickpdflibrary.com/
  • http://www.gnostice.com/PDFtoolkit_VCL.asp
like image 178
Leo Avatar answered Sep 22 '22 14:09

Leo