In this simple tutorial we will learn how to convert JSON to PDF in Node.js. It contains the details for the IDE settings, a list of programming tasks, and a runnable sample code for transforming a file from JSON to PDF in Node.js. You will learn different properties and methods to set text style in the output PDF file.
Steps to Convert JSON to PDF in Node.js
- Set the environment to use Aspose.Cells for Node.js via Java for JSON to PDF conversion
- Read the text from the source JSON file
- Instantiate a workbook and access a sheet from it
- Create a JsonLayoutOptions class object
- Call the importData() method from the JsonUtility class to fill JSON data in the sheet
- Save the output workbook as PDF using the SaveFormat.AUTO enumerator
The above-mentioned steps assist in converting JSON file to PDF in Node.js. The process is quite simple as access to the sheet is obtained first where contents from the JSON file are to be saved followed by declaring an object of JsonLayoutOptions class to format the contents in the output workbook. Once the contents are copied to the target sheet using the importData() method, the resultant workbook is saved as PDF using the SaveFormat.AUTO enumerator.
Code to Convert JSON File to PDF in Node.js
This code sample explains the development of a JSON file to PDF converter in Node.js. The JSON text title in the Excel sheet can be formatted using the Style object created by CellsFactory.createStyle() method for instance you may set the title text horizontal and vertical alignment, the text color and italic or bold style. This object can be later set in the JsonLayoutOptions object using the setTitleStyle(titleStyle) method.
This article has taught us to convert a file from JSON format to PDF in Node.js. If you want to learn the process of exporting a CSV file to a PDF file, refer to the article on how to change CSV to PDF in Node.js.