How to Convert XSL FO to PDF using Python

This short tutorial guides how to convert XSL FO to PDF using Python. It contains all the required information to establish the environment to run the sample code, a list of steps to be followed while writing this application, and a runnable sample code demonstrating the process of how to export XSL FO to PDF using Python. You will also get details to customize the loading of XSL FO files and the customization of the output PDF file on the disk or to an output stream.

Steps to Render XSL FO to PDF using Python

  1. Configure the environment to use Aspose.PDF for Python via .NET for converting XSL-FO to PDF
  2. Create an object of XslFoLoadOptions class to customize the loading of the XSL FO file
  3. Load the XSL FO file with the Document class object using the file name and XslFoLoadOptions object
  4. Save the loaded XSL FO file as a PDF using the save() method in the Document object

These steps summarize the process to convert XSL FO to PDF using Python. The process is started by declaring an object of XslFoLoadOptions class object that is used to customize the process to load an XLS FO file followed by the instantiation of the Document class object that takes the file name and load options for the XSL FO file. Once the file is loaded into the Document class object, it can be saved in various formats like PDF, DOC, XPS, HTML, and PPTX format to name a few.

Code to Export XSL FO to PDF using Python

The above code segment demonstrates how to render XSL FO to PDF using Python. The XslFoLoadOptions class object provides options to customize the loading of the XSL FO files you may set the WarningHandler to handle the warnings that are raised while loading the file, and describe the input file type as CGM, HTML, EPUB, XML, XSLFO, and so on. Similarly, while saving the loaded file as a PDF, you may use the PDFSaveOptions class object to set the default font name, set the flag to close the response object, set the path of the temporary file, and set a warning handler for controlling the warnings.

This article has taught us to transform XSL FO to PDF using Python. If you want to learn the process to create a PDF file in Python, refer to the article on how to create PDF in Python.

 English