ExportPDFToImagesOperation

ExportPDFToImagesOperation

An operation which exports a source PDF file to a supported format specified by ExportPDFToImagesOperation.SupportedExportFormats.

The result is a list of images. For example, a PDF file with 15 pages will generate 15 image files. The first file's name ends with "_0" and the last file's name ends with "_14".

Sample Usage:


 const credentials = PDFServicesSdk.Credentials.servicePrincipalCredentialsBuilder()
           .withClientId("PDF_SERVICES_CLIENT_ID")
           .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
           .build(),
       executionContext = PDFServicesSdk.ExecutionContext.create(credentials),
       ExportPDFToImages = PDFServicesSdk.ExportPDFToImages,
       exportPDFToImages = ExportPDFToImages.Operation.createNew(ExportPDFToImages.SupportedTargetFormats.JPEG),
       input = PDFServicesSdk.FileRef.createFromLocalFile('PDF.pdf', ExportPDFToImages.SupportedSourceFormat.pdf);

 exportPDFToImages.setInput(input);

 exportPDFToImages.execute(executionContext)
     .then(result => {
          let saveFilesPromises = [];
          for(let i = 0; i < result.length; i++){
              saveFilesPromises.push(result[i].saveAsFile(`output/exportPDFToJPEGOutput_{i}.jpeg`));
          }
          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 ExportPDFToImagesOperation.

(static, constant) SupportedExportFormats

Description:
  • List of target formats for ExportPDFToImages.

Properties:
Name Type Description
JPEG Object

Represents "image/jpeg" media type.

PNG Object

Represents "image/png" media type.

List of target formats for ExportPDFToImages.

(static, constant) OutputType

Description:
Properties:
Name Type Description
LIST_OF_PAGE_IMAGES string

Represents List Output type

ZIP_OF_PAGE_IMAGES string

Represents Zip Output type

List of supported outputTypes for ExportPDFToImagesOperation

Methods

(static) createNew(targetFormatnon-null) → {ExportPDFToImagesOperation}

Description:
Parameters:
Name Type Description
targetFormat ExportPDFToImagesOperation.SupportedExportFormats

Format to which the PDF will be exported to.

Returns:

A new ExportPDFToImagesOperation instance

Type
ExportPDFToImagesOperation

setInput(sourceFileRefnon-null)

Description:
  • Sets an input PDF file (media type "application/pdf").

Parameters:
Name Type Description
sourceFileRef FileRef

An input PDF file.

setOutputType(outputTypenon-null)

Description:
Parameters:
Name Type Description
outputType ExportPDFToImagesOperation.OutputType

see ExportPDFToImagesOperation.OutputType. Default value is ExportPDFToImagesOperation.OutputType.LIST_OF_PAGE_IMAGES

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

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

    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>>