Handle PDF more easily and simply, utilizing Doc2X's powerful document conversion capabilities for retained format file conversion/RAG enhancement.
Doc2X is a new universal document OCR tool that can convert images or PDF files into Markdown/LaTeX text with formulas and text formatting. It performs better than similar tools in most scenarios. pdfdeal
provides abstract packaged classes to use Doc2X for requests.
Use various OCR or PDF recognition tools to identify images and add them to the original text. You can set the output format to use PDF, which will ensure that the recognized text retains the same page numbers as the original in the new PDF. It also offers various practical file processing tools.
After conversion and pre-processing of PDF using Doc2X, you can achieve better recognition rates when used with knowledge base applications such as graphrag, Dify, and FastGPT.
See how to use it with graphrag, its not supported to recognize pdf, but you can use the CLI tool doc2x
to convert it to a txt document for use.
Or for knowledge base applications, you can use pdfdeal
's built-in variety of enhancements to documents, such as uploading images to remote storage services, adding breaks by paragraph, etc. See Integration with RAG applications.
![](https://private-user-images.githubusercontent.com/122662527/360427185-034d3eb0-d77e-4f7d-a707-9be08a092a9a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ3MDk5ODksIm5iZiI6MTcyNDcwOTY4OSwicGF0aCI6Ii8xMjI2NjI1MjcvMzYwNDI3MTg1LTAzNGQzZWIwLWQ3N2UtNGY3ZC1hNzA3LTliZTA4YTA5MmE5YS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODI2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgyNlQyMjAxMjlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1lMTVhMTFlM2I4YjJiMjE3ODJjMTdmOWRhNzY4OGQwMjI3ZjFkYmMxNDE1NGFlMzJiOTBlODU4YzA4MTZhMmVjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.13dAFmhq04Auae6Rd2ApDNZN_Zya2j9_w_sW0NV29iI)
![](https://private-user-images.githubusercontent.com/122662527/360427192-6078e585-7c06-485f-bcd3-9fac84eb7301.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ3MDk5ODksIm5iZiI6MTcyNDcwOTY4OSwicGF0aCI6Ii8xMjI2NjI1MjcvMzYwNDI3MTkyLTYwNzhlNTg1LTdjMDYtNDg1Zi1iY2QzLTlmYWM4NGViNzMwMS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODI2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgyNlQyMjAxMjlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT04YjFjNDk2YjhhZTIzMjQ2NDYzZDBjZjI3NWIyZTdiYzZlMDU4YzlkMmFmYmM2MTA2ZmZkOTg1M2VmNTYwNThlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.oJEw_clGOZkxVXKbZPNwUQ2nXe4OiauK4I1d6diDBLM)
- You can find Doc2X plugin in FastGPT 4.8.9 and later which supports PDF/image conversion.
For details, please refer to the documentation
Or check out the documentation repository pdfdeal-docs.
For details, please refer to the documentation
Install from PyPI:
pip install --upgrade pdfdeal
from pdfdeal import Doc2X
from pdfdeal import get_files
client = Doc2X()
file_list, rename = get_files(path="tests/pdf", mode="pdf", out="pdf")
success, failed, flag = client.pdfdeal(
pdf_file=file_list,
output_path="./Output/test/multiple/pdfdeal",
output_names=rename,
)
print(success)
print(failed)
print(flag)
When using "pytesseract", make sure that tesseract is installed first:
pip install 'pdfdeal[pytesseract]'
from pdfdeal import deal_pdf, get_files
files, rename = get_files("tests/pdf", "pdf", "md")
output_path, failed, flag = deal_pdf(
pdf_file=files,
output_format="md",
ocr="pytesseract",
language=["eng"],
output_path="Output",
output_names=rename,
)
for f in output_path:
print(f"Save processed file to {f}")
See the online documentation for details.