PDF Test1
@raymondcamden
code:
data:privatelast updated:4 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,000+ developers using the Pipedream platform
steps.
trigger
inactive
last updated:-last event:-
steps.
optimizepdf
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
}
60

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);
}

steps.
dropbox_upload_file
auth
to use OAuth tokens and API keys in code via theauths object
(auths.dropbox)
params
File path

Full path name such as /Folder1/Folder2/File Name.pdf

 
string ·params.file_path
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
}
22
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
}