R Client for the 'PaddleOCR' Cloud API

An R client for the 'PaddleOCR' cloud service API < https://www.paddleocr.ai/latest/en/version3.x/inference_deployment/serving/paddleocr_official_api/overview.html>. Submit images, PDFs, or URLs for OCR processing using models like 'PaddleOCR-VL-1.6'. Supports job submission, polling, result retrieval, automatic image download, and streaming PDF-to-markdown conversion with batch processing.


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

  • Simple API: paddle_ocr() handles everything from submission to result saving
  • File & URL support: Submit local files or remote URLs
  • PDF processing: Streaming page-by-page PDF rendering and OCR
  • Batch processing: Process entire directories of PDFs
  • Auto image download: Inline Markdown images and layout images are saved automatically
  • Configurable: Model selection, orientation classification, unwarping, chart recognition

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

  • Required: httr, jsonlite
  • Optional: pdftools (for PDF processing)

License

MIT © PaddleOCR authors

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("PaddleOCR")

0.2.1 by Chaoyang Luo, 2 months ago


https://github.com/xiaoluolorn/PaddleOCR


Report a bug at https://github.com/xiaoluolorn/PaddleOCR/issues


Browse source code at https://github.com/cran/PaddleOCR


Authors: Chaoyang Luo [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports httr, jsonlite, tools, utils

Suggests pdftools, testthat, withr


See at CRAN