WPF FixedDocument, also known as an XPS document, is a definite improvement over PDF. It has many features that pdf is missing. In most cases, it is better to distribute your document as XPS rather than PDF, but sometimes you need to convert it from XPS to PDF, for example, if you need to open the document on devices that have only PDF support. Unfortunately, most free tools for converting from XPS to PDF, such as CutePDF and BullzipPDF, require the installation of a printer driver or are not open source.
A good open source solution is to use the gxps tool, which is part of GhostPDL. GhostPDL is part of the Ghostscript project and is open source, licensed under the GPL2 license.
Your code might look like this:
string pdfPath = ... // Path to place PDF file string xpsPath = Path.GetTempPath(); using(XpsDocument doc = new XpsDocument(xpsPath, FileAccess.Write)) XpsDocument.CreateXpsDocumentWriter(doc).Write(... content ...); Process.Start("gxps.exe", "-sDEVICE=pdfwrite -sOutputFile=" + pdfPath + "-dNOPAUSE " + xpsPath).WaitForExit(); // Now the PDF file is found at pdfPath
Ray burns
source share