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 |
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
| async function watermarkJob(source, watermark, token, clientId) { | |
| let body = { | |
| 'inputDocumentAssetID': source.assetID, | |
| 'watermarkDocumentAssetID': watermark.assetID | |
| } | |
| let resp = await fetch(REST_API + 'operation/addwatermark', { | |
| method: 'POST', | |
| headers: { | |
| 'Authorization':`Bearer ${token}`, |
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 fs from 'fs'; | |
| import { Readable } from 'stream'; | |
| import { finished } from 'stream/promises'; | |
| let REST_API = "https://pdf-services.adobe.io/"; | |
| let CLIENT_ID = process.env.CLIENT_ID; | |
| let CLIENT_SECRET = process.env.CLIENT_SECRET; | |
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
| /* | |
| This is hard coded, but in a real application would be dynamic: | |
| */ | |
| let email = 'jedimaster@adobe.com'; | |
| async function documentGenerationJob(asset, outputFormat, data, token, clientId) { | |
| let body = { | |
| 'assetID': asset.assetID, | |
| 'outputFormat': outputFormat, |
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 sourceAsset = await getUploadData('application/pdf', accessToken, CLIENT_ID); | |
| await uploadFile(sourceAsset.uploadUri, SOURCE_PDF, 'application/pdf'); | |
| console.log('Source PDF Uploaded.'); | |
| let sourceAsset = await getUploadData('application/pdf', accessToken, CLIENT_ID); | |
| await uploadFile(sourceAsset.uploadUri, SOURCE_PDF, 'application/pdf'); | |
| console.log('Source PDF Uploaded.'); | |
| job = await watermarkJob(sourceAsset, docgenResult.asset, accessToken, CLIENT_ID); | |
| console.log('Watermark Job created. Now to poll it.'); |