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 have a limit of 400 pages. Scanned PDFs have a limit of 150 pages or less. Limits may be lower for files with multiple tables. For larger files or those with complex layouts, it is recommended to split the file into smaller sections before processing.
  • 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](https://helpx.adobe.com/acrobat/using/removing-sensitive-content-pdfs.html) 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.

Error codes

ScenarioError codeError message
Invalid API parameters
-
Invalid parameters
File size violation
DISQUALIFIED_FILE_SIZE
File exceeds size limit.
Page limit violation
DISQUALIFIED_PAGE_LIMIT
File exceeds page limit.
Scan page limit violation
DISQUALIFIED_SCAN_PAGE_LIMIT
Scanned file exceeds page limit.
Unsupported XFA file
DISQUALIFIED_XFA
File contains XFA form(s). Not supported for content extraction.
Encryption permission
DISQUALIFIED_PERMISSIONS
File permissions do not allow for content extraction.
Complex file
DISQUALIFIED_COMPLEX_FILE
File contents are too complex for content extraction.
Unsupported language
DISQUALIFIED_LANGUAGE
File content language is unsupported.
Bad PDF
BAD_PDF
Unable to extract content. File is corrupted, malformed or an empty PDF.
Invalid file type
BAD_PDF_FILE_TYPE
The input file is not a PDF file.
Damaged file
BAD_PDF_DAMAGED
The input file is damaged.
File contains complex table
BAD_PDF_COMPLEX_TABLE
The input file contains a table that is too complex to process.
File contains complex content
BAD_PDF_COMPLEX_INPUT
The input file contains content that is too complex to process.
File contains unsupported font
BAD_PDF_UNSUPPORTED_FONT
The input file contains font data that is corrupted or not supported.
Large PDF
BAD_PDF_LARGE_FILE
The input file size exceeds the maximum allowed.
Protected PDF
PROTECTED_PDF
Unable to extract content. File is password protected.
Empty or corrupted input
BAD_INPUT
Input is corrupted or empty.
Invalid input parameters
BAD_INPUT_PARAMS
Invalid input parameters.
Timeout
TIMEOUT
Processing timeout. Please try splitting the file into multiple files with fewer pages.
Unknown error / failure
ERROR
Unable to extract content - Internal error.

REST API

See our public API Reference for Extract PDF.

Extract Text from a PDF

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

Please refer the API usage guide to understand how to use our APIs.

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 Logger LOGGER = LoggerFactory.getLogger(ExtractTextInfoFromPDF.class);
8
9 public static void main(String[] args) {
10
11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/extractPdfInput.pdf").toPath())) {
12 // Initial setup, create credentials instance
13 Credentials credentials = new ServicePrincipalCredentials(
14 System.getenv("PDF_SERVICES_CLIENT_ID"),
15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
16
17 // Creates a PDF Services instance
18 PDFServices pdfServices = new PDFServices(credentials);
19
20 // Creates an asset(s) from source file(s) and upload
21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
22
23 // Create parameters for the job
24 ExtractPDFParams extractPDFParams = ExtractPDFParams.extractPDFParamsBuilder()
25 .addElementsToExtract(Arrays.asList(ExtractElementType.TEXT)).build();
26
27 // Creates a new job instance
28 ExtractPDFJob extractPDFJob = new ExtractPDFJob(asset)
29 .setParams(extractPDFParams);
30
31 // Submit the job and gets the job result
32 String location = pdfServices.submit(extractPDFJob);
33 PDFServicesResponse<ExtractPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExtractPDFResult.class);
34
35 // Get content from the resulting asset(s)
36 Asset resultAsset = pdfServicesResponse.getResult().getResource();
37 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
38
39 // Creates an output stream and copy stream asset's content to it
40 Files.createDirectories(Paths.get("output/"));
41 OutputStream outputStream = Files.newOutputStream(new File("output/ExtractTextInfoFromPDF.zip").toPath());
42 LOGGER.info("Saving asset at output/ExtractTextInfoFromPDF.zip");
43 IOUtils.copy(streamAsset.getInputStream(), outputStream);
44 outputStream.close();
45 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException e) {
46 LOGGER.error("Exception encountered while executing operation", e);
47 }
48 }
49}
50

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.

Please refer the API usage guide to understand how to use our APIs.

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 Logger LOGGER = LoggerFactory.getLogger(ExtractTextTableInfoFromPDF.class);
8
9 public static void main(String[] args) {
10
11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/extractPdfInput.pdf").toPath())) {
12 // Initial setup, create credentials instance
13 Credentials credentials = new ServicePrincipalCredentials(
14 System.getenv("PDF_SERVICES_CLIENT_ID"),
15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
16
17 // Creates a PDF Services instance
18 PDFServices pdfServices = new PDFServices(credentials);
19
20 // Creates an asset(s) from source file(s) and upload
21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
22
23 // Create parameters for the job
24 ExtractPDFParams extractPDFParams = ExtractPDFParams.extractPDFParamsBuilder()
25 .addElementsToExtract(Arrays.asList(ExtractElementType.TEXT, ExtractElementType.TABLES))
26 .build();
27
28 // Creates a new job instance
29 ExtractPDFJob extractPDFJob = new ExtractPDFJob(asset)
30 .setParams(extractPDFParams);
31
32 // Submit the job and gets the job result
33 String location = pdfServices.submit(extractPDFJob);
34 PDFServicesResponse<ExtractPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExtractPDFResult.class);
35
36 // Get content from the resulting asset(s)
37 Asset resultAsset = pdfServicesResponse.getResult().getResource();
38 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
39
40 // Creates an output stream and copy stream asset's content to it
41 Files.createDirectories(Paths.get("output/"));
42 OutputStream outputStream = Files.newOutputStream(new File("output/ExtractTextTableInfoFromPDF.zip").toPath());
43 LOGGER.info("Saving asset at output/ExtractTextTableInfoFromPDF.zip");
44 IOUtils.copy(streamAsset.getInputStream(), outputStream);
45 outputStream.close();
46 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException e) {
47 LOGGER.error("Exception encountered while executing operation", e);
48 }
49 }
50}
51

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.

Please refer the API usage guide to understand how to use our APIs.

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 Logger LOGGER = LoggerFactory.getLogger(ExtractTextTableInfoWithRenditionsFromPDF.class);
8
9 public static void main(String[] args) {
10
11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/extractPdfInput.pdf").toPath())) {
12 // Initial setup, create credentials instance
13 Credentials credentials = new ServicePrincipalCredentials(
14 System.getenv("PDF_SERVICES_CLIENT_ID"),
15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
16
17 // Creates a PDF Services instance
18 PDFServices pdfServices = new PDFServices(credentials);
19
20 // Creates an asset(s) from source file(s) and upload
21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
22
23 // Create parameters for the job
24 ExtractPDFParams extractPDFParams = ExtractPDFParams.extractPDFParamsBuilder()
25 .addElementsToExtract(Arrays.asList(ExtractElementType.TEXT, ExtractElementType.TABLES))
26 .addElementToExtractRenditions(ExtractRenditionsElementType.TABLES)
27 .build();
28
29 // Creates a new job instance
30 ExtractPDFJob extractPDFJob = new ExtractPDFJob(asset)
31 .setParams(extractPDFParams);
32
33 // Submit the job and gets the job result
34 String location = pdfServices.submit(extractPDFJob);
35 PDFServicesResponse<ExtractPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExtractPDFResult.class);
36
37 // Get content from the resulting asset(s)
38 Asset resultAsset = pdfServicesResponse.getResult().getResource();
39 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
40
41 // Creates an output stream and copy stream asset's content to it
42 Files.createDirectories(Paths.get("output/"));
43 OutputStream outputStream = Files.newOutputStream(new File("output/ExtractTextTableInfoWithRenditionsFromPDF.zip").toPath());
44 LOGGER.info("Saving asset at output/ExtractTextTableInfoWithRenditionsFromPDF.zip");
45 IOUtils.copy(streamAsset.getInputStream(), outputStream);
46 outputStream.close();
47 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException e) {
48 LOGGER.error("Exception encountered while executing operation", e);
49 }
50 }
51}

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.

Please refer the API usage guide to understand how to use our APIs.

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 Logger LOGGER = LoggerFactory.getLogger(ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF.class);
8
9 public static void main(String[] args) {
10
11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/extractPdfInput.pdf").toPath())) {
12 // Initial setup, create credentials instance
13 Credentials credentials = new ServicePrincipalCredentials(
14 System.getenv("PDF_SERVICES_CLIENT_ID"),
15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
16
17 // Creates a PDF Services instance
18 PDFServices pdfServices = new PDFServices(credentials);
19
20 // Creates an asset(s) from source file(s) and upload
21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
22
23 // Create parameters for the job
24 ExtractPDFParams extractPDFParams = ExtractPDFParams.extractPDFParamsBuilder()
25 .addElementsToExtract(Arrays.asList(ExtractElementType.TEXT, ExtractElementType.TABLES))
26 .addElementsToExtractRenditions(Arrays.asList(ExtractRenditionsElementType.TABLES, ExtractRenditionsElementType.FIGURES))
27 .build();
28
29 // Creates a new job instance
30 ExtractPDFJob extractPDFJob = new ExtractPDFJob(asset)
31 .setParams(extractPDFParams);
32
33 // Submit the job and gets the job result
34 String location = pdfServices.submit(extractPDFJob);
35 PDFServicesResponse<ExtractPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExtractPDFResult.class);
36
37 // Get content from the resulting asset(s)
38 Asset resultAsset = pdfServicesResponse.getResult().getResource();
39 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
40
41 // Creates an output stream and copy stream asset's content to it
42 Files.createDirectories(Paths.get("output/"));
43 OutputStream outputStream = Files.newOutputStream(new File("output/ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF.zip").toPath());
44 LOGGER.info("Saving asset at output/ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF.zip");
45 IOUtils.copy(streamAsset.getInputStream(), outputStream);
46 outputStream.close();
47 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException e) {
48 LOGGER.error("Exception encountered while executing operation", e);
49 }
50 }
51 }

Extract Text and Tables and Character Bounding Boxes (w/ Renditions)

The sample below extracts table renditions and bounding boxes for characters present in text blocks (paragraphs, list, headings), in addition to text and table element information from a PDF Document. Note that the output is a zip containing the structured information along with table renditions in PNG and XLSX format.

Please refer the API usage guide to understand how to use our APIs.

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.ExtractTextTableInfoWithCharBoundsFromPDF
4
5public class ExtractTextTableInfoWithCharBoundsFromPDF {
6
7 private static final Logger LOGGER = LoggerFactory.getLogger(ExtractTextTableInfoWithCharBoundsFromPDF.class);
8
9 public static void main(String[] args) {
10
11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/extractPdfInput.pdf").toPath())) {
12 // Initial setup, create credentials instance
13 Credentials credentials = new ServicePrincipalCredentials(
14 System.getenv("PDF_SERVICES_CLIENT_ID"),
15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
16
17 // Creates a PDF Services instance
18 PDFServices pdfServices = new PDFServices(credentials);
19
20 // Creates an asset(s) from source file(s) and upload
21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
22
23 // Create parameters for the job
24 ExtractPDFParams extractPDFParams = ExtractPDFParams.extractPDFParamsBuilder()
25 .addElementToExtract(ExtractElementType.TEXT)
26 .addCharInfo(true)
27 .build();
28
29 // Creates a new job instance
30 ExtractPDFJob extractPDFJob = new ExtractPDFJob(asset)
31 .setParams(extractPDFParams);
32
33 // Submit the job and gets the job result
34 String location = pdfServices.submit(extractPDFJob);
35 PDFServicesResponse<ExtractPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExtractPDFResult.class);
36
37 // Get content from the resulting asset(s)
38 Asset resultAsset = pdfServicesResponse.getResult().getResource();
39 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
40
41 // Creates an output stream and copy stream asset's content to it
42 Files.createDirectories(Paths.get("output/"));
43 OutputStream outputStream = Files.newOutputStream(new File("output/ExtractTextTableInfoWithCharBoundsFromPDF.zip").toPath());
44 LOGGER.info("Saving asset at output/ExtractTextTableInfoWithCharBoundsFromPDF.zip");
45 IOUtils.copy(streamAsset.getInputStream(), outputStream);
46 outputStream.close();
47 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException e) {
48 LOGGER.error("Exception encountered while executing operation", e);
49 }
50 }
51}

Extract Text and Tables and Table Structure as CSV (w/ Renditions)

The sample below adds option to get CSV output for tables in addition to extracting 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 along with table renditions in PNG and CSV format.

Please refer the API usage guide to understand how to use our APIs.

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.ExtractTextTableInfoWithTableStructureFromPdf
4
5public class ExtractTextTableInfoWithTableStructureFromPdf {
6
7 private static final Logger LOGGER = LoggerFactory.getLogger(ExtractTextTableInfoWithTableStructureFromPdf.class);
8
9 public static void main(String[] args) {
10
11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/extractPdfInput.pdf").toPath())) {
12 // Initial setup, create credentials instance
13 Credentials credentials = new ServicePrincipalCredentials(
14 System.getenv("PDF_SERVICES_CLIENT_ID"),
15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
16
17 // Creates a PDF Services instance
18 PDFServices pdfServices = new PDFServices(credentials);
19
20 // Creates an asset(s) from source file(s) and upload
21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
22
23 // Create parameters for the job
24 ExtractPDFParams extractPDFParams = ExtractPDFParams.extractPDFParamsBuilder()
25 .addElementsToExtract(Arrays.asList(ExtractElementType.TEXT, ExtractElementType.TABLES))
26 .addElementToExtractRenditions(ExtractRenditionsElementType.TABLES)
27 .addTableStructureFormat(TableStructureType.CSV)
28 .build();
29
30 // Creates a new job instance
31 ExtractPDFJob extractPDFJob = new ExtractPDFJob(asset)
32 .setParams(extractPDFParams);
33
34 // Submit the job and gets the job result
35 String location = pdfServices.submit(extractPDFJob);
36 PDFServicesResponse<ExtractPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExtractPDFResult.class);
37
38 // Get content from the resulting asset(s)
39 Asset resultAsset = pdfServicesResponse.getResult().getResource();
40 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
41
42 // Creates an output stream and copy stream asset's content to it
43 Files.createDirectories(Paths.get("output/"));
44 OutputStream outputStream = Files.newOutputStream(new File("output/ExtractTextTableInfoWithTableStructureFromPdf.zip").toPath());
45 LOGGER.info("Saving asset at output/ExtractTextTableInfoWithTableStructureFromPdf.zip");
46 IOUtils.copy(streamAsset.getInputStream(), outputStream);
47 outputStream.close();
48 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException e) {
49 LOGGER.error("Exception encountered while executing operation", e);
50 }
51 }
52}

Extract Text and Tables and Styling Info

The sample below adds an option to get styling information for each text element( Bold / Italics / Superscript etc) in addition to extracting text and table element information. Note that the output is a zip containing the structured information along with table renditions in PNG and XLSX format. Please see the Styling JSON schema for reference.

Please refer the API usage guide to understand how to use our APIs.

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.ExtractTextTableWithStylingInfoFromPdf
4
5public class ExtractTextTableInfoWithStylingFromPDF {
6
7 private static final Logger LOGGER = LoggerFactory.getLogger(ExtractTextTableInfoWithStylingFromPDF.class);
8
9 public static void main(String[] args) {
10
11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/extractPdfInput.pdf").toPath())) {
12 // Initial setup, create credentials instance
13 Credentials credentials = new ServicePrincipalCredentials(
14 System.getenv("PDF_SERVICES_CLIENT_ID"),
15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
16
17 // Creates a PDF Services instance
18 PDFServices pdfServices = new PDFServices(credentials);
19
20 // Creates an asset(s) from source file(s) and upload
21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
22
23 // Create parameters for the job
24 ExtractPDFParams extractPDFParams = ExtractPDFParams.extractPDFParamsBuilder()
25 .addElementsToExtract(Arrays.asList(ExtractElementType.TEXT, ExtractElementType.TABLES))
26 .addGetStylingInfo(true)
27 .build();
28
29 // Creates a new job instance
30 ExtractPDFJob extractPDFJob = new ExtractPDFJob(asset)
31 .setParams(extractPDFParams);
32
33 // Submit the job and gets the job result
34 String location = pdfServices.submit(extractPDFJob);
35 PDFServicesResponse<ExtractPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExtractPDFResult.class);
36
37 // Get content from the resulting asset(s)
38 Asset resultAsset = pdfServicesResponse.getResult().getResource();
39 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
40
41 // Creates an output stream and copy stream asset's content to it
42 Files.createDirectories(Paths.get("output/"));
43 OutputStream outputStream = Files.newOutputStream(new File("output/ExtractTextTableInfoWithStylingFromPDF.zip").toPath());
44 LOGGER.info("Saving asset at output/ExtractTextTableInfoWithStylingFromPDF.zip");
45 IOUtils.copy(streamAsset.getInputStream(), outputStream);
46 outputStream.close();
47 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException e) {
48 LOGGER.error("Exception encountered while executing operation", e);
49 }
50 }
51}
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.