Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Created January 2, 2024 14:04
Show Gist options
  • Save groupdocs-cloud-gists/c1a40ab6fac6fe4f0f1fd05b8468eeb5 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/c1a40ab6fac6fe4f0f1fd05b8468eeb5 to your computer and use it in GitHub Desktop.
Convert JSON to PDF in Node.js - JSON to PDF Converter
// Get the groupdocs-conversion-cloud module into your project.
let groupdocs_conversion_cloud = require("groupdocs-conversion-cloud");
// Define your API credentials
const clientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
const clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
myStorage = "test";
// Initialize an object of the ConvertApi with the API credentials.
const convertApi = groupdocs_conversion_cloud.ConvertApi.fromKeys(clientId, clientSecret);
// Instantiate an instance of the ConvertSettings class and set the values such as filePath, format, storageName and outputPath.
const settings = new groupdocs_conversion_cloud.ConvertSettings();
settings.storageName = myStorage;
settings.filePath = "sample.json";
settings.format = "pdf";
settings.outputPath = "output/sample-file.pdf";
try {
// Initialize the object of the ConvertDocumentRequest class with the object of the ConvertSettings class.
const request = new groupdocs_conversion_cloud.ConvertDocumentRequest(settings);
// Call the convertDocument method to convert JSON to PDF.
convertApi.convertDocument(request).then(()=>{})
}
catch (err) {
console.log(err);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment