Replies: 3 comments
-
I tested to prepare 3 textline
But the position after apply the same morph changes to above three inserted texts, the position does not match, any method to match space after applied transform for above 3 textline? ''' text_pure = text_aqua = text_red = ''' |
Beta Was this translation helpful? Give feedback.
-
Another font is a little better, but some characters cannot be displayed? Any method to use font family to support all characters? |
Beta Was this translation helpful? Give feedback.
-
Some characters can match, and some cannot. |
Beta Was this translation helpful? Give feedback.
-
'''
import fitz # 导入 PyMuPDF
创建新的 PDF 文档
doc = fitz.Document()
新建一页
page = doc.new_page()
定义插入文本的位置和字体大小
x, y = 100, 100
font_size = 10
stretch_factor = 10.0 # 拉伸因子(大于1表示横向拉伸)
text = "This is a test."
point = p1 = fitz.Point(x, y - font_size)
应用横向拉伸的变换
transform_matrix = fitz.Matrix(stretch_factor, 0, 0, 1, 0, 0)
transform_matrix = fitz.Matrix(stretch_factor, 0, 0, 1, 0, 0)
绘制文本,应用变换
page.insert_text((x, y), text, fontsize=font_size, color=(0,0,0), morph=(point, transform_matrix ))
page.insert_text((x, y+100), text, fontsize=font_size, color=(0,0,0))
rect = fitz.Rect(100, 100, 400, 150)
page.insert_htmlbox(rect, text)
保存 PDF 文件
doc.save(r'F:\transformed_text.pdf', garbage=3, deflate=True)
doc.close()
'''
Beta Was this translation helpful? Give feedback.
All reactions