Skip to content

Instantly share code, notes, and snippets.

View cfjedimaster's full-sized avatar
😺
Happy, and tired.

Raymond Camden cfjedimaster

😺
Happy, and tired.
View GitHub Profile
let response = await pdfServices.getJobResult({ pollingURL, resultType: CreatePDFResult });
const params = new ProtectPDFParams({
userPassword: "password",
encryptionAlgorithm: EncryptionAlgorithm.AES_256
});
// Create a new job instance
job = new ProtectPDFJob({inputAsset:response.result.asset, params});
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'));
import {
ServicePrincipalCredentials,
PDFServices,
MimeType,
CreatePDFJob,
CreatePDFResult,
ProtectPDFParams,
EncryptionAlgorithm,
ProtectPDFJob,
ProtectPDFResult
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}`,
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 is hard coded, but in a real application would be dynamic:
*/
let email = '[email protected]';
async function documentGenerationJob(asset, outputFormat, data, token, clientId) {
let body = {
'assetID': asset.assetID,
'outputFormat': outputFormat,
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.');
async function watermarkJob(source, watermark, token, clientId) {
let body = {
'inputDocumentAssetID': source.assetID,
'watermarkDocumentAssetID': watermark.assetID,
'appearance': {
'opacity':33
}
}
let resp = await fetch(REST_API + 'operation/addwatermark', {