SplitPDFOperation

SplitPDFOperation

An operation that splits PDF document into multiple smaller documents by simply specifying either the number of files, pages per file, or page ranges.

Sample Usage:


 const credentials = PDFServicesSdk.Credentials.servicePrincipalCredentialsBuilder()
           .withClientId("PDF_SERVICES_CLIENT_ID")
           .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
           .build(),
       executionContext = PDFServicesSdk.ExecutionContext.create(credentials),
       SplitPDF = PDFServicesSdk.SplitPDF,
       splitPDFOperation = SplitPDF.Operation.createNew();

 splitPDFOperation.setInput(PDFServicesSdk.FileRef.createFromLocalFile('~/Documents/splitPDFInput.pdf',
 	SplitPDF.SupportedSourceFormat.pdf));
 splitPDFOperation.setPageCount(2);

 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);
      })
     .catch(err => console.log(err));

Members

(static, constant) SupportedSourceFormat

Description:
Properties:
Name Type Description
pdf string

Represents "application/pdf" media type

Supported source file formats for SplitPDFOperation.

Methods

(static) createNew() → {SplitPDFOperation}

Description:
Returns:

A new SplitPDFOperation instance.

Type
SplitPDFOperation

setInput(sourceFileRefnon-null)

Description:
  • Sets an input file.

Parameters:
Name Type Description
sourceFileRef FileRef

An input file.

setPageRanges(pageRangesnon-null)

Description:
  • Sets the page ranges on the basis of which to split the input PDF file. Each page range corresponds to a single output file having the pages specified in the page range.

Parameters:
Name Type Description
pageRanges PageRanges

Page ranges for split.

setFileCount(fileCountnon-null)

Description:
  • Sets the number of documents to split the input PDF.

Parameters:
Name Type Description
fileCount Number

Represents the number of output files.

setPageCount(pageCountnon-null)

Description:
  • Sets the maximum number of pages each of the output files can have.

Parameters:
Name Type Description
pageCount Number

Maximum number of pages per output file.

execute(contextnon-null) → {Promise.<Array.<FileRef>>}

Description:
  • Executes this operation synchronously using the supplied context and returns a new list of FileRef instances for the resultant PDF files.

    The resultant files may be stored in the system temporary directory (per the os.tempdir(), symlinks are resolved to the actual path). See FileRef for how temporary resources are cleaned up.

Parameters:
Name Type Description
context ExecutionContext

The context in which the operation will be executed.

Throws:
  • if an API call results in an error response.

    Type
    ServiceApiError
  • if service usage limits have been reached or credentials quota has been exhausted.

    Type
    ServiceUsageError
Returns:

A promise which resolves to the operation result.

Type
Promise.<Array.<FileRef>>