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
| 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 }); |
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
| 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}); |
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
| let response = await pdfServices.getJobResult({ pollingURL, resultType: CreatePDFResult }); | |
| let streamAsset = await pdfServices.getContent({ asset: response.result.asset}); | |
| streamAsset.readStream.pipe(fs.createWriteStream('./output.pdf')); |
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'; | |
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, | |
| ProtectPDFParams, | |
| EncryptionAlgorithm, | |
| ProtectPDFJob, | |
| ProtectPDFResult |
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
| let response = await pdfServices.getJobResult({ pollingURL, resultType: CreatePDFResult }); |
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
| const params = new ProtectPDFParams({ | |
| userPassword: "password", | |
| encryptionAlgorithm: EncryptionAlgorithm.AES_256 | |
| }); |
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
| // Create a new job instance | |
| job = new ProtectPDFJob({inputAsset:response.result.asset, params}); |
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
| pollingURL = await pdfServices.submit({job}); | |
| response = await pdfServices.getJobResult({ | |
| pollingURL, | |
| resultType: ProtectPDFResult | |
| }); | |
| // Get content from the resulting asset(s) | |
| let streamAsset = await pdfServices.getContent({ asset: response.result.asset}); | |
| streamAsset.readStream.pipe(fs.createWriteStream('./output_protected.pdf')); |
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, | |
| ProtectPDFParams, | |
| EncryptionAlgorithm, | |
| ProtectPDFJob, | |
| ProtectPDFResult |