auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params) => {
}
console.log('new file size is '+event.size);
const PDFToolsSdk = require('@adobe/documentservices-pdftools-node-sdk');
const fs = require("fs");
const got = require("got");
const stream = require("stream");
const { promisify } = require("util");
const pipeline = promisify(stream.pipeline);
const nanoid = require('nanoid').nanoid;
let dest = `/tmp/${nanoid()}.pdf`;
await pipeline(
got.stream(event.link),
fs.createWriteStream(dest)
);
console.log('file streamed down to ' + dest);
let creds = {
clientId:process.env.ADOBE_CLIENT_ID,
clientSecret:process.env.ADOBE_CLIENT_SECRET,
privateKey:process.env.ADOBE_KEY,
organizationId:process.env.ADOBE_ORGANIZATION_ID,
accountId:process.env.ADOBE_ACCOUNT_ID
}
const credentials = PDFToolsSdk.Credentials.serviceAccountCredentialsBuilder()
.withClientId(creds.clientId)
.withClientSecret(creds.clientSecret)
.withPrivateKey(creds.privateKey)
.withOrganizationId(creds.organizationId)
.withAccountId(creds.accountId)
.build();
const executionContext = PDFToolsSdk.ExecutionContext.create(credentials);
const protectPDF = PDFToolsSdk.ProtectPDF,
options = new protectPDF.options.PasswordProtectOptions.Builder()
.setUserPassword(params.password)
.setEncryptionAlgorithm(PDFToolsSdk.ProtectPDF.options.EncryptionAlgorithm.AES_256)
.build();
// Create a new operation instance.
const protectPDFOperation = protectPDF.Operation.createNew(options);
const input = PDFToolsSdk.FileRef.createFromLocalFile(dest);
protectPDFOperation.setInput(input);
try {
let result = await protectPDFOperation.execute(executionContext);
//it needs to write back to a new file, can't overwrite
this.newpdf = `/tmp/${nanoid()}.pdf`;
await result.saveAsFile(this.newpdf);
} catch(e) {
console.log('error', e);
}
auths
objectFull path name such as /Folder1/Folder2/File Name.pdf
return
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params, auths) => {
}
const fetch = require('isomorphic-fetch');
const { Dropbox } = require('dropbox');
const dbx = new Dropbox({
accessToken: auths.dropbox.oauth_access_token,
fetch
});
let file = steps.protectpdf.newpdf;
const fs = require("fs");
try {
this.resp = await dbx.filesUpload({
path: params.file_path,
contents: fs.readFileSync(file)
})
} catch (err) {
this.err = err
}