Edit in GitHubLog an issue

Extract PDF

Structured Information Output Format#

The output of an SDK extract operation is a zip package containing the following:

  • The structuredData.json file with the extracted content & PDF element structure. See the JSON schema for a description of the default output. (Please refer the Styling JSON schema for a description of the output when the styling option is enabled.)
  • A renditions folder(s) containing renditions for each element type selected as input. The folder name is either "tables" or "figures" depending on your specified element type. Each folder contains renditions with filenames that correspond to the element information in the JSON file.

Extract sample directory structure

The following is a summary of key elements in the extracted JSON(See additional descriptions in the JSON schema):

  • Elements : Ordered list of semantic elements (like headings, paragraphs, tables, figures) found in the document, on the basis of position in the structure tree of the document.The output does not include headers or footers.In addition, headings that repeat across pages are reported for the first occurrence only.

  • Bounds : Bounding box enclosing the content items forming this element. Not reported for elements which don't have any content items (like empty table cells). The bounds are as per PDF specification coordinates. PDF pages are generally specified in inches (like A4 page is 8.3 inches x 11.7 inches). If values are required in coordinates, we need a DPI value i.e. dots per inches. As per PDF specification, 72 DPI is used when creating a PDF. So, width of an A4 page is specified to be ~= 598 units (8.3 inches x 72) when creating the PDF. All values reported in Extract use this 72 dpi based coordinates. Again as per PDF spec, absolute values of bounds are in a coordinate system where origin is (0,0), up and right directions are positive. Going by this coordinate system, for all rects reported in Extract, bottom < top and left < right. In Extract JSON schema, all rects are of type #/definitions/rect and rect is defined as:

    description: Rectangle/Box in PDF coordinate system (bottom-left is origin). Values are in PDF user space units. Order of values - left, bottom, right, top.

  • Font : Font description for the font associated with the first character. Only reported for text elements.

  • TextSize : Text size (in points) of the last character. Only reported for text elements.

  • Attributes: Includes additional properties like line height and text alignment.

  • Path : The Path describes the location of elements in the structure tree including the element type and the instance number. Path along with bounds defines the reading order of the document. Element types are based on the ISO standard , a summary is included below for convenience :

    • Aside : Content which is not part of regular content flow of the document
    • Figure : Non-reflowable constructs like graphs, images, flowcharts
    • Footnote : FootNote
    • H, H1, H2, etc : Heading Level
    • L : List
    • Li : List Item
    • Lbl : List Item label
    • Lbody : List item body
    • P : Paragraph
    • ParagraphSpan : Denotes part of a paragraph. Reported when paragraph is broken (generally due to page break or column break)
    • Reference : Link
    • Sect : Logical section of the document
    • StyleSpan : Denotes difference in styling of text relative to the parent container
    • Sub : Single line of a multiline paragraph (e.g. addresses). Such paras are created in html using \<br> inside \<p> tags
    • Table : Table
    • TD : Table cell
    • TH : Table header cell
    • TR : Table row
    • Title : Title of the document. This is the most prominent heading which can define the whole document.
    • TOC : Table of contents
    • TOCI : Table of contents item
    • Watermark : Watermark
  • Text : Text for the element in UTF-8 format, only reported for text elements. When inline elements are reported separately from parent block element, then this value has references to those inline elements.

  • Figures : Identified as a Figure in the Path attribute, saved as a PNG in the figures folder with the filename identified in the filePaths attribute.

  • Tables : Identified as a Table in the Path attribute, saved as a .CSV, .XLSX, and .PNG in the tables folder with the filename identified in the filePaths attribute.

  • FilePaths : List of file paths to additional output files (images and spreadsheets)

  • Pages : A list of properties for each page of the PDF including page number, width, height, and rotation.

  • Reading Order : The reading order of content within columns, across page breaks, and inclusive of asides is represented by the order of the elements in the Elements array. In the normal mode, exceptions can occur for elements extracted from their container (eg. A reference link in the middle of a paragraph). However, the order is preserved in Styling mode where all Elements and their Kids are represented in the natural reading order. Reading order is determined by Bounds and path element provided in the .json file.

API limitations#

  • File size: Files up to a maximum of 100MB are supported.
  • Number of Pages: Non-scanned PDFs up to 200 pages and scanned PDFs up to 100 pages are supported, however limits may be lower for files with a large number of tables.
  • Rate limits: Keep request rate below 25 requests per minutes.
  • Page Size: The API supports standard page sizes not to exceed 17.5” or less than 6” in either dimension.
  • Hidden Objects: PDF files that contain content that is not visible on the page like javascript, OCG (optional content groups), etc are not supported. Files that contain such hidden information may fail to process. For such cases, removing hidden content prior to processing files again may return a successful result.
  • Language: The API is currently optimized for English language content. Files containing content in other Latin languages should return good results, but may have issues with non-English punctuation.
  • OCR and Scan quality: The quality of text extracted from scanned files is dependent on the clarity of content in the input file. Conditions like skewed pages, shadowing, obscured or overlapping fonts, and page resolution less than 200 DPI can all result in lower quality text output.
  • Form fields: Files containing XFA and other fillable form elements are not supported.
  • Unprotected files: The API supports files that are unprotected or where security restrictions allow copying of content. Files that are secured and do not allow copying of content will not be processed.
  • Annotations: Content in PDF files containing annotations such as highlights and sticky notes will be processed, but annotations that obscure text could impact output quality. Text within annotations will not be included in the output.
  • PDF Producers: The Extract API is designed to extract content from files that contain text, table data, and figures. Files created from applications that produce other types of content like illustrations, CAD drawings or other types of vector art may not return quality results.
  • PDF Collections: PDFs that are made from a collection of files including PDF Portfolios are not currently supported.

Error codes#

ScenarioError codeError message
Invalid API parameters-Invalid parameters
File size violationDISQUALIFIED_FILE_SIZEFile exceeds size limit.
Page limit violationDISQUALIFIED_PAGE_LIMITFile exceeds page limit.
Scan page limit violationDISQUALIFIED_SCAN_PAGE_LIMITScanned file exceeds page limit.
Unsupported XFA fileDISQUALIFIED_XFAFile contains XFA form(s). Not supported for content extraction.
Encryption permissionDISQUALIFIED_ENCRYPTIONFile permissions do not allow for content extraction.
Complex fileDISQUALIFIED_CMPLX_FILEFile contents are too complex for content extraction.
Bad PDFBAD_PDFUnable to extract content. File is corrupted, malformed or an empty PDF.
Invalid file typeBAD_PDF_FILE_TYPEThe input file is not a PDF file.
Damaged fileBAD_PDF_DAMAGEDThe input file is damaged.
File contains complex tableBAD_PDF_COMPLEX_TABLEThe input file contains a table that is too complex to process.
File contains complex contentBAD_PDF_COMPLEX_INPUTThe input file contains content that is too complex to process.
File contains unsupported fontBAD_PDF_UNSUPPORTED_FONTThe input file contains font data that is corrupted or not supported.
Large PDFBAD_PDF_LARGE_FILEThe input file size exceeds the maximum allowed.
Protected PDFPROTECTED_PDFUnable to extract content. File is password protected.
TimeoutTIMEOUTProcessing timeout. Please try splitting the file into multiple files with fewer pages.
Unknown error / failureERRORUnable to extract content - Internal error.

Extract Text from a PDF#

The sample below extracts text element information from a PDF document and returns a JSON file.

Copied to your clipboard
1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
2// Run the sample:
3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.extractpdf.ExtractTextInfoFromPDF
4
5public class ExtractTextInfoFromPDF {
6
7 private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ExtractTextInfoFromPDF.class);
8
9 public static void main(String[] args) {
10
11 try {
12
13 // Initial setup, create credentials instance.
14 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()
15 .fromFile("pdfservices-api-credentials.json")
16 .build();
17
18 // Create an ExecutionContext using credentials.
19 ExecutionContext executionContext = ExecutionContext.create(credentials);
20
21 ExtractPDFOperation extractPDFOperation = ExtractPDFOperation.createNew();
22
23 // Provide an input FileRef for the operation
24 FileRef source = FileRef.createFromLocalFile("src/main/resources/extractPdfInput.pdf");
25 extractPDFOperation.setInputFile(source);
26
27 // Build ExtractPDF options and set them into the operation
28 ExtractPDFOptions extractPDFOptions = ExtractPDFOptions.extractPdfOptionsBuilder()
29 .addElementsToExtract(Arrays.asList(ExtractElementType.TEXT))
30 .build();
31 extractPDFOperation.setOptions(extractPDFOptions);
32
33 // Execute the operation
34 FileRef result = extractPDFOperation.execute(executionContext);
35
36 // Save the result at the specified location
37 result.saveAs("output/ExtractTextInfoFromPDF.zip");
38
39 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException e) {
40 LOGGER.error("Exception encountered while executing operation", e);
41 }
42 }
43}
44

Extract Text and Tables#

The sample below extracts text and table element information from a PDF document and returns a JSON file along with table data in XLSX format.

Copied to your clipboard
1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
2// Run the sample:
3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.extractpdf.ExtractTextTableInfoFromPDF
4
5public class ExtractTextTableInfoFromPDF {
6
7 private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ExtractTextTableInfoFromPDF.class);
8
9 public static void main(String[] args) {
10
11 try {
12
13 // Initial setup, create credentials instance.
14 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()
15 .fromFile("pdfservices-api-credentials.json")
16 .build();
17
18 // Create an ExecutionContext using credentials.
19 ExecutionContext executionContext = ExecutionContext.create(credentials);
20
21 ExtractPDFOperation extractPDFOperation = ExtractPDFOperation.createNew();
22
23 // Provide an input FileRef for the operation
24 FileRef source = FileRef.createFromLocalFile("src/main/resources/extractPdfInput.pdf");
25 extractPDFOperation.setInputFile(source);
26
27 // Build ExtractPDF options and set them into the operation
28 ExtractPDFOptions extractPDFOptions = ExtractPDFOptions.extractPdfOptionsBuilder()
29 .addElementsToExtract(Arrays.asList(ExtractElementType.TEXT, ExtractElementType.TABLES))
30 .build();
31 extractPDFOperation.setOptions(extractPDFOptions);
32
33 // Execute the operation
34 FileRef result = extractPDFOperation.execute(executionContext);
35
36 // Save the result at the specified location
37 result.saveAs("output/ExtractTextTableInfoFromPDF.zip");
38
39 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException e) {
40 LOGGER.error("Exception encountered while executing operation", e);
41 }
42 }
43}
44

Extract Text and Tables (w/ Tables Renditions)#

The sample below extracts text and table element information as well as table renditions from a PDF Document. Note that the output is a zip containing the structured information in a JSON file along with table renditions in PNG and XLSX format.

Copied to your clipboard
1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
2// Run the sample:
3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.extractpdf.ExtractTextTableInfoWithRenditionsFromPDF
4
5public class ExtractTextTableInfoWithRenditionsFromPDF {
6
7 private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ExtractTextTableInfoWithRenditionsFromPDF.class);
8
9 public static void main(String[] args) {
10
11 try {
12
13 // Initial setup, create credentials instance.
14 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()
15 .fromFile("pdfservices-api-credentials.json")
16 .build();
17
18 // Create an ExecutionContext using credentials.
19 ExecutionContext executionContext = ExecutionContext.create(credentials);
20
21 ExtractPDFOperation extractPDFOperation = ExtractPDFOperation.createNew();
22
23 // Provide an input FileRef for the operation
24 FileRef source = FileRef.createFromLocalFile("src/main/resources/extractPdfInput.pdf");
25 extractPDFOperation.setInputFile(source);
26
27 // Build ExtractPDF options and set them into the operation
28 ExtractPDFOptions extractPDFOptions = ExtractPDFOptions.extractPdfOptionsBuilder()
29 .addElementsToExtract(Arrays.asList(ExtractElementType.TEXT, ExtractElementType.TABLES))
30 .addElementToExtractRenditions(ExtractRenditionsElementType.TABLES)
31 .build();
32 extractPDFOperation.setOptions(extractPDFOptions);
33
34 // Execute the operation
35 FileRef result = extractPDFOperation.execute(executionContext);
36
37 // Save the result at the specified location
38 result.saveAs("output/ExtractTextTableInfoWithRenditionsFromPDF.zip");
39
40 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException e) {
41 LOGGER.error("Exception encountered while executing operation", e);
42 }
43 }
44}

Extract Text and Tables (w/ Tables and Figures Renditions)#

The sample below extracts text and table elements information as well as table and figure renditions from a PDF Document. Note that the output is a zip containing the structured information in a JSON file along with figure renditions as PNGs and table renditions in PNG and XLSX format.

Copied to your clipboard
1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
2// Run the sample:
3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.extractpdf.ExtractTextTableInfoWithRenditionsFromPDF
4
5public class ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF {
6
7 private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF.class);
8
9 public static void main(String[] args) {
10
11 try {
12
13 // Initial setup, create credentials instance.
14 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()
15 .fromFile("pdfservices-api-credentials.json")
16 .build();
17
18 // Create an ExecutionContext using credentials.
19 ExecutionContext executionContext = ExecutionContext.create(credentials);
20
21 ExtractPDFOperation extractPDFOperation = ExtractPDFOperation.createNew();
22
23 // Provide an input FileRef for the operation
24 FileRef source = FileRef.createFromLocalFile("src/main/resources/extractPdfInput.pdf");
25 extractPDFOperation.setInputFile(source);
26
27 // Build ExtractPDF options and set them into the operation
28 ExtractPDFOptions extractPDFOptions = ExtractPDFOptions.extractPdfOptionsBuilder()
29 .addElementsToExtract(Arrays.asList(ExtractElementType.TEXT, ExtractElementType.TABLES))
30 .addElementsToExtractRenditions(Arrays.asList(ExtractRenditionsElementType.TABLES, ExtractRenditionsElementType.FIGURES))
31 .build();
32 extractPDFOperation.setOptions(extractPDFOptions);
33
34 // Execute the operation
35 FileRef result = extractPDFOperation.execute(executionContext);
36
37 // Save the result at the specified location
38 result.saveAs("output/ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF.zip");
39
40 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException e) {
41 LOGGER.error("Exception encountered while executing operation", e);
42 }
43 }
44 }