public class RotatePagesOperation extends Object implements Operation
Sample Usage:
RotatePagesOperation rotatePagesOperation = RotatePagesOperation.createNew();
rotatePagesOperation.setInput(FileRef.createFromLocalFile("~/Documents/rotatePagesOperationInput.pdf",
RotatePagesOperation.SupportedSourceFormat.PDF.getMediaType()));
rotatePagesOperation.setAngleToRotatePagesBy(Angle._90);
Credentials credentials = Credentials.serviceAccountCredentialsBuilder().fromFile("pdftools-api-credentials.json").build();
FileRef result = rotatePagesOperation.execute(ExecutionContext.create(credentials));
result.saveAs("output/rotatePagesOperationOutput.pdf");
Modifier and Type | Class and Description |
---|---|
static class |
RotatePagesOperation.SupportedSourceFormat
Supported source file formats for
RotatePagesOperation . |
Modifier and Type | Method and Description |
---|---|
static RotatePagesOperation |
createNew()
Constructs a
RotatePagesOperation instance. |
FileRef |
execute(ExecutionContext context)
Executes this operation synchronously using the supplied context and returns a new FileRef instance for the resulting PDF file.
|
void |
setAngleToRotatePagesBy(Angle angle)
Sets angle (in clockwise direction) for rotating all the pages of the input PDF file.
|
void |
setAngleToRotatePagesBy(Angle angle,
PageRanges pageRanges)
Sets angle (in clockwise direction) for rotating the specified pages of the input PDF file; can be invoked
multiple times to set rotation for different set of page ranges.
|
void |
setInput(FileRef sourceFileRef)
Sets an input file.
|
public static RotatePagesOperation createNew()
RotatePagesOperation
instance.RotatePagesOperation
instancepublic void setInput(FileRef sourceFileRef)
sourceFileRef
- an input file; can not be nullpublic void setAngleToRotatePagesBy(Angle angle)
Multiple invocations of this method will result in rotating the pages multiple times.
angle
- angle for rotation; see Angle
for valid angle valuespublic void setAngleToRotatePagesBy(Angle angle, PageRanges pageRanges)
Multiple invocations of this method on the same set of pages can result in rotating the pages multiple times.
For e.g.: PageRanges pageRanges = new PageRanges(); pageRanges.addSinglePage(1); rotatePagesOperation.setAngleToRotatePagesBy(Angle._90, pageRanges); rotatePagesOperation.setAngleToRotatePagesBy(Angle._180, pageRanges);Above invocations will effectively rotate pages (as specified by the page ranges) by 270 degrees.
angle
- angle for rotation; see Angle
for valid angle valuespageRanges
- page ranges for rotation; can not be null or emptypublic FileRef execute(ExecutionContext context) throws ServiceApiException, IOException, ServiceUsageException
The resulting file may be stored in the system temporary directory (per java.io.tmpdir System property).
See FileRef
for how temporary resources are cleaned up.
execute
in interface Operation
context
- the context in which to execute the operationServiceApiException
- if an API call results in an error responseIOException
- if there is an error in reading either the input source or the resulting PDF fileServiceUsageException
- if service usage limits have been reached or credentials quota has been exhaustedCopyright © 2020 Adobe. All rights reserved.