How to Extract Tables from PDF Files as CSV Using PDF.co Web API

PDF.co can extract tables from PDF documents and convert their rows and columns into structured CSV data. The resulting CSV file can be opened in applications such as Microsoft Excel, Google Sheets, or any system that supports comma-separated values.

The PDF to CSV endpoint can process both searchable and scanned PDFs. For scanned documents, PDF.co applies optical character recognition (OCR) during extraction.

In this tutorial, you will use PDF.co’s Request Tester to:

  1. Select the PDF to CSV endpoint.
  2. Provide a source PDF.
  3. Optionally limit extraction to the area containing the table.
  4. Run the request and download the resulting CSV file.

What You Will Need

Before starting, prepare:

  • A PDF.co account
  • A PDF containing a table
  • The password if the source PDF is password-protected

For the best results, choose a PDF in which the table has clearly separated rows and columns.

Step 1: Open the PDF.co Request Tester

Sign in to your PDF.co account.

Open API Tools, and then select Request Tester.

The Request Tester lets you configure and run PDF.co API requests without writing an application.

Step 2: Select the PDF to CSV Endpoint

In the endpoint selector, search for PDF to CSV and select:

POST /v1/pdf/convert/to/csv

This endpoint converts PDF documents and scanned images into CSV while detecting their rows, columns, and table structure.

For a complete description of its supported parameters, see the PDF.co PDF to CSV API documentation.

Step 3: Add the Source PDF

Provide the source file by uploading a PDF or entering a publicly accessible file URL.

When using a URL, make sure it points directly to the document and can be accessed without an interactive sign-in page. If the file requires HTTP authentication, provide the applicable username and password parameters.

Step 4: Identify the Table Area

If the PDF contains text or other content outside the table, you can restrict extraction to a rectangular portion of the page.

Open the PDF Edit Add Helper from your PDF.co account and load the sample PDF. Use the tool to locate the area containing the table.

Record the rectangle in the following format:

x y width height

For example:

40 180 520 400

The values represent:

  • x: Distance from the left side of the page
  • y: Distance from the top of the page
  • width: Width of the extraction area
  • height: Height of the extraction area

PDF coordinates are measured in points, where 72 points equal one inch.

The extraction rectangle is optional. Leave it empty when you want PDF.co to analyze the entire page.

Step 5: Configure the Request

Configure the request using values appropriate for your document. A typical request body looks like this:

{
  "url": "https://example.com/sample-invoice.pdf",
  "pages": "0-",
  "rect": "40 180 520 400",
  "lang": "eng",
  "inline": false,
  "unwrap": false,
  "lineGrouping": "",
  "async": false,
  "name": "extracted-table.csv",
  "password": "",
  "profiles": ""
}

If you uploaded the file through the Request Tester, use the generated file URL in the url parameter.

Parameter Details

  • url: Direct URL of the source PDF.
  • pages: Pages to process. Enter 0- to process every page.
  • rect: Optional table area in x y width height format.
  • lang: OCR language used for scanned documents. Use eng for English.
  • inline: When false, PDF.co returns a temporary URL for the generated CSV file. When true, the CSV content is returned in the response body.
  • unwrap: Controls whether wrapped lines are combined within table cells when compatible line grouping is enabled.
  • lineGrouping: Optionally controls how multiline table content is grouped.
  • async: When false, the request waits for processing to finish and returns the result directly.
  • name: Filename for the generated CSV.
  • password: Password for an encrypted source PDF, when required.
  • profiles: Optional advanced conversion settings.

PDF.co uses zero-based page numbering. Page 0 is the first page, and 0- means the first page through the end of the document.

If you want to process only the first page, use:

"pages": "0"

To process the second through fourth pages, use:

"pages": "1-3"

Step 6: Run the Request

Select Run Request.

PDF.co will process the source PDF and display the API response. A successful request should include:

  • error set to false
  • A successful status value
  • The generated filename
  • The number of processed pages
  • A URL for the generated CSV when inline is false

A simplified successful response may look like this:

{
  "url": "https://pdf-temp-files.s3.amazonaws.com/example/extracted-table.csv",
  "pageCount": 1,
  "error": false,
  "status": 200,
  "name": "extracted-table.csv"
}

The response may also contain information about processing time, consumed credits, and remaining credits.

Step 7: Review the Extracted Table

Open the generated URL or use the available download option to save the CSV file.

Review the result in Microsoft Excel, Google Sheets, or another spreadsheet application. Check that:

  • Headers appear in the correct columns.
  • Each table row is represented by one CSV row.
  • Multiline values remain associated with the correct cells.
  • Text outside the table has not been included.
  • Numeric and date values were extracted correctly.

PDF.co-generated file URLs use temporary storage. Download the result or transfer it to permanent storage before the URL expires.

Improving Table Extraction

PDF tables vary considerably in structure, so you may need to adjust the request for the best result.

Unrelated Text Appears in the CSV

Define a more precise rect value so that PDF.co processes only the table area.

Columns Are Not Detected Correctly

Try an advanced column-detection profile. Supported modes include:

  • ContentGroups
  • Borders
  • BorderedTables
  • ContentGroupsAI

For example:

{
  "profiles": "{'ColumnDetectionMode':'Borders'}"
}

Borders or BorderedTables can work well for tables with visible cell borders. ContentGroups can be more suitable when the table structure is indicated primarily by spacing.

Multiline Cells Produce Extra Rows

Use a line-grouping option suited to the document:

  • 1 groups compatible rows.
  • 2 groups content within individual columns.
  • 3 joins certain orphaned rows to the preceding row.

You can also enable unwrap when using the compatible row-grouping mode.

The Source Is a Scanned PDF

Confirm that the correct OCR language is set in lang. For example:

"lang": "eng"

Two OCR languages can be combined when necessary:

"lang": "eng+deu"

Higher-quality scans with straight pages, clear text, and adequate resolution generally produce more accurate results.

Only Some Pages Contain Tables

Set pages to the specific zero-based page numbers or ranges containing the tables. This reduces unnecessary processing and prevents unrelated pages from contributing data.

The PDF Is Password-Protected

Enter the document password in the password parameter.

You Need the CSV Content in the API Response

Set:

"inline": true

The extracted CSV will then be returned in the response’s body field rather than only through a generated-file URL.

Conclusion

You have used the PDF.co PDF to CSV endpoint to extract a table from a PDF and convert it into structured CSV data.

For documents containing additional text, defining a precise extraction rectangle helps isolate the table. OCR language, line grouping, and column-detection settings can also be adjusted to improve results for scanned PDFs and more complex table layouts.

Related Tutorials

See Related Tutorials