@Matthew Armshaw Did you try adding the using System.Windows.Xps.Packaging at the top of your class?
Printing in C# WPF
I am writing a program in C# WPF so I am hoping this is the correct forum. I am having difficulty with xps creation. Please refer to the following link:
The code following the comment "add content to the 1st document" calls the function AddDocumentContent, which does not exist as part of System and the article does not provide the code for this function. What I need to do is add either a URI or a FixedDocument refernce, but I do not know how. Can someone clarify this for me?
Thanks,
MattSA
Could not make link work, but https address is valid.
2 answers
Sort by: Most helpful
-
-
DaisyTian-1203 11,626 Reputation points
2020-07-29T06:56:45.433+00:00 Here is the details for AddDocumentContent which use the AddFixedPage method to obtain a fixed-page writer for adding pages to an XpsDocument.[Driver from IXpsFixedPageWriter Interface. By the way, I will also give you the example of GetPrintTicketFromPrinter which may give you some help.
private void AddDocumentContent(IXpsFixedDocumentWriter fixedDocumentWriter) { // Collection of image and font resources used on the current page. // Key: "XpsImage", "XpsFont" // Value: List of XpsImage or XpsFont resources Dictionary<string, List<XpsResource>> resources; try { // Add Page 1 to current document. IXpsFixedPageWriter fixedPageWriter = fixedDocumentWriter.AddFixedPage(); // Add the resources for Page 1 and get the resource collection. resources = AddPageResources(fixedPageWriter); // Write page content for Page 1. WritePageContent(fixedPageWriter.XmlWriter, "Page 1 of " + fixedDocumentWriter.Uri.ToString(), resources); // Commit Page 1. fixedPageWriter.Commit(); // Add Page 2 to current document. fixedPageWriter = fixedDocumentWriter.AddFixedPage(); // Add the resources for Page 2 and get the resource collection. resources = AddPageResources(fixedPageWriter); // Write page content to Page 2. WritePageContent(fixedPageWriter.XmlWriter, "Page 2 of " + fixedDocumentWriter.Uri.ToString(), resources); // Commit Page 2. fixedPageWriter.Commit(); } catch (XpsPackagingException xpsException) { throw xpsException; } }// end:AddDocumentContent()