[英]Page breaks for images in Python fpdf
I want to insert some lengthy images (each image can extend to 2 pages) using python fpdf. 我想使用python fpdf插入一些冗长的图像(每个图像可以扩展到2页)。 But the images don't continue to next page once a page break is triggered.
但是一旦触发分页符,图像就不会继续到下一页。 How can I print the rest of the images into the next page starting from a given set_y value (header included)?
如何从给定的set_y值(包括标题)开始将其余图像打印到下一页?
Although I believe there is a way with fpdf
, I suggest you switch to pdfkit / wkhtmltopdf based solution. 虽然我相信这是一个办法
fpdf
,我建议你改用pdfkit / wkhtmltopdf基础的解决方案。
I have many similar issues with reportlab
, which is very like fpdf
, then switched to wkhtmltopdf, feels much better. 我有很多类似的问题
reportlab
,这是非常喜欢fpdf
,然后切换到wkhtmltopdf,感觉好多了。
With wkhtmltopdf, you could control layout with standard web stack, use CSS and javascript, use a favorite template engine, then convert HTML file to pdf, easier and much more powerful. 使用wkhtmltopdf,您可以使用标准Web堆栈控制布局,使用CSS和javascript,使用喜欢的模板引擎,然后将HTML文件转换为pdf,更轻松,功能更强大。
Just an example of my above comment, 只是我上面评论的一个例子,
from fpdf import FPDF
from PIL import Image
pdf = FPDF()
pdf.add_page()
im = Image.open('1.jpg')
width_img, height_img = im.size
#mm = (pixels * 25.4) / dpi
# - 25.4 millimeters in an inch
w = (width_img*25.4)/300
h = (height_img*25.4)/300
pdf.image('1.jpg',0,0,w,h)
pdf.output("yourfile.pdf", "F")
If your pdf-dataset is a data string you can start searching for the " \\r
" and/or (multiple) ' \\n
' character(s) using the below code: 如果您的pdf数据集是一个数据字符串,则可以使用以下代码开始搜索“
\\r
”和/或(多个)“ \\n
”字符:
chrs = ['\r', '\n', '\n\n']
for item in chars:
pdf-data.replace(item)
In case its formatted strings in a list: 如果其格式字符串在列表中:
list = pdaf-data
for list-item in list:
for list-item in chars:
pdf-data.replace(item)
In case you read directly from a file use "open file, etc" and readline()
. 如果您直接从文件读取,请使用“打开文件等”和
readline()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.