To render a PDF document directly to a Device Context, do the following:
- Create a PDFXpress object and initialize it.
- Create a Document object from an existing PDF file.
- Create a RenderDcOptions object.
- Set the RenderDcOptions:
- ForDeviceTechnology – we chose Printer
- Create a PrintDocument object.
- Add a PrintPageEventHandler to the PrintDocument object.
- In the PrintPageEventHandler, call RenderPageToDeviceContext() on the Document object.
This will render the document directly to the Device Context, in this case the printer.
C# Example | Copy Code |
---|---|
using System; using System.Drawing; using System.Drawing.Printing; using Accusoft.PdfXpressSdk; namespace DC { class RenderToDC { static Document doc; static RenderDcOptions options; static void Main(string[] args) { using (PdfXpress pdf = new PdfXpress()) { try { pdf.Initialize(@"C:\Users\Public\Documents\Accusoft\PDFXpress\v5.0\Support\Font", @"C:\Users\Public\Documents\Accusoft\PDFXpress\v5.0\Support\CMap"); doc = new Document(pdf, "C:\\myfile.pdf"); options = new RenderDcOptions(); options.ForDeviceTechnology = DeviceTechnology.Printer; PrintDocument printer = new PrintDocument(); printer.PrintPage += new PrintPageEventHandler(PrintPage); printer.Print(); } finally { if (doc != null) { doc.Dispose(); doc = null; } } } } static void PrintPage(object sender, PrintPageEventArgs e) { doc.RenderPageToDeviceContext(0, e.Graphics, options); } } } |