title: How to embed JPEG images in XAML generated XPS?
body: <p>I'm generating an <code>XPS</code> file on the fly using the <a href="https://msdn.microsoft.com/en-us/library/system.windows.xps.packaging.xpsdocument(v=vs.110).aspx" rel="nofollow">XpsDocument</a> class. In my <code>XAML</code> template I embed a <code>JPEG</code> image in an <a href="https://msdn.microsoft.com/en-us/library/system.windows.controls.image(v=vs.110).aspx" rel="nofollow">Image</a> container. <strong>However, the embedded images in the resulting <code>XPS</code> are always <code>PNG</code> images</strong> - resulting in a very large files for certain types of images.</p>
  
  <p>It seems the document writer interprets the rendered images as bitmaps and then saves them as <code>PNG</code>.</p>
  
  <p>Here's the code that produces the <code>XPS</code>:</p>
  
  <pre><code>void ConvertToXps(IEnumerable&lt;FixedDocument&gt; fixedDocuments, Stream outputStream)
  {
      var package = Package.Open(outputStream, FileMode.Create);
      var xpsDoc = new XpsDocument(package, CompressionOption.Normal);
      var xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
  
      // XPS documents are built using fixed document sequences.
      var fixedDocSeq = new FixedDocumentSequence();
  
      // A4 = 210 x 297 mm = 8.267 x 11.692 inches = 793.632 * 1122.432 dots
      fixedDocSeq.DocumentPaginator.PageSize = new Size(793.632, 1122.432);
  
      foreach (var fixedDocument in fixedDocuments)
      {
          var docRef = new DocumentReference();
          docRef.BeginInit();
          docRef.SetDocument(fixedDocument);
          docRef.EndInit();
          ((IAddChild)fixedDocSeq).AddChild(docRef);
      }
  
      // Write out our fixed document to XPS.
      xpsWriter.Write(fixedDocSeq.DocumentPaginator);
  
      xpsDoc.Close();
      package.Close();
  }
  </code></pre>
  
  <p><strong>Q:</strong> How can I force my <code>XAML</code> rendered images to be saved as <code>JPEG</code> in the generated <code>XPS</code>?</p>