Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Possibly interesting as well: </p> <p>Save the documents to XPS using Microsoft Office 2007 (or print them to an XPS printer).</p> <p>You can display the read-only XPS document either using the XPS viewer component or render page by page into a PNG or JPEG image. This rendering can be achieved quite easily using .NET 3.5 / WPF.</p> <pre><code>XpsDocument xpsDoc = new XpsDocument(xpsFileName, System.IO.FileAccess.Read); FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence(); const double scaleFactor = 0.8; for (int pageNum = 0; pageNum &lt; docSeq.DocumentPaginator.PageCount; pageNum++) { DocumentPage docPage = docSeq.DocumentPaginator.GetPage(pageNum); // FIX: calling GetPage without calling UpdateLayout causes a memory leak ((FixedPage)docPage.Visual).UpdateLayout(); RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)Math.Round(scaleFactor * docPage.Size.Width), (int)Math.Round(scaleFactor * docPage.Size.Height), (int)Math.Round(scaleFactor * 96), (int)Math.Round(scaleFactor * 96), PixelFormats.Default); renderTarget.Render(docPage.Visual); JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.QualityLevel = 75; // Choose type here ie: JpegBitmapEncoder, etc //BitmapEncoder encoder = new PngBitmapEncoder(); // Choose type here ie: JpegBitmapEncoder, etc encoder.Frames.Add(BitmapFrame.Create(renderTarget)); string pageImageFileName = string.Format("{0}-{1}.jpg", Path.Combine(Path.GetDirectoryName(xpsFileName), Path.GetFileNameWithoutExtension(xpsFileName)), pageNum); using (FileStream pageOutStream = new FileStream(pageImageFileName, FileMode.Create, FileAccess.Write)) { encoder.Save(pageOutStream); } } </code></pre> <p>This code needs references to the PresentationCore, PresentationFramework and ReachFramework assemblies.</p> <p>EDIT: The code above contained a memory leak (see <a href="https://stackoverflow.com/questions/218681/opening-xps-document-in-net-causes-a-memory-leak">Opening XPS document in .Net causes a memory leak</a>). The workaround has been been inserted in the example.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload