Skip to content

Instantly share code, notes, and snippets.

@benvanderberg
Created September 23, 2020 23:16
Show Gist options
  • Save benvanderberg/9e89d73487c6e8fff85fc71ab9cd4d01 to your computer and use it in GitHub Desktop.
Save benvanderberg/9e89d73487c6e8fff85fc71ab9cd4d01 to your computer and use it in GitHub Desktop.
// Create an ExecutionContext using credentials
const executionContext = PDFToolsSdk.ExecutionContext.create(credentials);
// Create a new operation instance.
const splitPDFOperation = PDFToolsSdk.SplitPDF.Operation.createNew(),
input = PDFToolsSdk.FileRef.createFromLocalFile(
'resources/splitPDFInput.pdf',
PDFToolsSdk.SplitPDF.SupportedSourceFormat.pdf
);
// Set operation input from a source file.
splitPDFOperation.setInput(input);
// Set the number of documents to split the input PDF file into.
splitPDFOperation.setFileCount(2);
// Execute the operation and Save the result to the specified location.
splitPDFOperation.execute(executionContext)
.then(result => {
let saveFilesPromises = [];
for(let i = 0; i < result.length; i++){
saveFilesPromises.push(result[i].saveAsFile(`output/splitPDFOutput_${i}.pdf`));
}
return Promise.all(saveFilesPromises);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment