Created
January 2, 2024 14:04
-
-
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
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
// 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