Created
May 24, 2024 10:12
-
-
Save farhan-raza/8332fa8ad0ae115f26342444e65ed4e5 to your computer and use it in GitHub Desktop.
Convert JSON to PDF in C#
This file contains hidden or 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 Workbook object for storing JSON data | |
Aspose.Cells.Workbook JsonToPdf = new Aspose.Cells.Workbook(); | |
// Access default worksheet | |
Aspose.Cells.Worksheet wsDefault = JsonToPdf.Worksheets[0]; | |
// Read JSON data from file for saving to the selected worksheet | |
string jsonInputData = File.ReadAllText("input.json"); | |
// Instantiate JsonLayoutOptions for handling JSON data | |
Aspose.Cells.Utility.JsonLayoutOptions layoutOptions = new Aspose.Cells.Utility.JsonLayoutOptions(); | |
// Set flag to treat array data as table | |
// while exporting data from JSON to worksheet | |
layoutOptions.ArrayAsTable = true; | |
// Import JSON data using the above layout options starting from A1 | |
Aspose.Cells.Utility.JsonUtility.ImportData(jsonInputData, wsDefault.Cells, 0, 0, layoutOptions); | |
// Save the resultant workbook as PDF using the Workbook.Savefunction | |
JsonToPdf.Save("JSON-PDF.pdf", Aspose.Cells.SaveFormat.Auto); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment