keep the table grid lines align when use Chinese fonts #3939
-
Is your feature request related to a problem? Please describe. Describe the solution you'd like Describe alternatives you've considered Additional context import pymupdf
import duckdb
text = duckdb.sql("select '张三' 名字") # some text
doc = pymupdf.open() # empty pdf
text1=str(text)
print(text1)
n = doc.insert_page(-1, # default insertion point
text = text1,
fontsize = 11,
width = 595,
height = 842,
fontname = "china-s", # or "Courier"
fontfile = None, # any font file name
color = (0, 0, 0)) # text color (RGB)
doc.save(
"duckdboutput.pdf",
)
it output
┌─────────┐
│ 名字 │
│ varchar │
├─────────┤
│ 张三 │
└─────────┘ |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 5 replies
-
This is not an enhancement request. |
Beta Was this translation helpful? Give feedback.
-
In PyMuPDF, there are several ways to do this.
Example for option 1: import pymupdf
doc = pymupdf.open()
page = doc.new_page()
rect = pymupdf.Rect(100, 100, 400, 400)
cols = 3
rows = 5
cells = pymupdf.make_table(rect, rows=rows, cols=cols)
for i in range(rows):
for j in range(cols):
page.draw_rect(cells[i][j], color=(1, 0, 0))
page.insert_htmlbox(cells[i][j], f"第 {i} 行、第 {j} 列的任意文本")
doc.ez_save("x.pdf") |
Beta Was this translation helpful? Give feedback.
-
it's not a draw table question. |
Beta Was this translation helpful? Give feedback.
-
@JorjMcKie |
Beta Was this translation helpful? Give feedback.
-
I tried page = doc.new_page()
page.insert_htmlbox(page.rect,text1) it output the text without new lines, in other words, it omits the \n chars in the string. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
btw, by using wkhtmltopdf tools can output a fine aligned pdf. --not yet,see the notepad print to pdf does output a fine aligned pdf, see |
Beta Was this translation helpful? Give feedback.
-
doc.subset_fonts()
doc.ez_save() reduces the file size, but also cannot display the horizon gridlines. such as
|
Beta Was this translation helpful? Give feedback.
-
I tried many fonts, |
Beta Was this translation helpful? Give feedback.
-
I solved the question by using a font file |
Beta Was this translation helpful? Give feedback.
I solved the question by using a font file
page.insert_text((0,0),text1,fontname="milk",fontfile='d:/milky-term-cn-normal.ttf')