Note: To be able to use the samples you must install novaPDF SDK
as samples work only with it. Download it here: nova PDF SDK.
The CSharp Converter sample demonstrates how to convert an existing file by printing it to novaPDF Printer using the ShellExecute function. It also demonstrates how to set different options and manage profiles. The same approach should be taken if you print using a "Print()" method from another object (like an internet browser or a report control). Just replace the ShellExecute call with the call of your Print method. When the application starts, it creates a few profiles and makes different settings in the profiles. Then it shows a dialog from where the user can select the active profile and change its settings using the controls from the dialog. After that a document can be selected from the harddisk and printed to novaPDF Printer using the ShellExecute function call. When using this technique to convert a file to PDF, you have to consider the fact that ShellExecute prints to the default printer. This function returns immediately and does not wait until the print is finished (it may return before the printing is actually started). Therefore you have to set the default printer to novaPDF Printer before calling ShellExecute (using the SetDefaultPrinter method), wait the process to be started (using WaitForExit()) and restore the default printer (with the RestoreDefaultPrinter method). This way you make sure that the default printer was restored and your document is printed to novaPDF Printer. Source Code Snippets
1. Declare INovaPdfOptions variable private NovaPdfOptionsClass mobjNovaOptios; 2. Initialize INovaPdfOptions mobjNovaOptios = new NovaPdfOptionsClass(); // initialize the NovaPdfOptions object AddSmallProfile(); 3. Set novaPDF Printer Options try // ..... } 4. Start a print job private void btnStartPrinting_Click(object sender, System.EventArgs e) mobjNovaOptios.LicenseShellExecuteFile(txtFileToConvert.Text); Process myProcess = new Process();try { myProcess.StartInfo.FileName = txtFileToConvert.Text; myProcess.StartInfo.Verb = "Print"; myProcess.StartInfo.CreateNoWindow = true; myProcess.Start(); } catch (Win32Exception ex) { if(ex.NativeErrorCode == ERROR_FILE_NOT_FOUND) { Console.WriteLine(ex.Message + ". Check the path and filename"); } else if (ex.NativeErrorCode == ERROR_ACCESS_DENIED) { // Note that if your word processor might generate exceptions // such as this, which are handled first. Console.WriteLine(ex.Message + ". You do not have permission to print this file."); } } myProcess.WaitForExit(10000); myProcess.Close(); mobjNovaOptios.RestoreDefaultPrinter(); } |
Add comment

