PaddleOCR

CRAN status R-CMD-check Codecov test coverage

An R client for the PaddleOCR cloud API. Submit images, PDFs, or URLs for OCR processing and get structured Markdown output with automatic image downloading.

Installation

You can install the development version of PaddleOCR from GitHub:

# install.packages("devtools")
devtools::install_github("xiaoluolorn/PaddleOCR")

Setup

Set your PaddleOCR API token as an environment variable:

Sys.setenv(PADDLE_OCR_TOKEN = "your_api_token_here")

Or add it to your .Renviron file for persistence:

PADDLE_OCR_TOKEN=your_api_token_here

Quick Start

OCR a single image or URL

library(PaddleOCR)

# From a local file
result <- paddle_ocr("document.png")

# From a URL
result <- paddle_ocr("https://example.com/document.jpg")

# View results
result$markdown_files
result$page_count

OCR a PDF document

# Convert PDF to Markdown (requires pdftools)
result <- pdf_to_markdown_with_paddle("paper.pdf")

# The combined Markdown is saved and returned
cat(result$combined_markdown_text)

Interrupted runs resume automatically by reusing rendered page images, completed Markdown files, and submitted OCR job IDs. To run up to eight OCR jobs concurrently on the PaddleOCR service:

result <- pdf_to_markdown_with_paddle("paper.pdf", workers = 8)

Batch process PDFs

results <- batch_pdf_to_markdown_with_paddle(
  pdf_dir = "papers/",
  output_root = "papers/paddle_output"
)

Low-level API access

# Submit a job
job_id <- submit_paddle_job("image.png", token = "your_token")

# Poll for completion
jsonl_url <- poll_paddle_job(job_id, token = "your_token")

# Process the result
result <- process_paddle_jsonl_result(jsonl_url, output_dir = "output")

Features

API Options

Parameter Default Description
model "PaddleOCR-VL-1.6" OCR model to use
use_doc_orientation_classify FALSE Document orientation detection
use_doc_unwarping FALSE Document unwarping correction
use_chart_recognition FALSE Chart/table recognition
poll_interval 5 Seconds between status checks
max_wait_seconds 3600 Maximum wait time for job completion

Dependencies

License

MIT © PaddleOCR authors