Skip to main content
Use the Document Crop & Enhance API to turn document photos and scans into clean, corrected images before OCR, parsing, archiving, printing, or display. With a single request, the API can automatically detect document edges, crop away the surrounding background, correct perspective and orientation, and apply optional image enhancements.

What it does

Auto crop documents

Automatically detect the document boundary and crop away the surrounding background.The response also returns the four corner points of the detected document region, which can be used for downstream processing or visualization.Typical inputs include documents photographed on desks, receipts captured with extra background, and pages taken from imperfect distances or angles.

Correct perspective and orientation

Straighten document photos captured at an angle and correct geometric distortion so the page appears flat and rectangular.You can also enable orientation correction for sideways or incorrectly rotated document images.

Enhance document images

Apply optional image enhancements based on the source image and desired output.Available processing options include:
  • Deblur
  • Brighten
  • Sharpen
  • Black and white
  • Grayscale
  • Shadow removal
  • Bitmap
These options can help improve readability and produce cleaner images for OCR, archiving, printing, or display.

Common use cases

The Document Crop & Enhance API can be used to prepare:
  • smartphone photos for OCR and text recognition;
  • receipts, forms, contracts, and other paper documents for digital archiving;
  • photographed pages for printing or copying;
  • cleaner document images for sharing or display;
  • document images before downstream parsing or data extraction.

Typical processing flow

A single request can combine the processing steps you need: Document photo → Auto crop → Perspective correction → Orientation correction → Enhance → Clean document image Each processing option can be enabled or disabled independently.

Before you start

You need:
  • Your TextIn App ID and Secret Code. Find them in the TextIn console under API Keys, and send them in the x-ti-app-id and x-ti-secret-code request headers.
  • A document image (jpg, png, bmp, webp, pdf, tiff, or single-frame gif).
For PDF input, only the first page is processed. Multi-page PDFs are accepted, but only the first page is cropped, corrected, and enhanced.

Set your credentials

On Windows PowerShell:

Send a request

The endpoint accepts input in one of two ways. Send the raw file bytes with Content-Type: application/octet-stream, or send a file URL as plain text with Content-Type: text/plain.
The API always responds with HTTP 200. Check the code field in the response body to determine success (200) or failure.
By default, the endpoint crops and dewarps the document. To control cropping, correction, and enhancement, pass query parameters such as ?correct_direction=1&enhance_mode=5. See Configuration for the full list.

Read the response

The response returns the processed image as a Base64-encoded JPG, plus dimensions and crop coordinates. The image value below is truncated for readability.
Parse the response and decode the image field to save the processed image:

Next steps

Configuration

Control cropping, correction, and enhancement with query parameters.

API Reference

Every parameter, response field, and an interactive playground.

Supported Files & Limits

Supported formats, file size, and image dimensions.

Errors

Error codes and how to resolve them.