.NET API automation

About the programming interface for the virtual PDF printer driver.

Moderator: jr

.NET API automation

Postby myers.group » Wed May 01, 2013 7:39 pm

I am using the C# .NET API. Using the following snippet extracted from a method I wrote to append a file to a given PDF (this code came almost exactly as is from the online documentation)...

string printerName = PdfUtil.DefaultPrinterName;
PdfSettings pdfSettings = new PdfSettings();
pdfSettings.PrinterName = printerName;

// set output PDF name...
pdfSettings.SetValue("Output", <output PDF file name>);

// disable dialogs (go quiet!)
pdfSettings.SetValue("ShowSettings", "never");
pdfSettings.SetValue("ShowSaveAS", "never");
pdfSettings.SetValue("ShowProgress", "no");
pdfSettings.SetValue("ShowProgressFinished", "no");
pdfSettings.SetValue("ConfirmOverwrite", "no");
pdfSettings.SetValue("OpenFolder", "no");

// added to append subsequent outputs in batch to working PDF...
pdfSettings.SetValue("AppendIfExists", "yes");

// set statusfile output name and make sure it is not there
string statusFileName = <output directory> + @"\converter_status.ini";
if (System.IO.File.Exists(statusFileName))
pdfSettings.SetValue("StatusFile", statusFileName);

// suppose to suppress this dialog... but it seems to have NO EFFECT!!
pdfSettings.SetValue("ShowPDF", "no");

// set output settings...

// output...
PdfUtil.PrintFile(<file to append>, printerName);

// wait for statusfile signalling completion...
PdfUtil.WaitForFile(statusFileName, 60000);

It ALWAYS, WITHOUT FAIL, will popup Adobe PDF reader each time "PdfUtil.PrintFile()" is called, and then will pause the output until I close Adobe reader. If I call it several times, in succession, in an unattended process, I must close Adobe reader before appending the next file. If I uninstall Adobe reader, the processing fails with an error stating that no application is associated with file type (eg PDF). I also assume that removing the "WaitForFile" command will simply cause it to fail upon adding the next file because reader has it open from the previous output.

It appears that, when using the API interface, there is no way to suppress this. However, if I print from an external program using the user interface configuration, you can suppress this dialog and print as much as you wish (no dialogs or preview). That leads me to suspect that this is not a design flaw of some kind, or a conflict with something in Windows.

What I am trying to accomplish is to combine multiple files to a single PDF (combined report) output file in an unattended service.
As I see it, there are 4 possibilities:
1. I missed one or more settings not discussed before (and not mentioned in the example on which this code is based). For example, I added the "AppendIFExists" setting which was not part of the original example, so perhaps there is a missing setting related to that.
2. Full suppression through the API is only available in the purchased version
3. This is a bug
4. This is a limitation of some kind (which does not make sense but I suppose is remotely possible)
Posts: 1
Joined: Wed May 01, 2013 6:56 pm

Re: .NET API automation

Postby mforland » Fri Aug 02, 2013 11:23 am

Did you find a solution on this one? I've got same problem.

Posts: 1
Joined: Fri Aug 02, 2013 11:20 am

Re: .NET API automation

Postby jr » Tue Aug 06, 2013 1:25 pm

The PrintFile API call will ask Windows to print the file. Windows will look for a program registered in the registry to print files of the selected type. This is normally Adobe Reader for PDF files. The Adobe Reader does not close automatically after printing. This is a well know "feature" of the Adobe Reader. There is a tool at www.biopdf.com that will call the reader for you and close it after the print has finished.

If all you want is to merge a set of PDF documents then I can recommend free tools such as Ghostscript and PDF Toolkit. Those tools can be fully automated to do that from a command line.

Best regards,
Site Admin
Posts: 491
Joined: Sun Mar 26, 2006 12:28 pm

Re: .NET API automation

Postby russgreen » Fri Feb 20, 2015 12:23 pm

I'm using an almost idential method.

My tools is an addin to some software the automates the print process. I have a method that loops through print jobs and for each job calls a routine to send the print.

With my PDF export method I have this block of code

Dim pdfSettings As PdfSettings = New PdfSettings()
pdfSettings.PrinterName = PDFPRINTERNAME
pdfSettings.SetValue("Output", sFullPath)
pdfSettings.SetValue("ShowPDF", "yes")
pdfSettings.SetValue("ShowSettings", "never")
pdfSettings.SetValue("ShowSaveAS", "never")
pdfSettings.SetValue("ShowProgress", "no")
pdfSettings.SetValue("ShowProgressFinished", "no")
pdfSettings.SetValue("ConfirmOverwrite", "no")

Then I send my print.

Trouble is m,y PDF print job is sent everytime but the settings only seem to work the first time this method is called. Is very hit and miss as to whether the subsequent print jobs popup the bullzip dialog even though show settings and show saveas are set to never.
Posts: 3
Joined: Fri Feb 20, 2015 12:17 pm

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest