Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
Last active July 8, 2024 14:40
Show Gist options
  • Save conholdate-gists/9e4318c0f2953ab8be8502e9396fcf0d to your computer and use it in GitHub Desktop.
Save conholdate-gists/9e4318c0f2953ab8be8502e9396fcf0d to your computer and use it in GitHub Desktop.
Convert JSON to PDF in Java | JSON to PDF Converter
// Create a Workbook object
com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook();
// Access a worksheet
com.aspose.cells.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
com.aspose.cells.JsonLayoutOptions layoutOptions = new com.aspose.cells.JsonLayoutOptions();
layoutOptions.setArrayAsTable(true);
// Import JSON data
com.aspose.cells.JsonUtility.importData(content, worksheet.getCells(), 0, 0, layoutOptions);
// Save JSON as PDF
workbook.save("output.pdf", com.aspose.cells.SaveFormat.AUTO);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment