Convert XML to PDF

The XML format used to store structured data. There are several ways to convert XML to PDF in Aspose.PDF.

Consider option using XML document based on XSL-FO standard.

Convert XSL-FO to PDF

The conversion of XSL-FO files to PDF can be implemented using Document object with XslFoLoadOptions, but sometimes you can meet with the incorrect file structure.

// Convert XML to PDF
    public void convertXMLtoPDF() {
        // Initialize document object
        String pdfDocumentFileName = new File(fileStorage,"XML-to-PDF.pdf").toString();
        String xmlDocumentFileName = new File(fileStorage,"Conversion/employees.xml").toString();
        String xsltDocumentFileName = new File(fileStorage, "Conversion/employees.xslt").toString();

        try {
            XslFoLoadOptions options = new XslFoLoadOptions(xsltDocumentFileName);
            document = new Document(xmlDocumentFileName,options);
            // Save resultant PDF file
            document.save(pdfDocumentFileName.toString());
        } catch (Exception e) {
            resultMessage.setText(e.getMessage());
            return;
        }
        resultMessage.setText(R.string.success_message);
    }    
    ```