ExportPDFOperation

ExportPDFOperation

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

For the image target formats (JPEG and PNG), the resulting file is a ZIP archive containing one image per page of the source PDF file. Each image file name ends with "_<unpadded_page_index>". For example, a PDF file with 15 pages will generate 15 image files. The first file's name ends with "_1" and the last file's name ends with "_15".

Sample Usage:


 const credentials = PDFToolsSdk.Credentials.serviceAccountCredentialsBuilder()
           .fromFile("pdftools-api-credentials.json")
           .build(),
       executionContext = PDFToolsSdk.ExecutionContext.create(credentials),
       ExportPDF = PDFToolsSdk.ExportPDF,
       exportPdfOperation = ExportPDF.Operation.createNew(ExportPDF.SupportedTargetFormats.DOCX),
       input = PDFToolsSdk.FileRef.createFromLocalFile('test/resources/PDF.pdf', ExportPDF.SupportedSourceFormat.pdf);

 exportPdfOperation.setInput(input);

 exportPdfOperation.execute(executionContext)
     .then(result => result.saveAsFile('output/exportPdf.docx'))
     .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 ExportPDFOperation.

(static, constant) SupportedExportFormats

Properties:
Name Type Description
DOC Object

Represents "application/msword" media type.

DOCX Object

Represents "application/vnd.openxmlformats-officedocument.wordprocessingml.document" media type

JPEG Object

Represents "image/jpeg" media type.

PNG Object

Represents "image/png" media type.

PPTX Object

Represents "application/vnd.openxmlformats-officedocument.presentationml.presentation" media type

RTF Object

Represents "text/rtf" media type.

XLSX Object

Represents "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" media type

List of target formats for ExportPDFOperation.

Methods

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

Constructs an ExportPDFOperation instance.

Parameters:
Name Type Description
targetFormat ExportPDFOperation.SupportedExportFormats

Format to which the PDF will be exported to.

Returns:

A new ExportPDFOperation instance

Type
ExportPDFOperation

setInput(sourceFileRefnon-null)

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

Parameters:
Name Type Description
sourceFileRef FileRef

An input PDF file.

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>