Products
PDFRasterizer.NET 3.0
Created
7/3/2014
Tags
Printing

This code sample shows how to print PDF documents from a WPF application.

private void ButtonPrintPressed(object sender, RoutedEventArgs e) { //create and show a printer dialog var printDialog = new PrintDialog(); printDialog.PageRangeSelection = PageRangeSelection.AllPages; printDialog.UserPageRangeEnabled = true; var doPrint = printDialog.ShowDialog(); if (doPrint != true) { return; } FixedDocument fixedDocument; //open the input pdf using (var pdfFile = new FileStream("input.pdf", FileMode.Open, FileAccess.Read)) { var document = new Document(pdfFile); //set the redering options and setting var renderSettings = new RenderSettings(); var renderOptions = new ConvertToWpfOptions { ConvertToImages = false }; renderSettings.RenderPurpose = RenderPurpose.Print; renderSettings.ColorSettings.TransformationMode = ColorTransformationMode.HighQuality; //using the settings create the printable document fixedDocument = document.ConvertToWpf(renderSettings, renderOptions); } //using the selected printer, print the PDF printDialog.PrintDocument(fixedDocument.DocumentPaginator, "Print"); }

}]]>