.NET API automation
Posted: 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))
{
System.IO.File.Delete(statusFileName);
}
pdfSettings.SetValue("StatusFile", statusFileName);
// suppose to suppress this dialog... but it seems to have NO EFFECT!!
pdfSettings.SetValue("ShowPDF", "no");
// set output settings...
pdfSettings.WriteSettings(PdfSettingsFileType.RunOnce);
// 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)
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))
{
System.IO.File.Delete(statusFileName);
}
pdfSettings.SetValue("StatusFile", statusFileName);
// suppose to suppress this dialog... but it seems to have NO EFFECT!!
pdfSettings.SetValue("ShowPDF", "no");
// set output settings...
pdfSettings.WriteSettings(PdfSettingsFileType.RunOnce);
// 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)