All posts
|Also available in:DE

Automatic PDF Rotation – Document Orientation Detection API

Fix wrongly rotated PDF and image pages with the MaraDocs orientation detection API. Text-based detection, automatic correction, no manual rotation.

Martin Kurtz
APIPDFOrientationDocument ProcessingDeveloper
Automatic PDF Rotation – Document Orientation Detection API

Scanned or photographed documents often arrive with pages upside down or sideways. Manual rotation doesn't scale when you process hundreds of documents. An automatic PDF rotation API that detects orientation from the actual content – not just EXIF – and corrects it would remove a tedious step from your pipeline.

If you process case files, scans, or photos in bulk, wrong orientation slows everyone down.

Why Building a Document Orientation Detection Solution Yourself Takes Weeks

If you try to build this yourself, you'll quickly find that orientation detection usually means: run OCR, analyze text direction, infer rotation. Tesseract, EasyOCR, or cloud OCR services can help, but you must integrate them, handle different languages, and map results to 0°/90°/180°/270° rotations. PDFs add per-page complexity. Building a reliable document orientation detection API takes integration time and tuning.

How the MaraDocs Automatic PDF Rotation API Solves This in Minutes

The MaraDocs API provides pdf.orientation and img.orientation. Both use text-based analysis to determine the correct orientation – more reliable than EXIF, which is often wrong or missing. For PDFs, each page is analyzed; for images, the whole image. The API returns the rotated result and per-page angles with confidence. No OCR pipeline to maintain, no model hosting, no language configuration. One API call and you get a corrected handle ready for the next step.

Document Orientation Workflow: Validate, Orient, Chain

Upload a PDF or image, validate it for viruses and format, then call orientation. The API analyzes each page (or the whole image for single-page inputs) and returns a rotated handle. You can chain that handle directly into OCR, composition, or optimization – orientation fits into any pipeline as one step. No need to re-upload the file between steps; the rotated result stays in your workspace.

Get your API key in under a minute

Register for a free account and get your API key in under a minute. Of course we'll provide you with some developer credits.

Try MaraDocs API now →

Why MaraDocs is Different: Workspaces, Webview, and German Data Privacy

Most document APIs force you to upload, process, download, then re-upload for the next step. With MaraDocs, files stay in your workspace. After orientation, pass the rotated handle directly to OCR, composition, or optimization – no re-upload. Handles flow; data stays server-side.

When orientation detection is uncertain – low-contrast scans, handwritten notes, or mixed languages – open app.maradocs.io for manual inspection and correction. Your users get full manual control when automation hits an edge case.

All processing runs in Germany (Maramia GmbH), encrypted at rest and in transit. Workspaces expire after 7 days. No data leaves the EU. For GDPR-sensitive document processing, this matters.

TypeScript Code for Automatic PDF Rotation

API reference: data/upload, pdf/validate, img/validate, pdf/orientation, img/orientation, data/download/pdf

import { MaraDocsClient } from "@maramia/maradocs-sdk-ts";
import { okPdf } from "@maramia/maradocs-sdk-ts/models/pdf";

const client = new MaraDocsClient({ workspaceSecret: workspace_secret });

// Upload and validate
const uploaded = await client.data.upload(pdfOrImageFile);
const pdfVal = await client.pdf.validate({ unvalidated_file_handle: uploaded.unvalidated_file_handle });
const pdfHandle = okPdf(pdfVal);

// PDF orientation
const oriented = await client.pdf.orientation({ pdf_handle: pdfHandle });

// Download result
const blob = await client.data.downloadPdf({ pdf_handle: oriented.rotated_pdf_handle });

// For images: use client.img.validate + client.img.orientation

Python Code for Document Orientation Detection

API reference: data/upload, pdf/validate, pdf/orientation, img/orientation, data/download/pdf

import requests
import time

API_URL = "https://api.maradocs.io/v1"
headers = {"Authorization": f"Bearer {WORKSPACE_SECRET}"}

def poll(url, job_id):
    while True:
        r = requests.get(f"{url}/{job_id}", headers=headers).json()
        if r["status"] == "complete":
            return r["response"]["response"]
        time.sleep(1)

# 1. Upload, 2. Validate
upload = requests.post(f"{API_URL}/data/upload", headers=headers, files={"file": (...)}).json()
val = requests.post(f"{API_URL}/pdf/validate", headers=headers,
    json={"unvalidated_file_handle": upload["unvalidated_file_handle"]}).json()
pdf_handle = poll(f"{API_URL}/pdf/validate", val["job_id"])["pdf_handle"]

# 3. Orientation
orient = requests.post(f"{API_URL}/pdf/orientation", headers=headers, json={"pdf_handle": pdf_handle}).json()
oriented = poll(f"{API_URL}/pdf/orientation", orient["job_id"])

# 4. Download
pdf_resp = requests.get(f"{API_URL}/data/download/pdf", headers=headers,
    params={"pdf_handle": oriented["rotated_pdf_handle"]})
with open("rotated.pdf", "wb") as out:
    out.write(pdf_resp.content)

Summary and Next Steps

An automatic PDF rotation and document orientation detection API is ready. MaraDocs handles images and PDFs with text-based analysis. See Document Scanner, PDF Handling, and Text Recognition for related workflows.


Try it: MaraDocs API | TypeScript SDK


Subscribe to our newsletter

Stay up to date with us and receive the latest news, articles, and resources by email.