python 使用fpdf中的write不能实现自动换行,而multi_cell可以实现自动换行,具体看下面的代码

# Import FPDF class
from fpdf import FPDF# Create instance of FPDF class
# Letter size paper, use inches as unit of measure
pdf=FPDF(format='letter', unit='in')# Add new page. Without this you cannot create the document.
pdf.add_page()# Remember to always put one of these at least once.
pdf.set_font('Times','',10.0) # Long meaningless piece of text
loremipsum = """Lorem ipsum dolor sit amet, vel ne quando dissentias. \
Ne his oporteat expetendis. Ei tantas explicari quo, sea vidit minimum \
menandri ea. His case errem dicam ex, mel eruditi tibique delicatissimi \
ut. At mea wisi dolorum contentiones, in malis vitae viderer mel.Vis at dolores ocurreret splendide. Noster dolorum repudiare vis ei, te \
augue summo vis. An vim quas torquatos, electram posidonium eam ea, eros \
blandit ea vel. Reque summo assueverit an sit. Sed nibh conceptam cu, pro \
in graeci ancillae constituto, eam eu oratio soleat instructior. No deleniti \
quaerendum vim, assum saepe munere ea vis, te tale tempor sit. An sed debet \
ocurreret adversarium, ne enim docendi mandamus sea.
"""effective_page_width = pdf.w - 2*pdf.l_marginpdf.set_font('Times','B',10.0)
pdf.cell(1.0,0.0, 'Without multi_cell using effective page width:')
pdf.ln(0.25)
pdf.set_font('Times','',10.0)
# Cell is as wide as the effective page width
pdf.cell(effective_page_width, 0.0, loremipsum)
pdf.ln(0.5)
pdf.set_font('Times','B',10.0)
pdf.cell(1.0,0.0, 'Using multi_cell and effective page width:')
pdf.ln(0.25)pdf.set_font('Times','',10.0)
# Cell is as wide as the effective page width
# and multi_cell requires declaring the height of the cell.
pdf.multi_cell(effective_page_width, 0.15, loremipsum)
pdf.ln(0.5)# Cell half as wide as the effective page width
# and multi_cell requires declaring the height of the cell.
pdf.set_font('Times','B',10.0)
pdf.cell(1.0,0.0, 'Using multi_cell and half the effective page width:')
pdf.ln(0.25)pdf.set_font('Times','',10.0)
pdf.multi_cell(effective_page_width/2, 0.15, loremipsum)
pdf.ln(0.5)pdf.output('multi_cell.pdf','F')


这篇文章是否对你有帮助,如果有帮助愿意请博主喝杯咖啡哈

python fpdf中multi_cell实现自动换行相关推荐

  1. python使用fpdf的multi_cell API实现长文本写入的自动换行功能实战

    python使用fpdf的multi_cell API实现长文本写入的自动换行功能实战 目录 python使用fpdf的multi_cell API实现长文本写入的自动换行功能实战

  2. python调用什么函数实现对文件内容的读取_如何使用python语言中的方法对文件进行读写操作...

    在我们使用python语言中的文件时,可以使用open()方法打开文件,close()方法关闭文件,read()方法读取文件内容,write()方法写入内容到文件中.下面利用几个实例说明文件读写方法, ...

  3. python图像中如何显示中文

    python图像中如何显示中文 在开头加入这两行即可 from pylab import * mpl.rcParams['font.sans-serif'] = ['SimHei']

  4. 关于python缩进的描述中_关于Python程序中与“缩进”有关的说法中,以下选项中正确的是()...

    关于Python程序中与"缩进"有关的说法中,以下选项中正确的是() 答:缩进在程序中长度统一且强制使用 同文学或同音乐主题的民歌,<_______>是其中之一.此曲经 ...

  5. python 类中定义类_Python中的动态类定义

    python 类中定义类 Here's a neat Python trick you might just find useful one day. Let's look at how you ca ...

  6. Python培训分享:Python新版本中的6个新特性

    Python在几年做了一个全面的升级,此次Python升级中有6个新特性,本期小编为大家介绍的Python培训教程就是关于介绍Python新版本中的6个新特性的,来看看下面的详细介绍. Python培 ...

  7. Python培训常识:Python面试中常被问到的几种设计模式要知道

    学习Python技术大家都是为了日后能够找到适合自己的工作岗位,那么除了要学习好Python技术外,对于面试环节的问题也要有所了解,本期小编为大家介绍的Python培训教程就算关于Python面试中常 ...

  8. python语言中如何使用注释

    每一种计算机语言都有自己的注释方式,我们知道注释的作用是解释这些代码,方便程序员以后的检查和修改.而且注释的一部分在运行程序的过程中不起作用,也不会显示出来.下面我们将为大家介绍,在python语言中 ...

  9. arcgis里python窗口运行,在 Python 窗口中执行工具

    当第一次打开 Python 窗口时,它会显示类似这样的界面: 左侧区域为 Python 的主提示窗口,在这里执行 Python 命令.右侧区域为帮助和语法窗口,工具运行时,在这里显示执行消息:输入代码 ...

最新文章

  1. CPU/GPU/TPU/NPU...XPU都是什么意思?
  2. iOS 不同机型屏幕适配
  3. [Codeforces50C]Happy Farm 5 凸包
  4. linux中jpg文件,Linux下压缩和优化jpg与png图片的方法
  5. mysql的innodb表生成的物理文件_MySQL innodb表使用表空间物理文件复制或迁移表
  6. 鸿蒙系统平板界面,华为鸿蒙系统界面首次曝光!首款预装鸿蒙设备正式入网:发布在即...
  7. Navicat工具获取操作数据库和表的SQL语句
  8. DefaultNetworkCredentials vs DefaultCredentials
  9. 黑客攻防技术宝典web实战篇:利用信息泄露习题
  10. 转 @PathVariable是什么?详情及用法解析
  11. Respo 首屏 DOM 更新的方案, CSS 动画的 Demo
  12. vue3中获取dom元素和操作
  13. python读取nc出图_python读取nc文件
  14. 【已解决】java int转byte出现负数
  15. 【全套资料.zip下载】数电课设-色子骰子模拟电路Multisim仿真设计【Multisim仿真+报告+讲解视频.zip下载】
  16. 模2除法——用非常直观的例子解释
  17. Java 在Word指定段落/文本位置插入分页符
  18. 利用excel生成word,批量插入图片、题注、标题等格式
  19. 三阶魔方大中小魔公式_三阶魔方花样玩法 公式汇总大全
  20. Hibernate手动控制事物

热门文章

  1. 【MySQL】 insert into语句几种方式
  2. ardupilot/arduplane/attitude.cpp 姿态控制解析
  3. jmeter(二十):Logic Controller:逻辑控制器(上)
  4. 以太网 TCP协议交互过程中出现丢包时的解决机制,超时重传、快速重传、SACK与DSACK
  5. Spark中cache、persist、checkpoint区别
  6. 用Matlab进行快速傅里叶变换
  7. python 数字转换成汉字,Python实现把数字转换成中文
  8. js实现鼠标跟随效果
  9. 宏碁笔记本u盘装系统如何进入bios设置u盘启动图文教程
  10. android studio抛出,Android Studio升级到3.0,抛出Aapt2Exception异常