Aspose.Total for Java is a comprehensive suite of APIs that enables developers to easily convert JSON to PS in their Java applications. It consists of two powerful APIs, Aspose.Cells for Java and Aspose.Words for Java, which can be used in a two-step process to achieve the desired result.
The first step involves using Aspose.Cells for Java to parse JSON to PDF. This API provides a wide range of features that enable developers to create, manipulate, and convert spreadsheets in various formats. It also provides the ability to parse JSON to PDF, which is essential for the conversion process.
The second step involves using Aspose.Words for Java to convert PDF to PS. This API provides a comprehensive set of features that enable developers to create, manipulate, and convert documents in various formats. It also provides the ability to convert PDF to PS, which is essential for the conversion process.
Overall, Aspose.Total for Java is an ideal solution for developers who need to convert JSON to PS in their Java applications. It provides a comprehensive suite of APIs that enable developers to easily and quickly achieve the desired result.
Convert JSON Format to PS via Java
- Create a new Workbook object and read valid JSON data from file
- Import JSON file to worksheet using JsonUtility class and Save it as PDF
- Load PDF document by using Document class
- Save the document to PS format using Save method
Conversion Requirements
You can easily use Aspose.Total for Java directly from a Maven based project and include libraries in your pom.xml.
Alternatively, you can get a ZIP file from downloads .
// create a blank Workbook object | |
Workbook workbook = new Workbook(); | |
// access default empty worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Read JSON file | |
String jsonInput = new String(Files.readAllBytes("SampleJson.json")); | |
// import JSON data to default worksheet starting at cell A1 | |
JsonUtility.importData(jsonInput, worksheet.getCells(), 0, 0, new JsonLayoutOptions()); | |
// save resultant file in JSON-TO-PDF format | |
workbook.save("output.pdf", SaveFormat.AUTO); | |
// load PDF with an instance of Document | |
var document = new Document("output.pdf"); | |
// supports DOC, DOT, DOCM, DOTX, DOTX, FLATOPC, RTF, WordML, MOBI, CHM, ODT, OTT, PS, PCL, EPUB file formats | |
// call Save method while passing SaveFormat.DOC | |
document.Save("output.doc", SaveFormat.Doc); |
Set Layout & Convert JSON Format to PS via Java
Furthermore, the API allows you to set layout options for your JSON while parsing JSON to PS using JsonLayoutOptions . It allows you to process Array as a table, ignore nulls, ignore array title, ignore object title, convert string to number or date, set date and number format, and set title style. All of these options allow you to present your data as per your needs. The following code snippet shows you how to set the layout options.
// create a blank Workbook object | |
Workbook workbook = new Workbook(); | |
// access default empty worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// read JSON file | |
String jsonInput = new String(Files.readAllBytes("SampleJson.json")); | |
// set JsonLayoutOptions for formatting | |
JsonLayoutOptions layoutOptions = new JsonLayoutOptions(); | |
layoutOptions.setArrayAsTable(true); | |
layoutOptionssetConvertNumericOrDate(true); | |
layoutOptionssetIgnoreArrayTitle(true); | |
layoutOptionssetIgnoreNull(true); | |
layoutOptionssetIgnoreObjectTitle(true); | |
// import JSON data to default worksheet starting at cell A1 | |
JsonUtility.importData(jsonInput, worksheet.getCells(), 0, 0, layoutOptions); | |
// save resultant file in JSON-TO-PDF format | |
workbook.save("output.pdf", SaveFormat.AUTO); | |
// load PDF with an instance of Document | |
var document = new Document("output.pdf"); | |
// supports DOC, DOT, DOCM, DOTX, DOTX, FLATOPC, RTF, WordML, MOBI, CHM, ODT, OTT, PS, PCL, EPUB file formats | |
// call Save method while passing SaveFormat.DOC | |
document.Save("output.doc", SaveFormat.Doc); |
Convert JSON Format to PS with Watermark via Java
Using the API, you can also parse JSON to PS with watermark. In order to add a watermark to your PS document, you can first convert the JSON file to PDF and add a watermark to it. In order to add a watermark, load the newly created PDF file using the Document class, create an instance of TextWatermarkOptions and set its properties, Call Watermark.setText method and pass watermark text & object of TextWatermarkOptions. After adding the watermark, you can save the document to PS.
// create a blank Workbook object | |
Workbook workbook = new Workbook(); | |
// access default empty worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Read JSON file | |
String jsonInput = new String(Files.readAllBytes("SampleJson.json")); | |
// import JSON data to default worksheet starting at cell A1 | |
JsonUtility.importData(jsonInput, worksheet.getCells(), 0, 0, new JsonLayoutOptions()); | |
// save resultant file in JSON-TO-PDF format | |
workbook.save("output.pdf", SaveFormat.AUTO); | |
// load PDF with an instance of Document | |
var document = new Document("output.pdf"); | |
TextWatermarkOptions options = new TextWatermarkOptions(); | |
options.setFontFamily("Arial"); | |
options.setFontSize(36); | |
options.setColor(Color.BLACK); | |
options.setLayout(WatermarkLayout.HORIZONTAL); | |
options.isSemitrasparent(false); | |
document.getWatermark().setText("Test", options); | |
// supports DOC, DOT, DOCM, DOTX, DOTX, FLATOPC, RTF, WordML, MOBI, CHM, ODT, OTT, PS, PCL, EPUB file formats | |
// call Save method while passing SaveFormat.DOC | |
document.Save("output.doc", SaveFormat.Doc); |