ExtractPdfOperation

ExtractPdfOperation

An Operation that extracts pdf elements such as text, images, tables in a structured format from a PDF.

Sample Usage:


 try {
	const credentials =  PDFServicesSdk.Credentials
		.serviceAccountCredentialsBuilder()
		.fromFile("pdfservices-api-credentials.json")
		.build();

	const clientConfig = PDFServicesSdk.ClientConfig
		.clientConfigBuilder()
		.fromFile("pdfservices-api-client-config.json")
		.build();

	const clientContext = PDFServicesSdk.ExecutionContext
		.create(credentials,clientConfig);

	const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder()
		.addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT)
		.addElementsToExtractRenditions(PDFServicesSdk.ExtractPDF.options.ExtractRenditionsElementType.TABLES)
		.addCharInfo(true)
		.addTableStructureFormat(PDFServicesSdk.ExtractPDF.options.TableStructureType.CSV)
		.build();

	const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(),
		input = PDFServicesSdk.FileRef.createFromLocalFile(
			'test/resources/extractPDFInput',
			PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf
		);

	extractPDFOperation.setInput(input);
	extractPDFOperation.setOptions(input);

	extractPDFOperation.execute(clientContext)
		.then(result => result.saveAsFile('output/extractPdf.zip'))
		.catch(err => console.log(err));
  } catch (err) {
	throw err;
 }

Members

(static, constant) SupportedSourceFormat

Description:
Properties:
Name Type Description
pdf string

Represents "application/pdf" media type

Supported source file formats for ExtractPdfOperation is .pdf.

Methods

(static) createNew() → {ExtractPdfOperation}

Description:
Returns:

A new ExtractPdfOperation instance.

Type
ExtractPdfOperation

setInput(sourceFileRefnon-null)

Description:
  • Sets an input file.

Parameters:
Name Type Description
sourceFileRef FileRef

An input file.

setOptions(optionsnon-null)

Description:
  • Sets the options for Extract PDF operation

Parameters:
Name Type Description
options ExtractPDFOptions

Options specifying the Parameters for extract PDF

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

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