Link Search Menu Expand Document

PDF To CSV

Convert PDF and scanned images into CSV representation with layout, columns, rows, tables.

Available methods

[POST] /pdf/convert/to/csv

Auto classification Of Incoming Documents

Use /pdf/classifer (Document Classifer) endpoint to automatically sort / detect the class of the document based on keywords-based rules. For example, you can define rules to find which vendor provided the document to find which template to apply accordingly.

Parameters

  • url required. URL to the source file. Supports links from Google Drive, Dropbox and from built-in PDF.co files storage. For uploading files via API please check Files Upload section. If you are randomly getting Too Many Requests or Access Denied error for your input url, please try to add cache: to enable built-in url caching.
  • pages optional. Comma-separated list of page indices (or ranges) to process. IMPORTANT: the very first page starts at 0 (zero). To set a range use the dash -, for example: 0,2-5,7-. To set a range from index to the last page use range like this: 2- (from page #3 as the index starts at zero and till the of the document). For ALL pages just leave this param empty. Example: 0,2-5,7- means first page, then 3rd page to 6th page, and then the range from 8th (index = 7) page till the end of the document. Must be a String.
  • unwrap optional. Unwrap lines into a single line within table cells when lineGrouping is enabled. Must be one of: true, false.
  • rect optional. Defines coordinates for extraction, e.g. 51.8, 114.8, 235.5, 204.0. You can use PDF.co PDF Viewer with coordinates to easily select and copy coordinates. Must be a String.
  • lang optional. eng by default. Sets OCR (image to text extraction) language to be used for scanned PDF when scanned document is detected or input is PNG, JPG images. Default is eng. Supported values: eng, spa, deu, fra, jpn, chi_sim, chi_tra, kor. You can also specify two languages to be used on the same page, for example: eng+deu, jpn+kor or other combinations. For more languages please contact our customer support.
  • inline optional. Must be one of: true to return data as inline or false to return link to output file (default).
  • lineGrouping optional. optional. Line grouping within table cells. Set to 1 to enable the grouping. Must be a String.

  • encrypt optional. Enable encryption for output file. Must be one of: true, false.
  • async optional. Runs processing asynchronously. Returns Use JobId that you may use with /job/check to check state of the processing (possible states: working, failed, aborted and success). Must be one of: true, false.
  • name optional. File name for generated output. Must be a String.
  • profiles optional. Must be a String. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for examples. For example, to change CSV separator: { 'profiles': [ { 'profile1': { 'CSVSeparatorSymbol': ';' } } ] }

Description

  • Method: POST
  • URL: /v1/pdf/convert/to/csv

Query parameters

No query parameters accepted.

Body payload

{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-csv/sample.pdf",
    "lang": "eng",
    "inline": "true",
    "unwrap": "",
    "pages": "0-",
    "rect": "",
    "async": "false",
    "encrypt": "false",    
    "name": "result.csv",
    "password": "",
    "lineGrouping": "",
    "profiles": ""
}

Example responses

/pdf/convert/to/csv
{
    "body": "\"Your Company Name\",\"\",\"\",\"\",\r\n\"Your Address\",\"\",\"\",\"\",\r\n\"City, State Zip\",\"\",\"\",\"\",\r\n\"\",\"\",\"\",\"Invoice No. 123456\",\r\n\"\",\"\",\"\",\"Invoice Date 01/01/2016\",\r\n\"Client Name\",\"\",\"\",\"\",\r\n\"Address\",\"\",\"\",\"\",\r\n\"City, State Zip\",\"\",\"\",\"\",\r\n\"Notes\",\"\",\"\",\"\",\r\n\"Item\",\"Quantity\",\"Price\",\"Total\",\r\n\"Item 1\",\"1\",\"40.00\",\"40.00\",\r\n\"Item 2\",\"2\",\"30.00\",\"60.00\",\r\n\"Item 3\",\"3\",\"20.00\",\"60.00\",\r\n\"Item 4\",\"4\",\"10.00\",\"40.00\",\r\n\"\",\"\",\"TOTAL\",\"200.00\",\r\n",
    "pageCount": 2,
    "error": false,
    "status": 200,
    "name": "result.csv",
    "remainingCredits": 616411,
    "credits": 56
}

Code Snippets

CURL
curl --location --request POST 'https://api.pdf.co/v1/pdf/convert/to/csv' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ' \
--data-raw '{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-csv/sample.pdf",
    "lang": "eng",
    "inline": "true",
    "unwrap": "",
    "pages": "0-",
    "rect": "",
    "async": "false",
    "encrypt": "false",    
    "name": "result.csv",
    "password": "",
    "lineGrouping": "",
    "profiles": ""
}'
JavaScript
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("x-api-key", "");

var raw = JSON.stringify({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-csv/sample.pdf",
 "lang": "eng",
 "inline": "true",
 "unwrap": "",
 "pages": "0-",
 "rect": "",
 "async": "false",
 "encrypt": "false",
 "name": "result.csv",
 "password": "",
 "lineGrouping": "",
 "profiles": ""
});

var requestOptions = {
	method: 'POST',
	headers: myHeaders,
	body: raw,
	redirect: 'follow'
};

fetch("https://api.pdf.co/v1/pdf/convert/to/csv", requestOptions)
	.then(response => response.text())
	.then(result => console.log(result))
	.catch(error => console.log('error', error));
NodeJs
var request = require('request');
var options = {
	'method': 'POST',
	'url': 'https://api.pdf.co/v1/pdf/convert/to/csv',
	'headers': {
		'Content-Type': 'application/json',
		'x-api-key': ''
	},
	body: JSON.stringify({
	 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-csv/sample.pdf",
	 "lang": "eng",
	 "inline": "true",
	 "unwrap": "",
	 "pages": "0-",
	 "rect": "",
	 "async": "false",
	 "encrypt": "false",
	 "name": "result.csv",
	 "password": "",
	 "lineGrouping": "",
	 "profiles": ""
	})

};
request(options, function (error, response) {
	if (error) throw new Error(error);
	console.log(response.body);
});

PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
	CURLOPT_URL => 'https://api.pdf.co/v1/pdf/convert/to/csv',
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => '',
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 0,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => 'POST',
	CURLOPT_POSTFIELDS =>'{
    "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-csv/sample.pdf",
    "lang": "eng",
    "inline": "true",
    "unwrap": "",
    "pages": "0-",
    "rect": "",
    "async": "false",
    "encrypt": "false",    
    "name": "result.csv",
    "password": "",
    "lineGrouping": "",
    "profiles": ""
}',
	CURLOPT_HTTPHEADER => array(
		'Content-Type: application/json',
		'x-api-key: '
	),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Java
import java.io.*;
import okhttp3.*;
public class main {
	public static void main(String []args) throws IOException{
		OkHttpClient client = new OkHttpClient().newBuilder()
			.build();
		MediaType mediaType = MediaType.parse("application/json");
		RequestBody body = RequestBody.create(mediaType, "{\n    \"url\": \"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-csv/sample.pdf\",\n    \"lang\": \"eng\",\n    \"inline\": \"true\",\n    \"unwrap\": \"\",\n    \"pages\": \"0-\",\n    \"rect\": \"\",\n    \"async\": \"false\",\n    \"encrypt\": \"false\",    \n    \"name\": \"result.csv\",\n    \"password\": \"\",\n    \"lineGrouping\": \"\",\n    \"profiles\": \"\"\n}");
		Request request = new Request.Builder()
			.url("https://api.pdf.co/v1/pdf/convert/to/csv")
			.method("POST", body)
			.addHeader("Content-Type", "application/json")
			.addHeader("x-api-key", "")
			.build();
		Response response = client.newCall(request).execute();
		System.out.println(response.body().string());
	}
}

C#
using System;
using RestSharp;
namespace HelloWorldApplication {
	class HelloWorld {
		static void Main(string[] args) {
			var client = new RestClient("https://api.pdf.co/v1/pdf/convert/to/csv");
			client.Timeout = -1;
			var request = new RestRequest(Method.POST);
			request.AddHeader("Content-Type", "application/json");
			request.AddHeader("x-api-key", "");
			var body = @"{" + "\n" +
			@"    ""url"": ""https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-csv/sample.pdf""," + "\n" +
			@"    ""lang"": ""eng""," + "\n" +
			@"    ""inline"": ""true""," + "\n" +
			@"    ""unwrap"": """"," + "\n" +
			@"    ""pages"": ""0-""," + "\n" +
			@"    ""rect"": """"," + "\n" +
			@"    ""async"": ""false""," + "\n" +
			@"    ""encrypt"": ""false"",    " + "\n" +
			@"    ""name"": ""result.csv""," + "\n" +
			@"    ""password"": """"," + "\n" +
			@"    ""lineGrouping"": """"," + "\n" +
			@"    ""profiles"": """"" + "\n" +
			@"}";
			request.AddParameter("application/json", body,  ParameterType.RequestBody);
			IRestResponse response = client.Execute(request);
			Console.WriteLine(response.Content);
		}
	}
}

Python
import requests
import json

url = "https://api.pdf.co/v1/pdf/convert/to/csv"

payload = json.dumps({
 "url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-csv/sample.pdf",
 "lang": "eng",
 "inline": "true",
 "unwrap": "",
 "pages": "0-",
 "rect": "",
 "async": "false",
 "encrypt": "false",
 "name": "result.csv",
 "password": "",
 "lineGrouping": "",
 "profiles": ""
})
headers = {
	'Content-Type': 'application/json',
	'x-api-key': ''
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Powershell
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("x-api-key", "")

$body = "{`n    `"url`": `"https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-to-csv/sample.pdf`",`n    `"lang`": `"eng`",`n    `"inline`": `"true`",`n    `"unwrap`": `"`",`n    `"pages`": `"0-`",`n    `"rect`": `"`",`n    `"async`": `"false`",`n    `"encrypt`": `"false`",    `n    `"name`": `"result.csv`",`n    `"password`": `"`",`n    `"lineGrouping`": `"`",`n    `"profiles`": `"`"`n}"

$response = Invoke-RestMethod 'https://api.pdf.co/v1/pdf/convert/to/csv' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json