PDF Processing Canonical Workflow
Introduction
The PDF Processing Canonical Workflow processes a PDF file and can perform 3 different tasks:
Text Chunking: extracts text from the PDF file pages. It can be configured to extract text chunks based on the file’s TOC (table of contents) or to treat paragraphs in the document as chunks.
Image Extraction: extracts a list of images per page with their corresponding name, size, and content.
Table Extraction: extracts HTML representations of tables in the PDF file. The extraction can be performed with the Tabula library or by using the AWS Textract service.
The PDF Processing Canonical Workflow has 2 main stages: one stage for the workflow configuration and one stage for the actual processing of the PDF files. It also has an optional stage for table extraction with AWS Textract that will or will not be executed depending on the configuration.
For the instructions below, please request and reference the following files:
workflow_pdf processing canonical workflow_export.aspire
pom.xml
Workflow configuration
Each Canonical Workflow has a configuration script where initialization variables can be set or changed according to the needs of the client. This script is always at the very beginning of the workflow stages.
Also, all necessary external jars are preloaded in the file “pdf-processing-workflow-[VERSION].jar,” which needs to be loaded in the “External Resources” sections of the processing stages.
Additionally, if AWS Textract is enabled, the AWS Textract component needs to be configured with the client AWS account and the document field that will contain the path to the S3 bucket where PDFs will be available or uploaded.
Configuration Variables
useChunking
This variable has to be set to true if PDF files’ text chunk extraction is required. Otherwise, set this variable to false.
tocChunking
Chunk extraction can be performed by TOC (table of contents) area or by paragraph. Set this variable to true if TOC extraction is required; otherwise, set it to false.
chunksFieldName
This variable controls the name of the field where the text chunks list is stored.
useImageExtraction
This variable has to be set to true if PDF files’ image extraction is required. Otherwise, set this variable to false.
imagesFieldName
This variable controls the name of the field where the images list is stored.
createImageSubjobs
This variable has to be set to true if you need to generate subjobs for images extracted from the PDF files. Otherwise, set this variable to false.
useTableExtraction
This variable has to be set to true if PDF file table extraction is required. Otherwise, set this variable to false.
useTextract
Basic table extraction can be performed using the Tabula library. A more advanced and accurate extraction can be performed by using the AWS Textract service. Set this variable to true if AWS Textract is required; otherwise, set it to false.
tablesFieldName
This variable controls the name of the field where the tables list is stored.
Expected Input
Job input
Job variable name | Job variable description |
contentStream | This variable holds the content of the file being processed. Normally it is not accessed directly but through framework functions such as “getContentStream“. Aspire connector’s text extraction consumes this stream, so be sure to turn off text extraction in the connector that uses the workflow. |
Document Input
Document variable name | Document variable description |
title | This variable is used to infer the name of the file and its extension. Used by all chunk, image, and table extraction. |
action | This variable is only used during subjobs creation. |
id | This variable is only used during subjobs creation. |
Workflow output
Job Output
Job variable name | Job variable description |
No job output variables.
Document Output
Document variable name | Document variable description |
[user_defined_field for text chunks] | A list of chunk objects. Each chunk object contains a section name, a list of paragraphs in the chunk, a chunk number, and a total number of words in the chunk (from all paragraphs in it). The name of the field is defined by the user in the workflow configuration. |
[user_defined_field for pdf images] | A list of image objects. Each image object contains a page index, the name of the image, the size of the image, and the content of the image. The name of the field is defined by the user in the workflow configuration. |
[user_defined_field for pdf tables] | A list of HTML table representations of tables in the PDF. The name of the field is defined by the user in the workflow configuration. |
If Chunk Extraction is enabled, PDF chunks will be listed inside a “pdfChunks” node inside the document. Inside the node, chunks found in the document will be listed:
If Image Extraction is enabled, a list of images will be generated inside a node called “pdfImages.” The node will contain image metadata as well as the image content from images in the PDF document:
If Table Extraction is enabled and Tabula is used to extract tables, the HTML representations of those tables will be in a “tables_html” node. Inside that node, we will have all the tables present in the PDF document.
Subjobs generated for images look like this:
Limitations
TOC Chunking
Extracting chunks with the Table of Contents option requires a good layout of the links in the processed document to get good and semantically meaningful chunks. Documents with links to random paragraphs or to a page footer, for instance, instead of the actual start or title of a topic, may result in poor-quality chunks.
Paragraph Chunking
Paragraph chunking quality is highly dependent on the paragraph structure of the PDF, so while a well-structured document might result in semantically meaningful chunks, a badly structured document will more likely result in non-meaningful or badly split chunks.
Table extraction with Tabula
Tabula library extraction, while having a fair quality table detection for well-defined tables in the document, might fail to recognize some types of tables that a more robust option, like, for example, AWS Textract, would. It could also generate an error sometimes if lines in a table are not perfectly vertical or horizontal.
Errors and Troubleshooting
Corrupt PDF Files
While no actual PDF files are used during the processing (an InputStream is generated from the content stream in the pipeline instead), previous manipulation of the content stream of the document might corrupt it and generate IOExceptions as a result. Pinpointing the part of the process that manipulates the content stream and fixing it is a way to solve the problem. A way to work around it would be to exclude the document altogether from the crawl.
Tabula generates many empty columns/rows
When extracting table data, you may notice the Tabula component might generate an exaggerated number of empty rows or columns. This is a known issue. Also, this won’t affect the display of tables in most browsers since these are ignored.
Tabula: “java.lang.IllegalArgumentException: lines must be orthogonal, vertical, and horizontal”
Tabula might throw this exception if it detects a table that has lines that are not perfectly horizontal or vertical.
General
Generally, the images and table lists generated by the corresponding extraction might come empty if the document does not contain images or tables or if the libraries fail to detect these objects. In the case of table extraction. Switching table extraction methods can help alleviate the issue.
Done!
Your workflow is now configured and ready to be used.