在Python中创建和写入pdf文件

编程入门 行业动态 更新时间:2024-10-25 07:26:02
本文介绍了在Python中创建和写入pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为什么不行:

with open('file.pdf', 'w') as outfile: outfile.write("Hello")

该代码可以正常工作,但是无法打开.pdf文件.普通文本文件和pdf有什么区别? 如果我想在python中创建并写入pdf文件怎么办?

The code works fine, but the .pdf file cannot be opened. What's the difference between a normal text file and pdf? What to do if I want to create and write to a pdf file in python?

推荐答案

您可以安装fpdf库,然后:

you could install the fpdf library and then:

from fpdf import FPDF pdf = FPDF() pdf.add_page() pdf.set_xy(0, 0) pdf.set_font('arial', 'B', 13.0) pdf.cell(ln=0, h=5.0, align='L', w=0, txt="Hello", border=0) pdf.output('test.pdf', 'F')

更多推荐

在Python中创建和写入pdf文件

本文发布于:2023-10-31 01:46:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:建和   中创   文件   Python   pdf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!