Last active
June 22, 2021 03:45
-
-
Save aspose-com-gists/a92f28aeaffae678d3433561ec7d4193 to your computer and use it in GitHub Desktop.
Convert JSON to PDF in Java | https://blog.aspose.com/2021/05/22/convert-json-to-pdf-using-java/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a blank Workbook object | |
Workbook workbook = new Workbook(); | |
// access default empty worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// read JSON file | |
String fileName = "Data.json"; | |
String content = new String(Files.readAllBytes(Paths.get(fileName))); | |
// set JsonLayoutOptions for formatting | |
JsonLayoutOptions layoutOptions = new JsonLayoutOptions(); | |
layoutOptions.setArrayAsTable(true); | |
// import JSON data to default worksheet starting at cell A1 | |
JsonUtility.importData(content, worksheet.getCells(), 0, 0, layoutOptions); | |
// convert imported JSON to PDF | |
workbook.save("output.pdf", SaveFormat.AUTO); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read the article: https://blog.aspose.com/2021/05/22/convert-json-to-pdf-using-java/