PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Using PDFSharp to print: how can I suppress Adobe window?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1933
Page 1 of 1

Author:  ilyaz [ Tue Mar 06, 2012 3:02 pm ]
Post subject:  Using PDFSharp to print: how can I suppress Adobe window?

I have a simple C# utility that invokes PDFSharp to send a PDF file to a printer. However, it seems to behave inconsistently on a Windows 7 machine. Here's the code

Code:
PdfFilePrinter.AdobeReaderPath = "C:\\Program Files\\Adobe\\Reader 10.0\\Reader\\AcroRd32.exe";
PdfFilePrinter printer = new PdfFilePrinter(fileToPrint, printerName);
try
{
   printer.Print();


When testing I launch the utility from the command line several times in a row processing a bunch of PDF files one file at a time. During some of these runs, a small Adobe window pops up (see attachment). Unless I manually close this window, printer.Print() will never complete, which is a problem since I need to batch process hundreds of files at a time.

When this happens seems to be random. Sometimes it happens when the 1st test file is being processed and sometimes it's the 5th or the 7th.

How can I either ensure that this window does not appear or suppress it automatically if it does?

Attachments:
adobe_screen.jpg
adobe_screen.jpg [ 51.58 KiB | Viewed 4049 times ]

Author:  Thomas Hoevel [ Tue Mar 06, 2012 3:46 pm ]
Post subject:  Re: Using PDFSharp to print: how can I suppress Adobe window?

Hi!
ilyaz wrote:
When testing I launch the utility from the command line several times in a row processing a bunch of PDF files one file at a time.
The source code of PdfFilePrinter is included.
It was developed for Adobe Reader 7 and contains a hack: if no instance of Adobe Reader is running, it starts a new one.

So if you create several PdfFilePrinters in a very short time, more than one of them may find there's no Adobe Reader running - and more than one gets started (one loading invisible, others loading with a Window).

If that is the problem, then you'd better have one process that does all the printing - and the command line utility only adds print jobs to the queue of this service.

PdfFilePrinter is just a helper that calls Adobe Reader with some command-line parameters. You can vary the code and/or the command-line parameters to see if that makes a difference.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/