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
{
option_two: 'Yes or Off',
option_one: 'Yes or Off',
name: 'A name',
option_three: 'Yes or Off',
age: 'A number, but as a string',
favorite_movie: 'One of three movies'
}
async function setFormDataJob(source, data, token, clientId) {
let body = {
'assetID': source.assetID,
'jsonFormFieldsData':data
}
let resp = await fetch('https://pdf-services-ue1.adobe.io/operation/setformdata', {
method: 'POST',
headers: {
let input = [
{ option_one: 'Yes', option_two: 'Off', option_three: 'Off', name: 'Jacob Smith', age: '90', favorite_movie: 'Star Wars' },
{ option_one: 'Off', option_two: 'Off', option_three: 'Off', name: 'Zelda Camden', age: '12', favorite_movie: 'Star Wars Again' },
{ option_one: 'Yes', option_two: 'Yes', option_three: 'Yes', name: 'Grace Undrapress', age: '45', favorite_movie: 'The Empire Strikes Back' },
];
let accessToken = await getAccessToken(CLIENT_ID, CLIENT_SECRET);
console.log('Got our access token.');
let sourceAsset = await getUploadData('application/pdf', accessToken, CLIENT_ID);
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;
favorite_movie value lies outside the list values, setting custom text is not allowed;
npm install @adobe/pdfservices-node-sdk
import {
ServicePrincipalCredentials,
PDFServices,
MimeType,
CreatePDFJob,
CreatePDFResult
} from '@adobe/pdfservices-node-sdk';
import fs from 'fs';
let CLIENT_ID = process.env.CLIENT_ID;
let CLIENT_SECRET = process.env.CLIENT_SECRET;
// Setup credentials
let credentials = new ServicePrincipalCredentials({ clientId: CLIENT_ID, clientSecret: CLIENT_SECRET });
let pdfServices = new PDFServices({ credentials });
const inputAsset = await pdfServices.upload({
readStream:fs.createReadStream('./input.docx'),
mimeType: MimeType.DOCX
});
console.log(`Source doc uploaded, asset ID is ${inputAsset.assetId}`);
let job = new CreatePDFJob({inputAsset});
let pollingURL = await pdfServices.submit({job});
let response = await pdfServices.getJobResult({ pollingURL, resultType: CreatePDFResult });
let streamAsset = await pdfServices.getContent({ asset: response.result.asset});
streamAsset.readStream.pipe(fs.createWriteStream('./output.pdf'));