簡體   English   中英

將掃描的 PDF 或 tessaract 可搜索的 PDF 轉換為 docx/doc 並使用 python 維護所有格式和布局

[英]Convert Scanned PDF or tessaract searchable PDF to docx/doc and maintaing all formats and layouts using python

需要將掃描的 pdf 轉換為 docx 文檔。到目前為止我使用的方法 1. 使用 pytessaract 將掃描的 pdf 轉換為可搜索的 pdf pytesseract.image_to_pdf_or_hocr() 2. 然后使用 lowriter 'lowriter --invisible - 將該可搜索的 pdf 轉換為 docx - -轉換為 docx"{}"

但這會導致 docx /doc 中的格式和布局問題,並且生成的 docx 文件中存在文本和圖像重疊。 請幫忙

您可以使用pythons,pdfminer將您的pdf轉換為txt,這在內存方面比tesseract更好,它接受al文本數據,但丟失格式,然后您可以使用python-Docx將此txt文件轉換為Docx

from docx import Document
import re
import os

path = 'your path'
direct = os.listdir(path)

for i in direct:
    document = Document()
    document.add_heading(i, 0)
    myfile = open('/path/to/read/from/'+i).read()
    myfile = re.sub(r'[^\x00-\x7F]+|\x0c',' ', myfile) # remove all non-XML-compatible 
  characters
    p = document.add_paragraph(myfile)
    document.save('/path/to/write/to/'+i+'.docx')

或者您可以將文檔轉換為 XML 並以這種方式閱讀,您可能可以通過比較字體大小來保存格式,

GroupDocs.Conversion Cloud,提供用於文本/PDF 到 DOC/DOCX 和許多其他常見文件格式從一種格式到另一種格式的轉換的 Python SDK,不依賴於任何第三方工具或軟件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM