python-fan / pdf2word

60行代码实现多线程PDF转Word

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

建议改几个地方

chamwen opened this issue · comments

主函数中:

1.避免输出时输出一堆找不到字体warning

import logging
logging.Logger.propagate = False
logging.getLogger().setLevel(logging.ERROR)

2.pdf转成txt之后至少进行一些正则匹配,下面是我加的

def pdf_to_word(pdf_file_path, word_file_path):
    content = read_from_pdf(pdf_file_path)
    content = re.compile(r'([0-9a-zA-Z_])\n([0-9a-zA-Z_])').sub(r'\1 \2', content)
    content0 = re.compile(r'(-)\n([0-9a-zA-Z_])').sub(r'\2', content)
    content1 = re.compile(r' \n ').sub(r'', content0)
    content_2 = re.compile(r'([^.])\n').sub(r'\1', content1)
    content_compile = re.compile(r'\(cid:\d{1,2}\)').sub(r'', content_2)
    save_text_to_word(content_compile, word_file_path)
commented

谢谢建议,请问下上面的正则是为了解决什么问题?

处理英文文献PDF时,一般论文都是分两栏的,转换之后会出现每一行只有一半有内容(有很多没用的换行符)。简单来说就是处理一些多余的换行,特殊符号乱码等问题

commented

了解,能否提一个pull request?