title: WPF to XPS to PDF
body: <p>I have implemented a report in standard WPF controls and have also implemented a <code>DocumentPaginator</code> to take these controls and convert them into a document for printing.</p>
  
  <p>I have also implemented some code which uses the document paginator to render the pages to images and write them out to a PDF using <a href="http://www.pdfsharp.com/" rel="noreferrer">PDFSharp</a>, however this does not allow for copying and pasting, also the image quality is questionable.</p>
  
  <p>I have experimented with the <a href="http://artifex.com/downloads/" rel="noreferrer">GhostXPS</a> utility and was thinking of using it by saving out to an XPS document and then using <a href="http://artifex.com/downloads/" rel="noreferrer">GhostXPS</a> to convert it to a PDF, this was promising, however the current version contains a bug that renders data copied from the generated PDF useless...</p>
  
  <p>So I thought I would ask here to try and find a efficient method for doing this, Can someone please suggest a good way to take a <code>DocumentPaginator</code> and either save it directly out to a PDF, with copy/paste functionality or convert it from an XPS document to a PDF with this functionality?</p>
  
  <p>Thanks,
  Alex.</p>
  
  <p>EDIT - PDFSharp fix:
  Ok as requested here is what I did to compile the fix for the PDFSharp 1.31 XPS converter:</p>
  
  <p>1) I downloaded the source from here:</p>
  
  <p><a href="http://sourceforge.net/projects/pdfsharp/files/pdfsharp/PDFsharp%201.31/" rel="noreferrer">PDFSharp - SourceForge</a></p>
  
  <p>2) I followed the instruction in this post:</p>
  
  <p><a href="http://forum.pdfsharp.net/viewtopic.php?f=2&amp;t=2144" rel="noreferrer">PSFSharp Fix</a></p>
  
  <pre><code>XpsParser.ImageBrush.cs (ln 22, added): brush.Opacity = 1;
  PdfContentWriter.cs (ln 526, changed): if (opacity &lt;= 1)
  </code></pre>
  
  <p>3) Then just compile the source, first open the 'PdfSharp-WPF.csproj' and build that, then open the 'PdfSharp.Xps.csproj' and build it as well, the relevent libraries are 'PdfSharp-WPF.dll' and 'PdfSharp.Xps.dll'</p>
  
  <p>Note upon trying to build the source you will likely receive a few errors depending on which version of .NET you are targeting, these are simple to fix if you just read the error messages.</p>
  
  <p>EDIT(2): NJones created a blog post with more details on the PdfSharp fix: <a href="http://www.nathanpjones.com/wp/2013/03/output-to-pdf-in-wpf-for-free/" rel="noreferrer">Output to PDF in WPF</a></p>