This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
favorite_movie value lies outside the list values, setting custom text is not allowed; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install @adobe/pdfservices-node-sdk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
ServicePrincipalCredentials, | |
PDFServices, | |
MimeType, | |
CreatePDFJob, | |
CreatePDFResult | |
} from '@adobe/pdfservices-node-sdk'; | |
import fs from 'fs'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let response = await pdfServices.getJobResult({ pollingURL, resultType: CreatePDFResult }); | |
let streamAsset = await pdfServices.getContent({ asset: response.result.asset}); | |
streamAsset.readStream.pipe(fs.createWriteStream('./output.pdf')); |