Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
Created January 1, 2024 12:29
Show Gist options
  • Save conholdate-gists/a4a45da5c744be1e6fef1d6f6796a5ea to your computer and use it in GitHub Desktop.
Save conholdate-gists/a4a45da5c744be1e6fef1d6f6796a5ea to your computer and use it in GitHub Desktop.
Convert XPS to DOCX Word Document in C# .NET
// Initialize PDF output stream
using (System.IO.Stream pdfStream = System.IO.File.Open(dataDir + "XPStoDOCX.pdf", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write))
{
// Initialize XPS input stream
System.IO.Stream xpsStream = System.IO.File.Open(dataDir + "sample.xps", System.IO.FileMode.Open);
// Load input XPS document
Aspose.Page.XPS.XpsDocument document = new Aspose.Page.XPS.XpsDocument(xpsStream, new Aspose.Page.XPS.XpsLoadOptions());
// Initialize options object with necessary parameters
Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions()
{
JpegQualityLevel = 100,
ImageCompression = Aspose.Page.XPS.Presentation.Pdf.PdfImageCompression.Jpeg,
};
// Create rendering device for PDF format
Aspose.Page.XPS.Presentation.Pdf.PdfDevice device = new Aspose.Page.XPS.Presentation.Pdf.PdfDevice(pdfStream);
// Save output PDF file
document.Save(device, options);
}
// Load the intermediate PDF file
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(dataDir + "XPStoDOCX.pdf");
// Save the output DOCX file
pdfDocument.Save(dataDir + "XPStoDOCX.docx", Aspose.Pdf.SaveFormat.DocX);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment