Skip to main content

pdf-text


Use the pdf-text endpoint to extract text from a PDF.

Use the pdf-text endpoint to extract text from a PDF. It uses an HTTP POST to send a PDF as binary and then returns the extracted text as a JSON response. The pdf-text endpoint takes an HTTP POST form submission, where the PDF is sent as binary in the form's body.

info

Refer to the following Users Guide page if you need more information illustrating how to call the endpoint directly as a REST call.

Run In Postman

API

The PdfText class encapsulates the pdf-text endpoint. A PdfText instance takes a PdfResource instance. A PdfResource is constructed from a PDF coming from a file, a byte array, or stream.

public PdfText(PdfResource resource);

public class PdfResource : Resource
{
public PdfResource(string filePath, string resourceName = null);
public PdfResource(byte[] value, string resourceName = null);
public PdfResource(Stream data, string resourceName = null);
}
Source: PdfText.cs Source: PdfResource.cs

Example

A complete example is available via one of the following GitHub projects depending upon the language you wish to use.

LanguageGitHub Users Guide ProjectClassLocation/Namespace/Package
C#https://github.com/dynamicpdf-api/dotnet-client-examplesProgram.csnamespace PdfTextExample
Gohttps://github.com/dynamicpdf-api/go-client-examplespdf-text-example.gogo-client-examples
Javahttps://github.com/dynamicpdf-api/java-client-examplesPdfTextExample.javacom.dynamicpdf.api.client.examples
Node.jshttps://github.com/dynamicpdf-api/nodejs-client-examplesPdfTextExample.jsnodejs-users-guide
PHPhttps://github.com/dynamicpdf-api/php-client-examplesPdfTextExample.phpphp-cllient-examples
Pythonhttps://github.com/dynamicpdf-api/python-client-examplesPdfTextExample.pypython-client-examples

The processing and syntax are similar for all six languages.

  • Create a new PdfText instance and pass a PdfResource instance to the constructor.
  • Call the PdfText instance's Process method and get the results as a PdfTextResponse which contains the extracted text as a JSON document.
using DynamicPDF.Api;
using System;

namespace PdfTextExample
{
class Program
{
static void Main(string[] args)
{
Run("DP.xxx-api-key-xxx", "C:/temp/dynamicpdf-api-usersguide-examples/");
}

public static void Run(String apiKey, String basePath)
{
PdfResource resource = new PdfResource(basePath + "/fw4.pdf");
PdfText pdfText = new PdfText(resource);
pdfText.ApiKey = apiKey;
PdfTextResponse response = pdfText.Process();
Console.WriteLine(PrettyPrintUtil.JsonPrettify(response.JsonContent));
}
}
}
Source: PdfTextExample
   Follow us on social media for latest news!