Auto Protect PDF
@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.
protectpdf
auth
to use OAuth tokens and API keys in code via theauths object
params
Password
 
string ·params.password
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) => {
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
61
62
63
}
64

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

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
}
23
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
}