Comments (3)
Thank you for your fast reply!
Fixed code this way
if isinstance(self.parent._parent, Cell):
delete_paragraph(doc.paragraphs[-1])
(added _parent) and now everything works.
from pdf2docx.
Many thanks to report this issue.
The root cause is a fact in Word document that an empty line is always created automatically when insert a nested table into a cell. So, a fix is to delete such line -> will be included in next version.
For now, you can modify the source code based on version 0.5.1
:
- Find
Blocks.py
>>> import pdf2docx
>>> pdf2docx.page.Blocks.__file__
'd:\\workspace\\github\\pdf2docx\\pdf2docx\\page\\Blocks.py'
- Check lines 523-538 in method
make_docx()
for block in self._instances:
# make paragraphs
if block.is_text_image_block():
# new paragraph
p = doc.add_paragraph()
block.make_docx(p)
pre_table = False # mark block type
# make table
elif block.is_table_block():
make_table(block, pre_table)
pre_table = True # mark block type
# below table processing is necessary for page level only
if isinstance(self.parent, Cell): return
- Change the above lines 523-538 to as follows
for block in self._instances:
# make paragraphs
if block.is_text_image_block():
# new paragraph
p = doc.add_paragraph()
block.make_docx(p)
pre_table = False # mark block type
# make table
elif block.is_table_block():
make_table(block, pre_table)
pre_table = True # mark block type
# NOTE: within a cell, there is always an empty paragraph after table,
# so, delete it right here
if isinstance(self.parent, Cell):
delete_paragraph(doc.paragraphs[-1])
Note to import method delete_paragraph()
accordingly:
from ..common.docx import reset_paragraph_format, delete_paragraph
from pdf2docx.
Ah, my fix was based on dev
. Per version 0.5.1
, self.parent
-> Layout
, then Layout._parent
-> Cell
.
So, thank you for figuring it out
from pdf2docx.
Related Issues (20)
- transfer error:unsupported colorspace for '{output}' HOT 1
- [WARNING] Ignore Line "<image>" due to overlap
- 无法复原pdf文件中表格的框线 HOT 1
- How to save highlight in table after convert pdf to docx HOT 4
- Negative ref_dif in Blocks.py causing paragraph splitting
- 转化后存在页面超出的问题
- ValueError: unsupported colorspace for 'png' HOT 2
- Any support for ANDROID? HOT 1
- 转换时遇到字体名为中文(比如“宋体”)时,发生错误 HOT 1
- language support
- pdf2docx.Converter将某些特殊pdf转word时,某个子进程会卡住 HOT 3
- Table is broken when the table is displayed on 2 pages HOT 1
- 关于行高分配的逻辑疑问
- 转换docx表格中文本不全,请问这个可以解决吗
- Resource Han Rounded CN Light rendered as "Resource"
- 转word后图片被旋转180° HOT 11
- 表格生成的时候没有处理好浮动形图片 HOT 1
- 含XFA表单域的PDF无法转换为word
- 占用内存没有gc
- pdf转word后,表格会溢出边界
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdf2docx.