RotatePagesOperation

RotatePagesOperation

An operation that allows rotation of specific pages in a PDF file.

Sample Usage:


 const credentials = PDFToolsSdk.Credentials.serviceAccountCredentialsBuilder()
           .fromFile("pdftools-api-credentials.json")
           .build(),
       executionContext = PDFToolsSdk.ExecutionContext.create(credentials),
       RotatePages = PDFToolsSdk.RotatePages,
       rotatePagesOperation = RotatePages.Operation.createNew();

 rotatePagesOperation.setInput(PDFToolsSdk.FileRef.createFromLocalFile('~/Documents/rotatePagesOperationInput.pdf',
 	RotatePages.SupportedSourceFormat.pdf));
 rotatePagesOperation.setAngleToRotatePagesBy(PDFToolsSdk.RotatePages.Angle._90);

 rotatePagesOperation.execute(executionContext)
     .then(result => result.saveAsFile('output/rotatePagesOperationOutput.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 RotatePagesOperation.

(static, constant) Angle

Properties:
Name Type Description
_90 number

Represents 90 degrees clockwise rotation

_180 number

Represents 180 degrees clockwise rotation

_270 number

Represents 270 degrees clockwise rotation

Supported rotation angle values for RotatePagesOperation.

Methods

(static) createNew() → {RotatePagesOperation}

Constructs a RotatePagesOperation instance.

Returns:

A new RotatePagesOperation instance.

Type
RotatePagesOperation

setInput(sourceFileRefnon-null)

Sets an input file.

Parameters:
Name Type Description
sourceFileRef FileRef

An input file.

setAngleToRotatePagesBy(anglenon-null, pageRangesopt)

Sets angle (in clockwise direction) for rotating pages of the input PDF file; can be invoked multiple times to set rotation angle for different set of pages.

Multiple invocation of this method on the same set of pages can result in rotating pages multiple times.

For e.g.:
PageRanges pageRanges = new PDFToolsSdk.PageRanges();
pageRanges.addSinglePage(1);
rotatePagesOperation.setAngleToRotatePagesBy(PDFToolsSdk.RotatePages.Angle._90, pageRanges);
rotatePagesOperation.setAngleToRotatePagesBy(PDFToolsSdk.RotatePages.Angle._180, pageRanges);
Above invocations will effectively rotate pages (as specified by the page ranges) by 270 degrees.

If pageRanges is not provided, all pages of the input PDF are rotated by the specified angle.

Parameters:
Name Type Attributes Description
angle RotatePagesOperation.Angle

Angle for rotation; see RotatePagesOperation.Angle for valid angle values.

pageRanges PageRanges <optional>

Page ranges of the PDF file for rotation.

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>