Accusoft.PdfXpress7.Net
Render to Device Context

To render a PDF document directly to a Device Context, do the following:

  1. Create a PDFXpress object and initialize it.
  2. Create a Document object from an existing PDF file.
  3. Create a RenderDcOptions object.
  4. Set the RenderDcOptions:
  5. Create a PrintDocument object.
  6. Add a PrintPageEventHandler to the PrintDocument object.
  7. 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\v7.0\Support\Font",
                                   @"C:\Users\Public\Documents\Accusoft\PDFXpress\v7.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);
        }
    }
}

 

 


©2018. Accusoft Corporation. All Rights Reserved.

Send Feedback