Created
September 23, 2020 23:16
-
-
Save benvanderberg/9e89d73487c6e8fff85fc71ab9cd4d01 to your computer and use it in GitHub Desktop.
This file contains 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
// 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