auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
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 test = fs.statSync(dest);
console.log(test.size);
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),
compressPDF = PDFToolsSdk.CompressPDF, compressPDFOperation = compressPDF.Operation.createNew();
const input = PDFToolsSdk.FileRef.createFromLocalFile(dest);
compressPDFOperation.setInput(input);
try {
let result = await compressPDFOperation.execute(executionContext);
//it needs to write back to a new file, can't overwrite
this.newpdf = `/tmp/${nanoid()}.pdf`;
await result.saveAsFile(this.newpdf);
let test = fs.statSync(this.newpdf);
console.log('new size', test.size);
} 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
});
var file = steps.optimizepdf.newpdf;
try {
this.resp = await dbx.filesUpload({
path: params.file_path,
contents: file
})
} catch (err) {
this.err = err
}