Metadata-Version: 2.1
Name: magic-pdf
Version: 0.5.11
Summary: A practical tool for converting PDF to Markdown
Home-page: https://github.com/magicpdf/Magic-PDF
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: boto3 >=1.28.43
Requires-Dist: Brotli >=1.1.0
Requires-Dist: click >=8.1.7
Requires-Dist: Distance >=0.1.3
Requires-Dist: PyMuPDF >=1.24.5
Requires-Dist: loguru >=0.6.0
Requires-Dist: matplotlib >=3.8.3
Requires-Dist: numpy >=1.21.6
Requires-Dist: pandas >=1.3.5
Requires-Dist: fast-langdetect >=0.1.1
Requires-Dist: regex >=2023.12.25
Requires-Dist: termcolor >=2.4.0
Requires-Dist: wordninja >=2.0.0
Requires-Dist: scikit-learn >=1.0.2
Requires-Dist: nltk ==3.8.1
Requires-Dist: s3pathlib >=2.1.1
Requires-Dist: pdfminer.six >=20231228
Requires-Dist: Levenshtein
Requires-Dist: nltk
Requires-Dist: rapidfuzz
Requires-Dist: statistics
Requires-Dist: openxlab
Requires-Dist: pandas
Requires-Dist: numpy
Requires-Dist: matplotlib
Requires-Dist: seaborn
Requires-Dist: scipy
Requires-Dist: scikit-learn
Requires-Dist: tqdm
Requires-Dist: htmltabletomd
Requires-Dist: pypandoc
Provides-Extra: cpu
Requires-Dist: paddleocr ; extra == 'cpu'
Requires-Dist: paddlepaddle ; extra == 'cpu'
Provides-Extra: gpu
Requires-Dist: paddleocr ; extra == 'gpu'
Requires-Dist: paddlepaddle-gpu ; extra == 'gpu'

<div id="top"></div>
<div align="center">

[![stars](https://img.shields.io/github/stars/magicpdf/Magic-PDF.svg)](https://github.com/magicpdf/Magic-PDF)
[![forks](https://img.shields.io/github/forks/magicpdf/Magic-PDF.svg)](https://github.com/magicpdf/Magic-PDF)
[![license](https://img.shields.io/github/license/magicpdf/Magic-PDF.svg)](https://github.com/magicpdf/Magic-PDF/tree/main/LICENSE)
[![issue resolution](https://img.shields.io/github/issues-closed-raw/magicpdf/Magic-PDF)](https://github.com/magicpdf/Magic-PDF/issues)
[![open issues](https://img.shields.io/github/issues-raw/magicpdf/Magic-PDF)](https://github.com/magicpdf/Magic-PDF/issues)

[English](README.md) | [简体中文](README_zh-CN.md)

</div>

<div align="center">

</div>

# Magic-PDF

## Introduction

Magic-PDF is a tool designed to convert PDF documents into Markdown format, capable of processing files stored locally or on object storage supporting S3 protocol.

Key features include:

- Support for multiple front-end model inputs
- Removal of headers, footers, footnotes, and page numbers
- Human-readable layout formatting
- Retains the original document's structure and formatting, including headings, paragraphs, lists, and more
- Extraction and display of images and tables within markdown
- Conversion of equations into LaTeX format
- Automatic detection and conversion of garbled PDFs
- Compatibility with CPU and GPU environments
- Available for Windows, Linux, and macOS platforms

## Project Panorama

![Project Panorama](docs/images/project_panorama_en.png)

## Getting Started

### Requirements

- Python 3.9 or newer

### Usage Instructions

#### 1. Install Magic-PDF
```bash
pip install magic-pdf
```

#### 2. Usage via Command Line

###### simple
```bash
cp magic-pdf.template.json to ~/magic-pdf.json
magic-pdf pdf-command --pdf "pdf_path" --model "model_json_path"
```
###### more 
```bash
magic-pdf --help
```

#### 3. Usage via Api

###### Local
```python
image_writer = DiskReaderWriter(local_image_dir)
image_dir = str(os.path.basename(local_image_dir))
jso_useful_key = {"_pdf_type": "", "model_list": model_json}
pipe = UNIPipe(pdf_bytes, jso_useful_key, image_writer)
pipe.pipe_classify()
pipe.pipe_parse()
md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none")
```

###### Object Storage
```python
s3pdf_cli = S3ReaderWriter(pdf_ak, pdf_sk, pdf_endpoint)
image_dir = "s3://img_bucket/"
s3image_cli = S3ReaderWriter(img_ak, img_sk, img_endpoint, parent_path=image_dir)
pdf_bytes = s3pdf_cli.read(s3_pdf_path, mode=s3pdf_cli.MODE_BIN)
jso_useful_key = {"_pdf_type": "", "model_list": model_json}
pipe = UNIPipe(pdf_bytes, jso_useful_key, s3image_cli)
pipe.pipe_classify()
pipe.pipe_parse()
md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none")
```

Demo can be referred to [demo.py](https://github.com/magicpdf/Magic-PDF/blob/master/demo/demo.py)

## All Thanks To Our Contributors

<a href="https://github.com/magicpdf/Magic-PDF/graphs/contributors">
  <img src="https://contrib.rocks/image?repo=magicpdf/Magic-PDF" />
</a>

## License Information

See [LICENSE.md](https://github.com/magicpdf/Magic-PDF/blob/master/LICENSE.md) for details.

## Acknowledgments

- [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR)
- [PyMuPDF](https://github.com/pymupdf/PyMuPDF)
