Convert XML to PDF

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

  1. Transform any XML data to HTML using XSLT and convert HTML to PDF as described below
  2. Generate XML document using Aspose.PDF XSD Schema
  3. Use XML document based on XSL-FO standard

Convert XSL-FO to PDF

The conversion of XSL-FO files to PDF can be implemented using the traditional Aspose.PDF technique - instantiate Document object with XslFoLoadOptions. But sometimes you can meet with the incorrect file structure. For this case, XSL-FO converter allows setting the error handling strategy. You can choose ThrowExceptionImmediately, TryIgnore or InvokeCustomHandler.

public static void Convert_XSLFO_to_PDF()
{
    // Instantiate XslFoLoadOption object
    var options = new XslFoLoadOptions(".\\samples\\employees.xslt");
    // Set error handling strategy
    options.ParsingErrorsHandlingType = XslFoLoadOptions.ParsingErrorsHandlingTypes.ThrowExceptionImmediately;
    // Create Document object
    var pdfDocument = new Aspose.Pdf.Document(".\\samples\\employees.xml", options);
    pdfDocument.Save(_dataDir + "data_xml.pdf");
}