Skip to content

Instantly share code, notes, and snippets.

@cfjedimaster
Created August 2, 2024 15:52
Show Gist options
  • Save cfjedimaster/305e2118846f0f3d32d0ae51572e8ea9 to your computer and use it in GitHub Desktop.
Save cfjedimaster/305e2118846f0f3d32d0ae51572e8ea9 to your computer and use it in GitHub Desktop.
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