Created
August 2, 2024 15:52
-
-
Save cfjedimaster/305e2118846f0f3d32d0ae51572e8ea9 to your computer and use it in GitHub Desktop.
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
import { | |
ServicePrincipalCredentials, | |
PDFServices, | |
MimeType, | |
CreatePDFJob, | |
CreatePDFResult | |
} from '@adobe/pdfservices-node-sdk'; | |
import fs from 'fs'; | |
let CLIENT_ID = process.env.CLIENT_ID; | |
let CLIENT_SECRET = process.env.CLIENT_SECRET; | |
// Setup credentials | |
let credentials = new ServicePrincipalCredentials({ clientId: CLIENT_ID, clientSecret: CLIENT_SECRET }); | |
let pdfServices = new PDFServices({ credentials }); | |
const inputAsset = await pdfServices.upload({ | |
readStream:fs.createReadStream('./input.docx'), | |
mimeType: MimeType.DOCX | |
}); | |
console.log(`Source doc uploaded, asset ID is ${inputAsset.assetId}`); | |
let job = new CreatePDFJob({inputAsset}); | |
let pollingURL = await pdfServices.submit({job}); | |
console.log(`Create PDF job begun, polling url is ${pollingURL}`); | |
let response = await pdfServices.getJobResult({ pollingURL, resultType: CreatePDFResult }); | |
let streamAsset = await pdfServices.getContent({ asset: response.result.asset}); | |
streamAsset.readStream.pipe(fs.createWriteStream('./output.pdf')); | |
console.log('All done and result PDF saved.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment