python - 如何在python中使用pyPDF2更改pdf文件中的字体
问题描述
如何更改 pyPDF 2 模块中的字体。
我试过了print(help(canvas.Canvas))
我尝试了initialFontName = None
和initialFontSize = None
但我的文字没有改变。另外,我正在使用带有 raspbian 操作系统的 raspberry-pi 来执行此操作。
这是我的代码
can = canvas.Canvas(packet, pagesize=letter, initialFontName = 'Helvetica', initialFontSize = 5)
now = datetime.datetime.now()
can.drawString(250, 500, self.get_Firstn1 + ' ' + self.get_Middlen1 +' ' + self.get_Lastn1)
can.drawString(300, 550, "Hello World")
can.drawString(350, 600,"Hello")
can.save()
packet.seek(0)
new_pdf = PdfFileReader(packet)
existing_pdf = PdfFileReader(open("Sample.pdf", "rb"))
existing_pdf.decrypt('')
output = PdfFileWriter()
# add the "watermark" (which is the new pdf) on the existing page
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
#write "output" to a real file
outputStream = open("destination.pdf", "wb")
output.write(outputStream)
outputStream.close()
#open pdf file
opener ="open" if sys.platform == "darwin"else "xdg-open"
subprocess.call([opener, "destination.pdf"])
我尝试更改 Arial、Times New Roman、Cambria 等字体,但它只接受 Helvetica 并且文本大小和字体没有改变。
解决方案
推荐阅读
- c - 函数中的变量输入类型
- python - 如何获取 Keras 模型所有层的输出?
- python - 如何在python中按字符串中的特定单词对行进行分组
- python - 如何在 python 中调用我网站上的 php 脚本?
- python - 将 hive 表卸载到。使用 Spark 或 pyspark 或 python 的 dat 文件
- python - 矩阵的平均值乘以标量向量
- python - Google App Engine:每天自动重新部署一次以更新机器学习模型?
- java - 如何从另一个类中调用同名方法?
- android - Material Component FloatingActionButton 中的 shapeAppearance 导致崩溃
- python - Tensorflow Gradient Tape 返回无