Dear All,
This is my first question in C# Corner. Please apologize for any inconvenience.
Iam using WPF and XPS to print content from a FlowDocument.
XAML :
WPF WPF, which stands forWindows Presentation Foundation ,is Microsoft's latest approach to a GUI framework, used with the .NET framework.Some advantages include:
C# Code to Print :
if (File.Exists("printPreview.xps")){File.Delete("printPreview.xps");}var xpsDocument = new XpsDocument("printPreview.xps", FileAccess.ReadWrite);XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);writer.Write(((IDocumentPaginatorSource)FD).DocumentPaginator);//Document = xpsDocument.GetFixedDocumentSequence();// Create the print dialog object and set optionsPrintDialog pDialog = new PrintDialog();pDialog.PageRangeSelection = PageRangeSelection.AllPages;pDialog.UserPageRangeEnabled = true;// Display the dialog. This returns true if the user presses the Print button.Nullableprint = pDialog.ShowDialog(); if (print == true){FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");xpsDocument.Close();}
Replies
Know the answer? Post it — somebody with the same question will find it here.