How to Render XSL FO to PDF using Java

In this short tutorial, you will learn how to render XSL FO to PDF using Java in Windows, Mac OS, or Ubuntu. You can convert XSL FO file to PDF format using a few lines of code.

Steps to Render XSL FO to PDF using Java

  1. Configure Aspose.PDF from the Maven repository in your project
  2. Load an input XSL FO file into the Document class object using load option XslFoLoadOptions
  3. Save output PDF converted from the input XSL FO file

In these steps, we configure the required library and then initialize the Document class object to load the input XSL FO file from the disc. Then we proceed to export XSL FO to PDF in Java using the load option XslFoLoadOptions.

Code to Convert XSL FO to PDF using Java

The above Java code snippet loads the input XSL FO file and renders it to a PDF file. There is no need to install the Adobe Acrobat application to run this code.

In this tutorial, we have learned how to generate PDF from XSL FO using Java. You can perform other operations also like for reading bookmarks from a PDF file, refer to the article on How to Read Bookmarks in PDF using Java.

 English