ReorderPagesOperation

ReorderPagesOperation

An operation that allows to rearrange pages in a PDF file according to the specified order.

Sample Usage:


 const credentials = PDFToolsSdk.Credentials.serviceAccountCredentialsBuilder()
           .fromFile("pdftools-api-credentials.json")
           .build(),
       executionContext = PDFToolsSdk.ExecutionContext.create(credentials),
       ReorderPages = PDFToolsSdk.ReorderPages,
       reorderPagesOperation = ReorderPages.Operation.createNew(),
       pageRanges = new PDFToolsSdk.PageRanges();

 reorderPagesOperation.setInput(PDFToolsSdk.FileRef.createFromLocalFile('~/Documents/reorderPagesOperationInput.pdf',
 	ReorderPages.SupportedSourceFormat.pdf));
 pageRanges.addSinglePage(3);
 pageRanges.addPageRange(1,2);
 reorderPagesOperation.setPagesOrder(pageRanges);

 reorderPagesOperation.execute(executionContext)
     .then(result => result.saveAsFile('output/reorderPagesOperationOutput.pdf'))
     .catch(err => console.log(err));

Members

(static, constant) SupportedSourceFormat

Properties:
Name Type Description
pdf string

Represents "application/pdf" media type

Supported source file formats for ReorderPagesOperation.

Methods

(static) createNew() → {ReorderPagesOperation}

Constructs a ReorderPagesOperation instance.

Returns:

A new ReorderPagesOperation instance.

Type
ReorderPagesOperation

setInput(sourceFileRefnon-null)

Sets an input file.

Parameters:
Name Type Description
sourceFileRef FileRef

An input file.

setPagesOrder(pageRangesnon-null)

Sets the order of the pages.

Parameters:
Name Type Description
pageRanges PageRanges

Page ranges for reordering.

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

Executes this operation using the supplied context and returns a Promise which resolves to the operation result.

The resulting file 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.<FileRef>