Why Use PDF to JSON API?

Extract PDF to JSON
Automatic Classification Using Built-in AI

PDF.co Classifier automatically classifies input documents based on built-in AI-powered analysis. You can also create your own custom pdf classification rules based on keywords.

Damaged and scanned text support

Some PDF files have scanned and damaged texts in them. Our built-in OCR (Optical Character Recognition) supports PDF files with mixed content and multiple languages.


Web API and Business Automation Platforms Integrations

Software developers can use the PDF.co API platform from multiple programming languages. You can convert PDF to JSON in PHP, C#, JavaScript, .NET and ASP.NET, Visual Basic. You can also convert PDF to JSON in Java, Python, and other languages.

For non-developers, the PDF operations can be performed via the following business automation platforms:

On-Prem and Private Instances for Enterprise

PDF.co Web API uses secure and certified cloud infrastructure, however, Enterprise customers who need to process ultra-sensitive data in-house can opt for the on-premise version. It will be on your server working completely offline when required.


PDF to JSON API Sample & Demo

For this demo, I am going to use a Sample PDF File.

Screenshot of Sample PDF
Screenshot of Sample PDF

We’ll be using the code snippets below which are written in different programming languages which will convert the Sample PDF File above into JSON. The final result will look like this.

"document": {
"pageCount": "1",
"pageCountWithOCRPerformed": "0",
"page": {
"index": "0",
"OCRWasPerformed": "False",
"row": {
"column": {
"text": {
"fontName": "Arial",
"fontSize": "24.0",
"fontStyle": "Bold",
"color": "#0000EF",
"x": "72.10",
"y": "70.60",
"width": "140.74",
"height": "24.00",
"text": "Hello World!"

Output JSON

Before we proceed with the code. Let us first check the /v1/pdf/convert/to/json parameters and its uses.


URL: https://api.pdf.co/v1/pdf/convert/to/json2
Method: POST
Parameter Description
url required. Link to the source file.
lang optional. english by default. Sets OCR (image to text extraction) language to be used for scanned PDF when a scanned document is detected or input is PNG, JPG images. Other 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.
inline optional. Must be one of: true to return data as inline or false to return link to the output file (default).
unwrap optional. Unwrap lines to a single line within table cells when lineGrouping is enabled. Must be one of true or false.
pages optional. Comma-separated list of page indices (or ranges) to process. IMPORTANT: the very first page starts with (zero). To set a range use the dash , for example: 0, 2-5, 7-.
rect optional. Defines coordinates for extraction, e.g. 51.8, 114.8, 235.5, 204.0. Must be a string.
encrypt optional. Enable encryption for the output file: true or false
async optional. Runs processing asynchronously. Returns jobId to use with job/checktrue or false
name optional. Output file name.
profiles optional. Must be a String. Set custom configuration. See profiles examples here
lineGrouping optional. Line grouping with table cells. Set to 1 to enable the grouping. Must be a string.

Now we are ready to write some codes.

cURL Code Snippet

curl --location --request POST 'https://api.pdf.co/v1/pdf/convert/to/json2' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY' \
--data-raw '{
"url": "https://pdf-temp-files.s3.amazonaws.com/5cd7dc4346294ba2bacff69c4a881aa0/sample.pdf",
"inline": true

This sample code and other cURL source code samples are available here.

Now let’s see this program in action.

Output JSON using cURL
Output JSON using cURL

The sample code for PDF to JSON in JavaScript is located here.

The sample code for PDF to JSON in PHP is located here.

The sample code for PDF to JSON in Python is here.

The sample code for PDF to JSON in Java is located here.

The sample code for PDF to JSON in C# is located here.

Sign Up

NOTE: Use PDF.co Document Classifier to know the source of the document. You can easily create and maintain classification rules with the desktop-based Classifier Testing Tool (see the details here)

Related Pages:

Related Samples: