PrintManager – Setting Advanced Printer Options

by Anil S

Mon, April 27 2015, 10:24 AM (US Eastern Time)

The PrintManager for .NET API allows printing of PDF files through any .NET application.  The settings accessible to the PrintManager are limited to those exposed through a standard API (such as Win32 or .NET).  But a printer may have additional settings that are specific to that printer and are not readily available through a standard API. This means that there could be non-standard features or settings available that vary between printers that are not able to be exposed through the PrintManager API.  To remedy this, we have exposed a way to manually save and reuse a specific state of the native printer’s dialog box that when provided to the Printjob will affect that job as if those options where manually selected by a user.  A full example on how to accomplish this is outlined below.

We will start with the code to invoke printer’s native dialog box and save the settings to a file.

To invoke the printer's advanced setting dialog we will be using a Win32 function called "AdvancedDocumentProperties".

AdvancedDocumentProperties(IntPtr.Zero,IntPtr.Zero,e.PrintJob.Printer.Name,e.DevMode, e.DevMode);

In order to import the above function to a .NET application, use the following DllImport.

[DllImport("winspool.Drv", EntryPoint = "AdvancedDocumentPropertiesW", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]

static extern int AdvancedDocumentProperties(IntPtr hwnd, IntPtr hPrinter, [MarshalAs(UnmanagedType.LPWStr)] string pDeviceName, IntPtr pDevModeOutput, IntPtr pDevModeInput);

Calling the Print() method will fire the Printjob.Starting event. In the event handler, call AdvancedDocumentProperties to display the printer setting dialog box. Select the appropriate setting that you would like to save to file and click OK. The file can be generated with individual settings or with a group of settings.

PrintJob printJob = new PrintJob(Printer.Default, "DocumentA.pdf");

printJob.Starting += new PrintJobStartingEventHandler(this.onStartingPrint1);

printJob.Print();

PrintJobStartingEventArgs contains following properties that will be used to retrieve the printer settings from the dialog box.

Name Type Definition
Devmode Intptr Pointer towards Devmode structure
DevmodeSize Int Size of  Devmode
DevmodeDriverExtra Int Size of  DmDriverExtra
PrintJob PrintJob DynamicPDF Printmanager PrintJob object. Generic printer settings can be changed using this object.

Here is the code for the event handler to retrieve and save the selected printer setting.

private void onStartingPrint1(object sender, PrintJobStartingEventArgs e)
{
    //Invoke the printer options dialog box.
    int value = AdvancedDocumentProperties(IntPtr.Zero, IntPtr.Zero, e.PrintJob.Printer.Name, e.DevMode, e.DevMode);

    //Create a byte array to store Devmode and DmDriverExtra settings.
    byte[] bytearray = new byte[e.DevModeSize + e.DevModeDriverExtra];

    //Copy the contents of both Devmode and DmDriverExtra to the byte array.
    Marshal.Copy(e.DevMode, bytearray, 0, e.DevModeSize + e.DevModeDriverExtra);

    //Save the settings to disk.
    File.WriteAllBytes("SettingsFile.bin", bytearray); 
}

Next, we will print a PDF using the saved settings by overwriting the Devmode and DmDriverExtra structures with the file contents. Due to this, all settings applied to the PrintJob object before Printjob.Starting event handler call will be lost. However we can set the print settings after overwriting Devmode and DmDriverExtra in the event handler.

private void onStartingPrint2(object sender, PrintJobStartingEventArgs e)
{
    //Load the saved settings into a byte array. 
    byte[] bytearray = File.ReadAllBytes("SettingsFile.bin");

    //Overwrite the DevMode with the byte array restored from file. 
    IntPtr pdevmode = Marshal.AllocHGlobal(bytearray.Length);
    Marshal.Copy(bytearray, 0, e.DevMode, bytearray.Length);

    //The line below displays the print options dialog box, so the modified settings can be verified during development. 
    //It is not required for printing so it can removed, especially for non-interactive applications like windows services             
    int value = AdvancedDocumentProperties(IntPtr.Zero, IntPtr.Zero, e.PrintJob.Printer.Name, e.DevMode, e.DevMode);            

    //Set additional print settings as needed. 
    e.PrintJob.PrintOptions.Copies = 1;
}

Complete source code is available for download below.

Downloads:

PrinterAdvancedOptions.zip (21.2 kb)

Tags: , , , , ,

Dynamic PDF for COM/ActiveX Core Suite Version 8 Release

Fri, February 20 2015, 4:25 PM (US Eastern Time)

Our DynamicPDF Core Suite (including Merger, Generator and ReportWriter) version 8 has now been fully released.  Download it Today!

Version 8 adds lots of new features including additional support for PDF/A-2, PDF/A-3, MSI (Modified Plessey) & RM4SCC (Royal Mail) barcodes, Strikethrough Text, Document Optimization (of Images), Enhanced Font Rendering, Field level Flattening as well as overall efficiency improvements and stabilizations. Take a look at our Version 8 Full Feature List.

For existing customers, eligible upgrades (free with Maintenance, discounted with previous versions) can be accessed via our Customer Area, www.dynamicpdf.com\customerarea or anyone can contact us directly, sales@cete.com or +1 410.772.8620.

Tags: , , , , , , ,

DynamicPDF for COM/ActiveX Core Suite Version 8 BETA Release

Fri, December 5 2014, 4:42 PM (US Eastern Time)

The DynamicPDF Core Suite for COM/ActiveX Version 8.0 BETA has just been posted to our site for download and testing, DynamicPDF Core Suite for COM/ActiveX v8 Beta Download.

This version 8 BETA includes DynamicPDF Generator, Merger and ReportWriter (all included in the Core Suite) and the installer includes the updated documentation and all our ASP, VB6 and VBScript examples.

Version 8 will include a bunch of new features including two new barcodes (MSI and RM4SCC), PDF/A-2 and PDF/A-3 support, duplicate image removal and more. Take a look at the full list of new features.

Email support@cete.com with any questions or issues and thanks for taking part in our Version 8 BETA.

Tags: , , , , , , , ,

Dynamic PDF for .NET Core Suite Version 8 Release

Mon, September 29 2014, 5:12 PM (US Eastern Time)

DynamicPDF Core Suite for .NET v8 has been released!  Thanks to everyone who participated in the beta testing and helped make this release a success.  Please review our full DynamicPDF Core Suite v8 Press Release.
 
Version 8 adds lots of new features including additional support for PDF/A-2, PDF/A-3, MSI (Modified Plessey) & RM4SCC (Royal Mail) barcodes, Strikethrough Text, Document Optimization (of Images), Enhanced Font Rendering, Field level Flattening as well as overall efficiency improvements and stabilizations. Take a look at our Version 8 Full Feature List.
 
For any upgrade options, existing customers can log into our Customer Area, or anyone can contact us directly, sales@cete.com or +1 410.772.8620.

Tags: , , , , , ,

DynamicPDF for .NET Core Suite Version 8 BETA Release

Wed, June 11 2014, 4:58 PM (US Eastern Time)

We have just posted the DynamicPDF Core Suite for .NET version 8 BETA on our site for download and testing, DynamicPDF Core Suite for .NET v8 Beta Download.

This version 8 BETA includes DynamicPDF Generator, Merger and ReportWriter (all included in the Core Suite) and the installer includes the updated documentation and all our C# and VB.NET Visual Studio examples.

Version 8 will include a bunch of new features including two new barcodes (MSI and RM4SCC), PDF/A-2 and PDF/A-3 support, duplicate image removal and more. Take a look at the full list of new features.

Email support@cete.com with any questions or issues and thanks for taking part in our version 8 BETA.

Tags: , , , , , , ,

DynamicPDF PrintManager for .NET Version 2 is Released

Wed, July 3 2013, 5:49 PM (US Eastern Time)

PrintManager for .NET version 2.0 is Live!  Easy PDF printing from within any C# or VB.NET application is what PrintManager is all about and version 2 is no different.  We have added some advanced features like being able to retrieve a list of the media/paper types from a printer and being able to set those types for a specific print job and the ability to redirect the print output to a file.

DynamicPDF PrintManager offers flexible server and developer based licensing options.

Try the fully functional evaluation edition of PrintManager for .NET today!

See a Print PDF C# example here.

Tags: , ,

DynamicPDF Viewer for .NET is Released

Wed, June 19 2013, 4:33 PM (US Eastern Time)

We are happy to announce the full production release of the DynamicPDF Viewer for .NET.  Viewer for .NET is our customizable .NET PDF viewer that can be embedded into any .NET windows form application.  It displays PDF files quick and efficiently and has no external dependencies.  If you need to add PDF displaying or viewing to your .NET application then you have got to try DynamicPDF Viewer for .NET.

We offer a fully functional evaluation edition that never expires so download and try it out today!

PDF Viewer for .NET

Tags: , , , ,

DynamicPDF PrintManager for .NET Version 2 BETA Release

by Anil S

Mon, April 29 2013, 11:48 AM (US Eastern Time)

The BETA of DynamicPDF PrintManager Version 2.0 is now available for download here.

For any one new to this product, DynamicPDF PrintManager for .NET allows developers to automate PDF printing from within any .NET application (C# or VB.NET).

We have added some new features into Version 2 that include retrieving the list of media/paper types, setting the media/paper type for a print job and redirecting print output to a file.

Read more and begin beta testing today, http://www.dynamicpdf.com/Products/DynamicPDFPrintManagerforNET/Beta.aspx.

Any questions, comments or issues should be sent to support@cete.com.

Tags: , , ,

.NET PDF Viewer - Beta Release

Thu, March 7 2013, 4:41 PM (US Eastern Time)

Now ready for Beta testing is our DynamicPDF Viewer 1.0 for .NET windows control.  This is an all new PDF Viewer designed specifically for .NET developers who want to add seamless, efficient, customizable PDF viewing to their .NET windows application.

No COM Interops, no problem!  DynamicPDF Viewer for .NET is an actual .NET Windows Form Control.  The API is easy to use and the PDF Viewing window is easy to customize.

Display a PDF from a file or byte array, open encrypted PDF files, turn toolbars on or off and so much more.

Read more and begin beta testing today, http://www.dynamicpdf.com/Products/DynamicPDFViewerForNET/Beta.aspx.

Any questions, comments or issues should be sent to support@cete.com.

Thanks for everyone's participation.

Tags: , , , ,

Java Release of DynamicPDF Merger and Generator Version 7

Tue, December 4 2012, 4:45 PM (US Eastern Time)

We are proud to announce the version 7 release of our DynamicPDF Merger and Generator for Java, our easy to use components for creating and interacting with any PDF documents from within any Java application.  Thanks to everyone who participated in the Beta testing process and contributed to a successful release.

Version 7 for Java includes new PDF encryption algorithm support (AES 128 and 256, RC4 128 and crypt filter support), adding QR codes to PDF, true PDF form flattening and lots more.  Check out our full list of new PDF features here.

We always love your feedback; let us know what features or functionality you want to see in the future.

Tags: , , , , , ,

Month List