Print PDF in WPF application

The following code snippet also work with Aspose.PDF.Drawing library.

Direct print

The Aspose.PDF library has the ability to convert PDF files to XPS. We can use this function to organize the printing of documents. Let’s consider the example for direct printing:

In this case, we will follow these steps:

  1. Open PDF file using OpenFileDialog.
  2. Convert PDF to XPS and store it in MemoryStream object.
  3. Associate MemoryStream object with Xps Package.
  4. Add the package to the Package Store.
  5. Create an XpsDocument based on package.
  6. Get an instance of the FixedDocumentSequence.
  7. Send this sequence to the printer using PrintDialog.

View and print document

In many cases, users want to see the document before printing. To implement a view, we can use a DocumentViewer control. Most of the steps for implementing this approach are similar to the previous example.