Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active March 16, 2022 08:17
Show Gist options
  • Save aspose-com-gists/57c37387e8fcf4af62b876c2ada169d2 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/57c37387e8fcf4af62b876c2ada169d2 to your computer and use it in GitHub Desktop.
Convert XPS to Word DOCX/DOC in Java | OXPS to Word DOCX DOC Document Programmatically using Java
// Initialize ByteArrayOutputStream to hold intermediary PDF file
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// Load input OXPS document
XpsDocument document = new XpsDocument("sample.oxps");
// Initialize PdfSaveOptions object with necessary parameters
PdfSaveOptions options = new PdfSaveOptions();
options.setJpegQualityLevel(100);
options.setImageCompression(PdfImageCompression.Jpeg);
// Create rendering device for PDF format
PdfDevice device = new PdfDevice(os);
// Save output PDF file
document.save(device, options);
// Load the intermediate PDF file
Document pdfDocument = new Document(os.toByteArray());
// Save output Word document as DOCX file
pdfDocument.save("output.docx" , SaveFormat.DocX);
// Initialize ByteArrayOutputStream to hold intermediary PDF file
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// Load input XPS document
XpsDocument document = new XpsDocument("sample.xps");
// Initialize PdfSaveOptions object with necessary parameters
PdfSaveOptions options = new PdfSaveOptions();
options.setJpegQualityLevel(100);
options.setImageCompression(PdfImageCompression.Jpeg);
// Create rendering device for PDF format
PdfDevice device = new PdfDevice(os);
// Save output PDF file
document.save(device, options);
// Load the intermediate PDF file
Document pdfDocument = new Document(os.toByteArray());
// Save output Word document as DOCX file
pdfDocument.save("output.docx" , SaveFormat.DocX);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment