Convert JSON to PDF using Java

JSON to PDF Java

JSON to PDF conversion is required in various cases for sharing, printing, or other purposes. To perform this conversion programmatically, this article covers how to convert JSON to PDF using Java.

Java API for JSON to PDF Conversion

In order to convert JSON files to PDF format, we will use Aspose.Cells for Java. It is a feature-rich spreadsheet manipulation API that allows you to generate and process Excel files using Java. You can either download the API or install it using the following Maven configurations.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-cells</artifactId>
    <version>21.6</version>
</dependency>

Convert JSON Data to PDF

The following are the steps to convert a JSON file to PDF using Java.

  1. First, create an instance of Workbook class.
  2. Select the default Worksheet from the WorksheetsCollection.
  3. Read JSON data into a string object.
  4. Create an instance of JsonLayoutOptions and set options.
  5. Import data from JSON to worksheet using JsonUtility.importData method with reference to Worksheet object and JSON data.
  6. Finally, convert JSON to PDF by saving the workbook as PDF using Workbook.save(string, SaveFormat.Auto) method.

The following code sample shows how to convert a JSON file to PDF.

Get a Free License

You can use Aspose.Cells for Java without evaluation limitations using a temporary license.

Conclusion

In this article, you have learned how to convert JSON data to PDF using Java. You can easily install the API and use the provided code sample in your Java applications. Furthermore, to learn more about Aspose.Cells for Java, you can explore the documentation. Also, you can post your questions or queries on our forum.

See Also