| Title: | R Client for the 'PaddleOCR' Cloud API |
|---|---|
| Description: | 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. |
| Authors: | Chaoyang Luo [aut, cre] |
| Maintainer: | Chaoyang Luo <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.1 |
| Built: | 2026-09-30 12:41:40 UTC |
| Source: | https://github.com/xiaoluolorn/paddleocr |
Processes all PDF files in a directory, converting each to Markdown using
pdf_to_markdown_with_paddle. Requires the pdftools
package.
batch_pdf_to_markdown_with_paddle( pdf_dir = ".", output_root = file.path(pdf_dir, "paddle_output"), dpi = 300, batch_trigger = 3, workers = 1, resume = TRUE, token = "", job_url = "", model = "", poll_interval = 5, max_wait_seconds = 1800, timeout = 600 )batch_pdf_to_markdown_with_paddle( pdf_dir = ".", output_root = file.path(pdf_dir, "paddle_output"), dpi = 300, batch_trigger = 3, workers = 1, resume = TRUE, token = "", job_url = "", model = "", poll_interval = 5, max_wait_seconds = 1800, timeout = 600 )
pdf_dir |
Directory containing PDF files (default: current directory). |
output_root |
Root directory for output (default:
|
dpi |
Image resolution for rendering (default: 300). |
batch_trigger |
Number of pages to render before starting OCR (default: 3). |
workers |
Maximum number of OCR jobs submitted concurrently. |
resume |
Logical; reuse completed work from interrupted runs. |
token |
PaddleOCR API token. |
job_url |
PaddleOCR API endpoint. |
model |
Model name. |
poll_interval |
Polling interval in seconds. |
max_wait_seconds |
Maximum wait time per job. |
timeout |
HTTP timeout. |
A named list of results (one per PDF). Failed conversions return a
list with an error element.
## Not run: results <- batch_pdf_to_markdown_with_paddle( pdf_dir = "papers", output_root = "papers/paddle_output" ) ## End(Not run)## Not run: results <- batch_pdf_to_markdown_with_paddle( pdf_dir = "papers", output_root = "papers/paddle_output" ) ## End(Not run)
Submits an image for OCR, polls for completion, and saves Markdown output.
image_to_markdown( image_path, output_dir, page_index, token = "", job_url = "", model = "", use_doc_orientation_classify = FALSE, use_doc_unwarping = FALSE, use_chart_recognition = FALSE, poll_interval = 5, max_wait_seconds = 1800, timeout = 600 )image_to_markdown( image_path, output_dir, page_index, token = "", job_url = "", model = "", use_doc_orientation_classify = FALSE, use_doc_unwarping = FALSE, use_chart_recognition = FALSE, poll_interval = 5, max_wait_seconds = 1800, timeout = 600 )
image_path |
Path to the image file. |
output_dir |
Directory for OCR output. |
page_index |
Page index for naming output files (1-indexed). |
token |
PaddleOCR API token. |
job_url |
PaddleOCR API endpoint. |
model |
Model name. |
use_doc_orientation_classify |
Logical; enable orientation classification. |
use_doc_unwarping |
Logical; enable document unwarping. |
use_chart_recognition |
Logical; enable chart recognition. |
poll_interval |
Polling interval in seconds. |
max_wait_seconds |
Maximum wait time. |
timeout |
HTTP timeout. |
A list with markdown_paths, markdown_texts, and
job_id.
## Not run: result <- image_to_markdown("page_1.png", output_dir = "output", page_index = 1) ## End(Not run)## Not run: result <- image_to_markdown("page_1.png", output_dir = "output", page_index = 1) ## End(Not run)
This is the main entry point for the PaddleOCR cloud API. Submit a local file (image or document) or a URL, and the function will handle job submission, polling, result retrieval, and file saving automatically.
paddle_ocr( file_path, output_dir = "output", token = "", job_url = "", model = "", use_doc_orientation_classify = FALSE, use_doc_unwarping = FALSE, use_chart_recognition = FALSE, poll_interval = 5, max_wait_seconds = 3600, timeout = 600 )paddle_ocr( file_path, output_dir = "output", token = "", job_url = "", model = "", use_doc_orientation_classify = FALSE, use_doc_unwarping = FALSE, use_chart_recognition = FALSE, poll_interval = 5, max_wait_seconds = 3600, timeout = 600 )
file_path |
A local file path or a URL ( |
output_dir |
Directory to save output Markdown and images
(default: |
token |
PaddleOCR API bearer token. If empty, reads from the
|
job_url |
PaddleOCR API endpoint. Defaults to the official cloud URL. |
model |
Model name to use. Defaults to |
use_doc_orientation_classify |
Logical; enable document orientation classification. |
use_doc_unwarping |
Logical; enable document unwarping. |
use_chart_recognition |
Logical; enable chart/table recognition. |
poll_interval |
Seconds between status checks (default: 5). |
max_wait_seconds |
Maximum wait time for job completion (default: 3600). |
timeout |
HTTP request timeout in seconds (default: 600). |
A list with elements:
Input file path or URL.
The submitted job ID.
Output directory path.
Paths to saved Markdown files.
Number of pages processed.
## Not run: # OCR a local image result <- paddle_ocr("document.png") # OCR a URL result <- paddle_ocr("https://example.com/document.jpg") # With custom options result <- paddle_ocr( file_path = "table.png", use_chart_recognition = TRUE, output_dir = "my_output" ) ## End(Not run)## Not run: # OCR a local image result <- paddle_ocr("document.png") # OCR a URL result <- paddle_ocr("https://example.com/document.jpg") # With custom options result <- paddle_ocr( file_path = "table.png", use_chart_recognition = TRUE, output_dir = "my_output" ) ## End(Not run)
Renders one page of a PDF to a PNG file. Uses a temporary directory internally to avoid pdftools filename template issues.
pdf_page_to_image(pdf_path, page_index, image_dir, dpi = 300, overwrite = TRUE)pdf_page_to_image(pdf_path, page_index, image_dir, dpi = 300, overwrite = TRUE)
pdf_path |
Path to the PDF file. |
page_index |
Page number to render (1-indexed). |
image_dir |
Directory to save the PNG image. |
dpi |
Resolution in dots per inch (default: 300). |
overwrite |
Logical; overwrite an existing rendered page. Set to
|
Path to the saved PNG image.
## Not run: img <- pdf_page_to_image("document.pdf", page_index = 1, image_dir = "pages") ## End(Not run)## Not run: img <- pdf_page_to_image("document.pdf", page_index = 1, image_dir = "pages") ## End(Not run)
Renders every page of a PDF file to PNG images at the specified DPI. Requires the pdftools package.
pdf_to_images(pdf_path, image_dir, dpi = 300)pdf_to_images(pdf_path, image_dir, dpi = 300)
pdf_path |
Path to the PDF file. |
image_dir |
Directory to save PNG images into. |
dpi |
Resolution in dots per inch (default: 300). |
A character vector of image file paths.
## Not run: images <- pdf_to_images("document.pdf", "images", dpi = 300) ## End(Not run)## Not run: images <- pdf_to_images("document.pdf", "images", dpi = 300) ## End(Not run)
Renders PDF pages to images one by one, then submits them for OCR using
the PaddleOCR cloud API. Pages are processed in streaming batches:
once batch_trigger pages are rendered, OCR begins while rendering
continues.
pdf_to_markdown_with_paddle( pdf_path, output_dir = NULL, combined_markdown = TRUE, dpi = 300, batch_trigger = 3, workers = 1, resume = TRUE, token = "", job_url = "", model = "", use_doc_orientation_classify = FALSE, use_doc_unwarping = FALSE, use_chart_recognition = FALSE, poll_interval = 5, max_wait_seconds = 1800, timeout = 600, ... )pdf_to_markdown_with_paddle( pdf_path, output_dir = NULL, combined_markdown = TRUE, dpi = 300, batch_trigger = 3, workers = 1, resume = TRUE, token = "", job_url = "", model = "", use_doc_orientation_classify = FALSE, use_doc_unwarping = FALSE, use_chart_recognition = FALSE, poll_interval = 5, max_wait_seconds = 1800, timeout = 600, ... )
pdf_path |
Path to the PDF file. |
output_dir |
Output directory. If |
combined_markdown |
Logical; if |
dpi |
Image resolution for rendering (default: 300). |
batch_trigger |
Number of pages to render before starting OCR (default: 3). |
workers |
Maximum number of OCR jobs submitted concurrently (default: 1). OCR runs concurrently on the PaddleOCR service; result polling remains local and sequential. |
resume |
Logical; reuse rendered page images, completed Markdown files,
and submitted job IDs from an interrupted run (default: |
token |
PaddleOCR API token. |
job_url |
PaddleOCR API endpoint. |
model |
Model name. |
use_doc_orientation_classify |
Logical; enable orientation classification. |
use_doc_unwarping |
Logical; enable document unwarping. |
use_chart_recognition |
Logical; enable chart recognition. |
poll_interval |
Polling interval in seconds. |
max_wait_seconds |
Maximum wait time per job. |
timeout |
HTTP timeout. |
... |
Ignored (for future compatibility). |
Requires the pdftools package.
A list with PDF path, image paths, Markdown file paths, combined Markdown path and text, and output directory.
## Not run: result <- pdf_to_markdown_with_paddle("document.pdf") cat(result$combined_markdown_text) ## End(Not run)## Not run: result <- pdf_to_markdown_with_paddle("document.pdf") cat(result$combined_markdown_text) ## End(Not run)
Repeatedly queries the job status endpoint until the job reaches
"done" or "failed" state, or the maximum wait time is
exceeded.
poll_paddle_job( job_id, token = "", job_url = "", poll_interval = 5, max_wait_seconds = 3600 )poll_paddle_job( job_id, token = "", job_url = "", poll_interval = 5, max_wait_seconds = 3600 )
job_id |
The job ID returned by |
token |
PaddleOCR API bearer token. If empty, reads from the
|
job_url |
PaddleOCR API endpoint. Defaults to the official cloud URL. |
poll_interval |
Seconds between status checks (default: 5). |
max_wait_seconds |
Maximum total wait time in seconds (default: 3600). |
A character string containing the JSONL result URL.
## Not run: job_id <- submit_paddle_job("document.png", token = "your_token") jsonl_url <- poll_paddle_job(job_id, token = "your_token") ## End(Not run)## Not run: job_id <- submit_paddle_job("document.png", token = "your_token") jsonl_url <- poll_paddle_job(job_id, token = "your_token") ## End(Not run)
Fetches the JSONL result from the URL, parses each line, and saves layout-parsed Markdown documents and their associated images.
process_paddle_jsonl_result(jsonl_url, output_dir, starting_doc_index = 0L)process_paddle_jsonl_result(jsonl_url, output_dir, starting_doc_index = 0L)
jsonl_url |
URL to the JSONL result file. |
output_dir |
Directory to save output files. |
starting_doc_index |
Integer offset for naming output files (default: 0). |
A list with elements markdown_files (file paths),
markdown_texts (text content), and doc_count (number of
documents saved).
## Not run: result <- process_paddle_jsonl_result( jsonl_url = "https://example.com/result.jsonl", output_dir = "output" ) ## End(Not run)## Not run: result <- process_paddle_jsonl_result( jsonl_url = "https://example.com/result.jsonl", output_dir = "output" ) ## End(Not run)
Submits a local file or a URL for OCR processing. The function detects whether the input is a URL or a local file path and uses the appropriate API call method (JSON body vs. multipart upload).
submit_paddle_job( file_path, token = "", job_url = "", model = "", use_doc_orientation_classify = FALSE, use_doc_unwarping = FALSE, use_chart_recognition = FALSE, timeout = 600 )submit_paddle_job( file_path, token = "", job_url = "", model = "", use_doc_orientation_classify = FALSE, use_doc_unwarping = FALSE, use_chart_recognition = FALSE, timeout = 600 )
file_path |
A local file path or a URL ( |
token |
PaddleOCR API bearer token. If empty, reads from the
|
job_url |
PaddleOCR API endpoint. Defaults to the official cloud URL. |
model |
Model name to use. Defaults to |
use_doc_orientation_classify |
Logical; enable document orientation classification. |
use_doc_unwarping |
Logical; enable document unwarping. |
use_chart_recognition |
Logical; enable chart/table recognition. |
timeout |
HTTP request timeout in seconds (default: 600). |
A character string containing the job ID.
## Not run: # Submit a local image job_id <- submit_paddle_job( file_path = "document.png", token = "your_token_here" ) # Submit a URL job_id <- submit_paddle_job( file_path = "https://example.com/document.jpg", token = "your_token_here" ) ## End(Not run)## Not run: # Submit a local image job_id <- submit_paddle_job( file_path = "document.png", token = "your_token_here" ) # Submit a URL job_id <- submit_paddle_job( file_path = "https://example.com/document.jpg", token = "your_token_here" ) ## End(Not run)