Converting (in Java) an XFA PDF to a PDF version that opens in a simple renderer (Firefox, Edge)


#1

I’m looking into using the Aspose.PDF for Java tool set to convert an XFA PDF into a PDF file that can open in a simple renderer, such as Firefox.

Issue:
It seems that a file with underlying XFA renders at runtime, which doesn’t load in an application without XFA support.

Attempts:
-Flattened document and flattened document.form(). XFA still seems to be present and won’t render
-Converted form to standard Acroform. Breaks document structure that the XFA describes, but does load in Firefox.
-[EDIT] converting to XPS and back. XFA does not render at all.

What works so far:
-[EDIT] Converting to XPS and back does not actually work as expected.
-[EDIT] Manually using Adobe print to PDF option works as expected. Resulting file opens in Firefox and Edge

I’m hoping to find a more direct way to create a prerendered PDF document and that flattens the XFA.


#2

@timsmay

Could you please share your sample PDF document with us. We will test the scenario in our environment and address it accordingly.


#4

Sorry for the delay, I tried to get a version of the document without sensitive information but wasn’t able to, unfortunately.

What we are exploring now is using a print to file method to render the PDF. When the file is printed to file through the Adobe program, it renders perfectly in any viewer.

Is there a way to print an Aspose document to a pdf file?

Attempts:
-Used PdfViewer.save(""), but get the error “java.lang.UnsupportedOperationException: The method is not supported by this facade”
-Used PdfViewer with a PdfPrinterSettings with PrintToFile as true and PrintToFileName set, but resulting PDF file seems to be corrupted
-Tried to use PrintController, but couldn’t find the functionality to actually print.

Thanks,
Tim


#5

@timsmay

Thanks for writing back.

Could you please try using following code snippet to print the PDF document to a file. In following code snippet, please use virtual printer e.g. Microsoft Print to PDF to print the document:

com.aspose.pdf.facades.PdfViewer viewer = new com.aspose.pdf.facades.PdfViewer();
viewer.bindPdf("c:/pdftest/TestDokument.pdf");
com.aspose.pdf.printing.PdfPrinterSettings printerSettings = new com.aspose.pdf.printing.PdfPrinterSettings();
printerSettings.setPrinterName("PrinterName");
com.aspose.pdf.printing.PrintPageSettings pageSettings = printerSettings.getDefaultPageSettings();
viewer.printDocumentWithSettings(pageSettings, printerSettings);
viewer.close(); 

In case you still face any issue, please feel free to let us know.