Refer to
Easily convert PDF to Word with just 2 lines of code
Introduce:
To use Python to convert PDF to Word, you need to extract the data in the PDF file through the PYMuPDF library in python, then use the python-docx library to parse the layout, paragraphs, pictures, tables, etc. of the content, and finally automatically generate a docx file.
- 解析和创建页面布局
- 页边距
- 章节和分栏 (目前最多支持两栏布局)
- 页眉和页脚 [TODO]
- 解析和创建段落
- OCR 文本 [TODO]
- 水平(从左到右)或竖直(自底向上)方向文本
- 字体样式例如字体、字号、粗/斜体、颜色
- 文本样式例如高亮、下划线和删除线
- 列表样式 [TODO]
- 外部超链接
- 段落水平对齐方式 (左/右/居中/分散对齐)及前后间距
- 解析和创建图片
- 内联图片
- 灰度/RGB/CMYK等颜色空间图片
- 带有透明通道图片
- 浮动图片(衬于文字下方)
- 解析和创建表格
- 边框样式例如宽度和颜色
- 单元格背景色
- 合并单元格
- 单元格垂直文本
- 隐藏部分边框线的表格
- 嵌套表格
- 支持多进程转换
Step:
- Install the pdf2docx library
pip install pdf2docx
- Code
''' PDF2docx According to PyMuPDF documentation,we could use python to extract data from PDF documents. And using python-docx analysis the contents.Finally,the docx file is automatically generated. Refer to :https://mp.weixin.qq.com/s/bXOaH1jEWGudaWakww47RQ ''' from pdf2docx import parse pdf_file = '/path/to/sample.pdf' docx_file = 'path/to/sample.docx' # convert pdf to docx parse(pdf_file, docx_file)
-
achieve effect