OCROperation

OCROperation

Convert a PDF file into a searchable PDF file. Allows specifying locale(OCROptions.OCRSupportedLocale) and OCR Type (OCROptions.OCRSupportedType) for performing OCR (Optical Character Recognition)

Sample Usage:


 const credentials = PDFServicesSdk.Credentials.servicePrincipalCredentialsBuilder()
           .withClientId("PDF_SERVICES_CLIENT_ID")
           .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
           .build(),
       executionContext = PDFServicesSdk.ExecutionContext.create(credentials),
       OCR = PDFServicesSdk.OCR,
       ocrOperation = OCR.Operation.createNew(),
       input = PDFServicesSdk.FileRef.createFromLocalFile('ocrInput.pdf', OCR.SupportedSourceFormat.pdf);

 ocrOperation.setInput(input);

 ocrOperation.execute(executionContext)
     .then(result => result.saveAsFile('ocrOutput.pdf'))
     .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 OCROperation.

Methods

(static) createNew() → {OCROperation}

Description:
Returns:

A new OCROperation instance.

Type
OCROperation

setInput(sourceFileRefnon-null)

Description:
  • Sets an input file.

Parameters:
Name Type Description
sourceFileRef FileRef

An input file.

setOptions(optionsopt)

Description:
  • Sets the options for this operation. See OCROptions for how to specify the options for the different locales and ocr types.

Parameters:
Name Type Attributes Description
options OCROptions <optional>

optional parameters; use null for default values.

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>