Sign inSign up

codeinchq/pdf2txt

By codeinchq

Updated almost 2 years ago

Containerized REST API for the extraction of the textual content of PDF documents using pdf.js

Image
0

2.5K

codeinchq/pdf2txt repository overview

Pdf2Txt

Code Inc. Docker Image CI Docker Image Version

This repository contains a simple containerized API to convert PDF documents to text using Mozilla's pdf.js and pdf.js-extract.

The source code is available on Github.

Configuration

By default, the container listens on port 3000. The port is configurable using the PORT environment variable.

Usage

All requests must by send in POST to the /convert endpoint with a multipart/form-data content type. The request must contain a PDF file with the key file.

Additional parameters can be sent to customize the conversion process:

  • firstPage: The first page to extract. Default is 1.
  • lastPage: The last page to extract. Default is the last page of the document.
  • password: The password to unlock the PDF. Default is none.
  • normalizeWhitespace: If set to true, the server normalizes the whitespace in the extracted text. Default is true.
  • format: The output format. Supported values are text (the server returns the raw text as text/plain) or json (the server returns a JSON object as text/json). Default is text.

The server returns 200 if the conversion was successful and the images are available in the response body. In case of error, the server returns a 400 status code with a JSON object containing the error message (format: {error: string}).

Example
Step 1: run the container using Docker
docker run -p "3000:3000" codeinchq/pdf2txt 
Step 2: convert a PDF file to text

Convert a PDF file to text with a JSON response:

curl -X POST -F "file=@/path/to/file.pdf" http://localhost:3000/convert -o example.json

Convert a PDF file to text:

curl -X POST -F "file=@/path/to/file.pdf" http://localhost:3000/convert

Extract a password-protected PDF file's text content as JSON and save it to a file:

curl -X POST -F "file=@/path/to/file.pdf" -F "password=XXX" -F "format=json" http://localhost:3000/convert -o example.json

Client

A PHP 8 client is available at on GitHub and Packagist.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Tag summary

Content type

Image

Digest

sha256:8c2261715

Size

97 MB

Last updated

almost 2 years ago

docker pull codeinchq/pdf2txt