Hello,
I am working on project to convert XPS document,
earlier I was using below code for conversion,
final com.aspose.xps.rendering.PdfSaveOptions pdfSaveOptions = new com.aspose.xps.rendering.PdfSaveOptions();
document = new com.aspose.xps.XpsDocument(sourceFilePath);
final FileOutputStream pdfStream = new FileOutputStream(outputFilePath);
if (targetType == TargetDocFormats.PDF) {
if (-1 != pdfStandardLvl) {
((IPdfOptions) pdfSaveOptions).setCompliance(pdfStandardLvl);
}
// Create rendering device for PDF format
final com.aspose.xps.rendering.PdfDevice device = new com.aspose.xps.rendering.PdfDevice(pdfStream);
// Export XPS to PDF
document.save(device, pdfSaveOpt
which uses PdfDevice for conversion to pdf.
Below code for xps to png conversion,
final com.aspose.xps.rendering.PngSaveOptions pngSaveOptions = new com.aspose.xps.rendering.PngSaveOptions();
pngSaveOptions.setSmoothingMode(SmoothingMode.HighQuality);
pngSaveOptions.setResolution(300);
pngSaveOptions.setPageNumbers(new int[] { 1 });
// Create rendering device for XPS format
final ImageDevice device = new ImageDevice();
// Save XPS as PNG
document.save(device, pngSaveOptions);
// Iterate through document partitions (fixed documents, in XPS terms)
for (int i = 0; i < 1; i++) {
// Iterate through partition pages
for (int j = 0; j < device.getResult()[i].length; j++) {
final FileOutputStream imageStream = new FileOutputStream(outputFilePath);
imageStream.write(device.getResult()[i][j], 0, device.getResult()[i][j].length);
imageStream.close();
}
}
which uses ImageDevice for conversion to png.
But after upgrading to version 24.10 I got error for PdfDevice and ImageDevice as unrecognized smbols.
After that I tried below ways,
// Convert XPS to PDF
FileOutputStream pdfStream = new FileOutputStream(outputFilePath);
PdfSaveOptions pdfOptions = new PdfSaveOptions();
document.save(pdfStream);
pdfStream.close();
and
// Iterate through pages and save as PNG
for (int i = 1; i <= document.getPageCount(); i++) {
FileOutputStream pngStream = new FileOutputStream(outputFilePath);
document.save(pngStream);
pngStream.close();
}
but these are also not working!
getting error like, com.aspose.imaging.coreexceptions.ImageLoadException: Cannot open an image. The image file format may be not supported at the moment.
at com.aspose.imaging.Image.a(Unknown Source)
at com.aspose.imaging.Image.load(Unknown Source)
What is the correct way to convert XPS to Pdf and Png by not using PdfDevice and ImageDevice?