tags:

views:

24

answers:

0

I am trying to print captured images from a WPF application - it seems the approach to take is to create an XPS document and then send that to the printer. I have found some samples that involve using a DrawingVisual and adding that to the document, but after that I am unsure of how you set pagination, etc.

Another example I have seen is this:

string resFile = "c:\\sampleimage.jpg";
XpsDocument xpsDoc = new XpsDocument("c:\\image.xps", FileAccess.ReadWrite);
IXpsFixedDocumentSequenceWriter fds = xpsDoc.AddFixedDocumentSequence();
IXpsFixedDocumentWriter fd = fds.AddFixedDocument();
IXpsFixedPageWriter fp = fd.AddFixedPage();
XpsResource res = fp.AddImage(XpsImageType.JpegImageType);

followed by actually writing out the XML tags for the elements manually

XmlWriter xmlWriter = fp.XmlWriter;
xmlWriter.WriteStartElement("Path");
xmlWriter.WriteAttributeString("Data", "M 20,20 L 770,20 770,770 20,770 z");
xmlWriter.WriteStartElement("Path.Fill");
xmlWriter.WriteStartElement("ImageBrush");
xmlWriter.WriteAttributeString("ImageSource", res.Uri.ToString());

This seems pretty odd to me as well. There appear to be very few resources on MSDN (or even here on SO) about the whole process. Can anyone provide a straightforward explanation of what the preferred method is of creating a multi-page XPS document with a full-screen image on each page?