2

I want to print a PDF from Delphi directly (Version 6.0, I know it's old stuff, but they use it here...).

So far I used the following command:

printCommand := 'print';
printerInfo := '';

ShellExecute(Application.Handle, PChar(printCommand),
    PChar(documentToPrint), PChar(printerInfo), nil, SW_HIDE);

But the problem is, that Adobe always opens when doing this (not opening the PDF, but just appearing as "empty").

I do not want to open Adobe, because then the operator always has to close the Reader then. It would also be OK if Adobe Reader closes after printing. I do not want to invoke Adobe Reader directly, because if path, name or PDF software changes it should still work! So it would be good if I can use win standard program. So the same should work if for example Ghost Reader is installed as default PDF software. But as said it should not open or at least close after printing job.

I also want to avoid to create a new process and then terminate or things like that.

Michael
  • 706
  • 9
  • 29
  • 2
    duplicate of http://stackoverflow.com/questions/2055307/delphi-how-to-print-a-pdf-without-showing-it. – Peter Jun 03 '13 at 07:57
  • This behaviour all depends on the specific installation and file associations on the target machine. You cannot expect to exert control using `ShellExecute`. You'll need to rethink your approach if you want a cleaner UI for the user. – David Heffernan Jun 03 '13 at 08:04
  • OK, found a solution to my problem. Not that satisfying, but OK. I installed Foxit Reader. When called with `ShellExecute(0, 'open', PChar('C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe'), PChar('/t ' + documentToPrint + ' /d'), nil, SW_HIDE);` then Foxit Reader prints without starting up. As a fallback I do the normal `print` as above if Foxit is not arround. – Michael Jun 04 '13 at 06:23

0 Answers0