CreatePDFOperation

CreatePDFOperation

An operation that converts a non-PDF file to a PDF file. Some source formats may have associated conversion parameters which can be set in the CreatePDFOperation#setOptions method.

The supported source media types are listed here. The SupportedSourceFormat object can be used to map file extensions to their corresponding media types when creating FileRef instances for the source files.

  • application/msword
  • application/vnd.ms-excel
  • application/vnd.ms-powerpoint
  • application/vnd.openxmlformats-officedocument.presentationml.presentation
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • application/zip (see "Special handling for HTML inputs" below)
  • image/bmp
  • image/gif
  • image/jpeg
  • image/png
  • image/tiff
  • text/html
  • text/plain
  • text/rtf

Special handling for HTML inputs:

An HTML input can be provided either as a local zip archive or as a static HTML file with inline CSS. Alternatively, an HTML can also be specified via URL using FileRef.createFromURL.
While creating the corresponding FileRef instance, the media type must be:

  • "application/zip", if the input is a local zip archive.
  • "text/html", if the input is a static HTML file with inline CSS

In case the input is a local zip archive, it must have the following structure:

    Sample layout:

       html_files.zip
       |__index.html
       |__referenced_file_1.css
       |__referenced_file_2.jpeg
       |__subfolder_1
       |_____referenced_file_3.jpeg
     

    Sample Usage:

    
     const credentials = PDFServicesSdk.Credentials.servicePrincipalCredentialsBuilder()
               .withClientId("PDF_SERVICES_CLIENT_ID")
               .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
               .build(),
           executionContext = PDFServicesSdk.ExecutionContext.create(credentials),
           CreatePDF = PDFServicesSdk.CreatePDF,
           createPDFOperation = CreatePDF.Operation.createNew(),
           input = PDFServicesSdk.FileRef.createFromLocalFile('createPDFInput.docx', CreatePDF.SupportedSourceFormat.docx);
    
     createPDFOperation.setInput(input);
    
     createPDFOperation.execute(executionContext)
         .then(result => result.saveAsFile('createPDF.pdf'))
         .catch(err => console.log(err));
    
    

Members

(static, constant) SupportedMediaTypes

Description:
Deprecated:
  • Since version 1.1.0; Use SupportedSourceFormat instead.
Properties:
Name Type Description
bmp string

Represents "image/bmp" media type

doc string

Represents "application/msword" media type

docx string

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

gif string

Represents "image/gif" media type

html string

Represents "text/html" media type

jpeg string

Represents "image/jpeg" media type

jpg string

Represents "image/jpeg" media type

png string

Represents "image/png" media type

ppt string

Represents "application/vnd.ms-powerpoint" media type

pptx string

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

rtf string

Represents "text/rtf" media type

tif string

Represents "image/tiff" media type

tiff string

Represents "image/tiff" media type

txt string

Represents "text/plain" media type

xls string

Represents "application/vnd.ms-excel" media type

xlsx string

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

zip string

Represents "application/zip" media type

Supported source file formats for CreatePDFOperation.

(static, constant) SupportedSourceFormat

Description:
Properties:
Name Type Description
bmp string

Represents "image/bmp" media type

doc string

Represents "application/msword" media type

docx string

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

gif string

Represents "image/gif" media type

html string

Represents "text/html" media type

jpeg string

Represents "image/jpeg" media type

jpg string

Represents "image/jpeg" media type

png string

Represents "image/png" media type

ppt string

Represents "application/vnd.ms-powerpoint" media type

pptx string

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

rtf string

Represents "text/rtf" media type

tif string

Represents "image/tiff" media type

tiff string

Represents "image/tiff" media type

txt string

Represents "text/plain" media type

xls string

Represents "application/vnd.ms-excel" media type

xlsx string

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

zip string

Represents "application/zip" media type

Supported source file formats for CreatePDFOperation.

Methods

(static) createNew() → {CreatePDFOperation}

Description:
  • Constructs a CreatePDFOperation instance.

Returns:

A new CreatePDFOperation instance.

Type
CreatePDFOperation

setInput(sourceFileRefnon-null)

Description:
  • Sets an input file.

Parameters:
Name Type Description
sourceFileRef FileRef

An input file.

setOptions(options)

Description:
  • Sets the conversion parameters for this operation.

Parameters:
Name Type Description
options Object

Conversion parameters; use null for default values. The type of this parameter depends on the source format of the file which is being converted to PDF. For example, for HTML to PDF conversions, the type will be CreatePDFFromHtmlOptions. For other supported options, refer the options key. in module:PDFServicesSDK#CreatePDF.

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

Description:
  • 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>