C#Examples \ PDFdriverAPI

PDF-XChange Drivers API (only) V4/V5
This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers SDK (only) - VERSION 4 & 5 - Please use the PDF-Tools SDK Forum for Library DLL assistance.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Post Reply
NRSGNT
User
Posts: 3
Joined: Tue Apr 05, 2011 6:54 pm

C#Examples \ PDFdriverAPI

Post by NRSGNT »

Has anyone tried using this sample project to select/file print a .pdf? What is supposed to happen? All I get is errors with any .pdf I pick...

C:\Program Files (x86)\Tracker Software\PDF-XChange 4 API\Examples\APIExamples\C#Examples\PDFdriverAPI

Error : No application is associated with the specified file for this operation
Error on : printJob.Start();
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: C#Examples \ PDFdriverAPI

Post by Walter-Tracker Supp »

NRSGNT wrote:Has anyone tried using this sample project to select/file print a .pdf? What is supposed to happen? All I get is errors with any .pdf I pick...

C:\Program Files (x86)\Tracker Software\PDF-XChange 4 API\Examples\APIExamples\C#Examples\PDFdriverAPI

Error : No application is associated with the specified file for this operation
Error on : printJob.Start();

Hello,

This error occurs because the print system must execute a program associated with the file type you are printing to render it before passing it to the print driver. In the example code there is a filter that only allows you to open .txt and .doc files, but you can change it to allow other file types as well. If you are trying to load a .doc or .txt file with the sample application, check to ensure that (within windows) you have a default application (for example notepad, or MS Word) associated with the .txt or .doc file type.

It sounds like you have changed the filters to allow it to load a PDF file (and then save a new PDF). If you do this, it will call whatever program is associated with PDF files (at the Windows operating system level), which loads the PDF, renders it, and passes it on to the print driver. If you install our PDF-XChange Viewer and ensure it is associated with PDF files, this would work. Presumably it will work with other PDF viewers, but I have only tested this example specifically with our PDF viewer.

Sincerely,

Walter Ash
Tracker Support
NRSGNT
User
Posts: 3
Joined: Tue Apr 05, 2011 6:54 pm

Re: C#Examples \ PDFdriverAPI

Post by NRSGNT »

I have Adobe Reader installed, hmmm. Can I use the PDFXviewer in a console application (i.e. no GUI) to print a pdf to the default print driver (i.e. PDFXchange)?
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: C#Examples \ PDFdriverAPI

Post by Walter-Tracker Supp »

NRSGNT wrote:I have Adobe Reader installed, hmmm. Can I use the PDFXviewer in a console application (i.e. no GUI) to print a pdf to the default print driver (i.e. PDFXchange)?
In the example project (PDFdriverAPI) you can replace this function with the following code and it will print to PDF silently, assuming you have PDFXViewer set as your default PDF viewer in Windows.

Code: Select all

private void bFilePrint_Click(object sender, EventArgs e)
        {
            PDFPrinter.SetAsDefaultPrinter();
            bPXCPrinterDefault = true;
            PDFPrinter.set_Option("Save.ShowSaveDialog", false);
            PDFPrinter.set_Option("Save.File", "c:\\test.pdf");

            System.Diagnostics.Process printJob = new System.Diagnostics.Process();
            printJob.StartInfo.FileName = "c:\\testinput.pdf";
            printJob.StartInfo.UseShellExecute = true;
            printJob.StartInfo.Verb = "print";
            printJob.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
            printJob.Start();
        }
If you wish to suppress warning dialogues that occur when the target file (c:\test.pdf in this example) already exists, you can set the options as follows:

Code: Select all

PDFPrinter.set_Option("Save.WhenExists",1); // value of "1" overwrites as documented in the PDFX driver API documentation
If you want to suppress executing a viewer to look at the output PDF file after printing you set the following option:

Code: Select all

PDFPrinter.set_Option("Save.RunApp",false);
I have executed the above example on my system with both Adobe Reader X and PDFXViewer and can successfully create the PDF copy silently. You can use this to, for example, silently flatten PDF forms.

Hope this helps.

Walter Ash
Tracker Support
Post Reply