{"id":25320464,"url":"https://github.com/oomol-lab/pdf-craft","last_synced_at":"2026-01-16T09:03:06.565Z","repository":{"id":277109351,"uuid":"931354511","full_name":"oomol-lab/pdf-craft","owner":"oomol-lab","description":"PDF craft can convert PDF files into various other formats. This project will focus on processing PDF files of scanned books.","archived":false,"fork":false,"pushed_at":"2026-01-14T02:48:45.000Z","size":23177,"stargazers_count":4442,"open_issues_count":42,"forks_count":288,"subscribers_count":19,"default_branch":"main","last_synced_at":"2026-01-14T05:44:49.929Z","etag":null,"topics":["deepseek-ocr","document","ocr","pdf"],"latest_commit_sha":null,"homepage":"https://pdf.oomol.com/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oomol-lab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-12T06:10:59.000Z","updated_at":"2026-01-14T05:08:18.000Z","dependencies_parsed_at":"2025-02-12T07:45:29.190Z","dependency_job_id":"9d885ef6-3ba7-4d10-8c4a-dc64669314d5","html_url":"https://github.com/oomol-lab/pdf-craft","commit_stats":null,"previous_names":["oomol-lab/pdf-craft"],"tags_count":46,"template":false,"template_full_name":null,"purl":"pkg:github/oomol-lab/pdf-craft","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oomol-lab%2Fpdf-craft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oomol-lab%2Fpdf-craft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oomol-lab%2Fpdf-craft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oomol-lab%2Fpdf-craft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oomol-lab","download_url":"https://codeload.github.com/oomol-lab/pdf-craft/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oomol-lab%2Fpdf-craft/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deepseek-ocr","document","ocr","pdf"],"created_at":"2025-02-13T21:51:12.469Z","updated_at":"2026-01-16T09:03:06.551Z","avatar_url":"https://github.com/oomol-lab.png","language":"Python","funding_links":[],"categories":["Python","光学字符识别OCR","开源工具"],"sub_categories":["资源传输下载","好用工具"],"readme":"\u003cdiv align=center\u003e\n  \u003ch1\u003ePDF Craft\u003c/h1\u003e\n  \u003cp\u003e\n    \u003ca href=\"https://github.com/oomol-lab/pdf-craft/actions/workflows/merge-build.yml\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/oomol-lab/pdf-craft/merge-build.yml\" alt=\"ci\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/pdf-craft/\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/pip_install-pdf--craft-blue\" alt=\"pip install pdf-craft\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/pdf-craft/\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/pdf-craft.svg\" alt=\"pypi pdf-craft\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/pdf-craft/\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/pypi/pyversions/pdf-craft.svg\" alt=\"python versions\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://deepwiki.com/oomol-lab/pdf-craft\" target=\"_blank\"\u003e\u003cimg src=\"https://deepwiki.com/badge.svg\" alt=\"Ask DeepWiki\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/oomol-lab/pdf-craft/blob/main/LICENSE\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/github/license/oomol-lab/pdf-craft\" alt=\"license\" /\u003e\u003c/a\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\u003ca href=\"https://hub.oomol.com/package/pdf-craft?open=true\" target=\"_blank\"\u003e\u003cimg src=\"https://static.oomol.com/assets/button.svg\" alt=\"Open in OOMOL Studio\" /\u003e\u003c/a\u003e\u003c/p\u003e\n  \u003cp\u003eEnglish | \u003ca href=\"./README_zh-CN.md\"\u003e中文\u003c/a\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n## Introduction\n\npdf-craft converts PDF files into various other formats, with a focus on handling scanned book PDFs.\n\nThis project is based on [DeepSeek OCR](https://github.com/deepseek-ai/DeepSeek-OCR) for document recognition. It supports the recognition of complex content such as tables and formulas. With GPU acceleration, pdf-craft can complete the entire conversion process from PDF to Markdown or EPUB locally. During the conversion, pdf-craft automatically identifies document structure, accurately extracts body text, and filters out interfering elements like headers and footers. For academic or technical documents containing footnotes, formulas, and tables, pdf-craft handles them properly, preserving these important elements (including images and other assets within footnotes). When converting to EPUB, the table of contents is automatically generated. The final Markdown or EPUB files maintain the content integrity and readability of the original book.\n\n## Lightweight and Fast\n\nStarting from the official v1.0.0 release, pdf-craft fully embraces [DeepSeek OCR](https://github.com/deepseek-ai/DeepSeek-OCR) and no longer relies on LLM for text correction. This change brings significant performance improvements: the entire conversion process is completed locally without network requests, eliminating the long waits and occasional network failures of the old version.\n\nHowever, the new version has also removed the LLM text correction feature. If your use case still requires this functionality, you can continue using the old version [v0.2.8](https://github.com/oomol-lab/pdf-craft/tree/v0.2.8).\n\n### Online Demo\n\nWe provide an [online demo platform](https://pdf.oomol.com/) that lets you experience PDF Craft's conversion capabilities without any installation. You can directly upload PDF files and convert them.\n\n[![PDF Craft Online Demo](docs/images/website-en.png)](https://pdf.oomol.com/)\n\n## Quick Start\n\n### Installation\n\n```bash\npip install torch torchvision --index-url https://download.pytorch.org/whl/cpu\npip install pdf-craft\n```\n\nThe above commands are for quick setup only. To actually use pdf-craft, you need to **install Poppler** for PDF parsing (required for all use cases) and **configure a CUDA environment** for OCR recognition (required for actual conversion). Please refer to the [Installation Guide](docs/INSTALLATION.md) for detailed instructions.\n\n### Quick Start\n\n#### Convert to Markdown\n\n```python\nfrom pdf_craft import transform_markdown\n\ntransform_markdown(\n    pdf_path=\"input.pdf\",\n    markdown_path=\"output.md\",\n    markdown_assets_path=\"images\",\n)\n```\n\n![mdmd](https://github.com/user-attachments/assets/d7082496-13b8-4728-9e79-44e2888e57fd)\n\n#### Convert to EPUB\n\n```python\nfrom pdf_craft import transform_epub, BookMeta\n\ntransform_epub(\n    pdf_path=\"input.pdf\",\n    epub_path=\"output.epub\",\n    book_meta=BookMeta(\n        title=\"Book Title\",\n        authors=[\"Author\"],\n    ),\n)\n```\n\n![20251218-162533](https://github.com/user-attachments/assets/7f6df04a-1fa7-48b3-aa5e-d2d056304ad6)\n\n## Detailed Usage\n\n### Convert to Markdown\n\n```python\nfrom pdf_craft import transform_markdown\n\ntransform_markdown(\n    pdf_path=\"input.pdf\",\n    markdown_path=\"output.md\",\n    markdown_assets_path=\"images\",\n    analysing_path=\"temp\",  # Optional: specify temporary folder\n    ocr_size=\"gundam\",  # Optional: tiny, small, base, large, gundam\n    models_cache_path=\"models\",  # Optional: model cache path\n    dpi=300,  # Optional: DPI for rendering PDF pages (default: 300)\n    max_page_image_file_size=None,  # Optional: max image file size in bytes, auto-adjust DPI if exceeded\n    includes_cover=False,  # Optional: include cover\n    includes_footnotes=True,  # Optional: include footnotes\n    ignore_pdf_errors=False,  # Optional: continue on PDF rendering errors\n    ignore_ocr_errors=False,  # Optional: continue on OCR recognition errors\n    generate_plot=False,  # Optional: generate visualization charts\n    toc_assumed=False,  # Optional: assume PDF contains a table of contents page\n)\n```\n\n### Convert to EPUB\n\n```python\nfrom pdf_craft import transform_epub, BookMeta, TableRender, LaTeXRender\n\ntransform_epub(\n    pdf_path=\"input.pdf\",\n    epub_path=\"output.epub\",\n    analysing_path=\"temp\",  # Optional: specify temporary folder\n    ocr_size=\"gundam\",  # Optional: tiny, small, base, large, gundam\n    models_cache_path=\"models\",  # Optional: model cache path\n    dpi=300,  # Optional: DPI for rendering PDF pages (default: 300)\n    max_page_image_file_size=None,  # Optional: max image file size in bytes, auto-adjust DPI if exceeded\n    includes_cover=True,  # Optional: include cover\n    includes_footnotes=True,  # Optional: include footnotes\n    ignore_pdf_errors=False,  # Optional: continue on PDF rendering errors\n    ignore_ocr_errors=False,  # Optional: continue on OCR recognition errors\n    generate_plot=False,  # Optional: generate visualization charts\n    toc_assumed=True,  # Optional: assume PDF contains a table of contents page\n    book_meta=BookMeta(\n        title=\"Book Title\",\n        authors=[\"Author 1\", \"Author 2\"],\n        publisher=\"Publisher\",\n        language=\"en\",\n    ),\n    lan=\"en\",  # Optional: language (zh/en)\n    table_render=TableRender.HTML,  # Optional: table rendering method\n    latex_render=LaTeXRender.MATHML,  # Optional: formula rendering method\n    inline_latex=True,  # Optional: preserve inline LaTeX expressions\n)\n```\n\n### Model Management\n\npdf-craft depends on DeepSeek OCR models, which are automatically downloaded from Hugging Face on first run. You can control model storage and loading behavior through the `models_cache_path` and `local_only` parameters.\n\n#### Pre-download Models\n\nIn production environments, it is recommended to download models in advance to avoid downloading on first run:\n\n```python\nfrom pdf_craft import predownload_models\n\npredownload_models(\n    models_cache_path=\"models\",  # Specify model cache directory\n    revision=None,  # Optional: specify model version\n)\n```\n\n#### Specify Model Cache Path\n\nBy default, models are downloaded to the system's Hugging Face cache directory. You can customize the cache location through the `models_cache_path` parameter:\n\n```python\nfrom pdf_craft import transform_markdown\n\ntransform_markdown(\n    pdf_path=\"input.pdf\",\n    markdown_path=\"output.md\",\n    models_cache_path=\"./my_models\",  # Custom model cache directory\n)\n```\n\n#### Offline Mode\n\nIf you have pre-downloaded the models, you can use `local_only=True` to disable network downloads and ensure only local models are used:\n\n```python\nfrom pdf_craft import transform_markdown\n\ntransform_markdown(\n    pdf_path=\"input.pdf\",\n    markdown_path=\"output.md\",\n    models_cache_path=\"./my_models\",\n    local_only=True,  # Use local models only, do not download from network\n)\n```\n\n## API Reference\n\n### OCR Models\n\nThe `ocr_size` parameter accepts a `DeepSeekOCRSize` type:\n\n- `tiny` - Smallest model, fastest speed\n- `small` - Small model\n- `base` - Base model\n- `large` - Large model\n- `gundam` - Largest model, highest quality (default)\n\n### Table Rendering Methods\n\n- `TableRender.HTML` - HTML format (default)\n- `TableRender.CLIPPING` - Clipping format (directly clips table images from the original PDF scan)\n\n### Formula Rendering Methods\n\n- `LaTeXRender.MATHML` - MathML format (default)\n- `LaTeXRender.SVG` - SVG format\n- `LaTeXRender.CLIPPING` - Clipping format (directly clips formula images from the original PDF scan)\n\n### Inline LaTeX\n\nThe `inline_latex` parameter (EPUB only, default: `True`) controls whether to preserve inline LaTeX expressions in the output. When enabled, inline mathematical formulas are preserved as LaTeX code, which can be rendered by compatible EPUB readers.\n\n### Table of Contents Detection\n\nThe `toc_assumed` parameter controls whether pdf-craft should assume the PDF contains a table of contents page:\n\n- When `True` (default for EPUB): pdf-craft attempts to locate and extract the table of contents from within the PDF, using it to build the document structure\n- When `False` (default for Markdown): pdf-craft generates the table of contents based on document headings only\n\nFor books with a dedicated table of contents section, setting `toc_assumed=True` typically produces better chapter organization.\n\n### Custom PDF Handler\n\nBy default, pdf-craft uses Poppler (via `pdf2image`) for PDF parsing and rendering. If Poppler is not in your system PATH, you can specify a custom path:\n\n```python\nfrom pdf_craft import transform_markdown, DefaultPDFHandler\n\n# Specify custom Poppler path\ntransform_markdown(\n    pdf_path=\"input.pdf\",\n    markdown_path=\"output.md\",\n    pdf_handler=DefaultPDFHandler(poppler_path=\"/path/to/poppler/bin\"),\n)\n```\n\nIf not specified, pdf-craft will use Poppler from your system PATH. For advanced use cases, you can also implement the `PDFHandler` protocol to use alternative PDF libraries.\n\n### Error Handling\n\nThe `ignore_pdf_errors` and `ignore_ocr_errors` parameters provide flexible error handling options. You can use them in two ways:\n\n**1. Boolean Mode** - Simple on/off control:\n\n```python\nfrom pdf_craft import transform_markdown\n\ntransform_markdown(\n    pdf_path=\"input.pdf\",\n    markdown_path=\"output.md\",\n    ignore_pdf_errors=True,  # Ignore all PDF rendering errors\n    ignore_ocr_errors=True,  # Ignore all OCR recognition errors\n)\n```\n\nWhen set to `True`, processing continues when errors occur on individual pages, inserting a placeholder message instead of stopping the entire conversion.\n\n**2. Custom Function Mode** - Fine-grained control:\n\n```python\nfrom pdf_craft import transform_markdown, OCRError, PDFError\n\ndef should_ignore_ocr_error(error: OCRError) -\u003e bool:\n    # Only ignore specific types of OCR errors\n    return error.kind == \"recognition_failed\"\n\ndef should_ignore_pdf_error(error: PDFError) -\u003e bool:\n    # Custom logic to decide which PDF errors to ignore\n    return \"timeout\" in str(error)\n\ntransform_markdown(\n    pdf_path=\"input.pdf\",\n    markdown_path=\"output.md\",\n    ignore_ocr_errors=should_ignore_ocr_error,  # Pass custom function\n    ignore_pdf_errors=should_ignore_pdf_error,  # Pass custom function\n)\n```\n\nThis allows you to implement custom logic for deciding which specific errors should be ignored during conversion.\n\n## Related Open Source Libraries\n\n[epub-translator](https://github.com/oomol-lab/epub-translator) uses AI large language models to automatically translate EPUB e-books while 100% preserving the original book's format, illustrations, table of contents, and layout. It also generates bilingual versions for convenient language learning or international sharing. When combined with this library, you can convert and translate scanned PDF books. For a demonstration, see this [video: Convert PDF scanned books to EPUB format and translate to bilingual books](https://www.bilibili.com/video/BV1tMQZY5EYY).\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.\n\nStarting from v1.0.0, pdf-craft has fully migrated to DeepSeek OCR (MIT license), removing the previous AGPL-3.0 dependency, allowing the entire project to be released under the more permissive MIT license. Note that pdf-craft has a transitive dependency on easydict (LGPLv3) via DeepSeek OCR. Thanks to the community for their support and contributions!\n\n## Acknowledgments\n\n- [DeepSeekOCR](https://github.com/deepseek-ai/DeepSeek-OCR)\n- [doc-page-extractor](https://github.com/Moskize91/doc-page-extractor)\n- [pyahocorasick](https://github.com/WojciechMula/pyahocorasick)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foomol-lab%2Fpdf-craft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foomol-lab%2Fpdf-craft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foomol-lab%2Fpdf-craft/lists"}