FPDF在Python中产生空白页
我编写了Python脚本,该脚本将基于带有JPEG的文件夹生成PDF.没什么好看的:
I wrote Python script that will produce PDFs based on folders with JPEGs. Nothing fancy:
import os
from fpdf import FPDF
folders = [ ... here are numbers - folders are numbered ... ]
for folder in folders:
pdf = FPDF()
for fil in os.scandir("parent folder" + str(folder) + "/"):
pdf.add_page()
pdf.image(fil.path, w=210, h=297)
pdf.output("target location/" + str(folder) + ".pdf", "F")
但是,此代码导致PDF中的每隔一页为空白.有趣的是,这段代码:
This code however results in PDF having every other page blank. Interestingly enough this code:
import os
from fpdf import FPDF
folders = [ ... here are numbers - folders are numbered ... ]
for folder in folders:
pdf = FPDF()
pdf.add_page()
for fil in os.scandir("parent folder" + str(folder) + "/"):
pdf.image(fil.path, w=210, h=297)
pdf.output("target location/" + str(folder) + ".pdf", "F")
产生的文件首页空白,其余部分正确.
produces file with empty first page and the rest is correct.
我没有看到明显的解决方案-看起来有点像fpdf库.还是不是?
I don't see obvious fix for this - looks a bit like a fpdf library. Or is it not?
请尝试在fpdf中禁用自动分页符模式.为此,请致电set_auto_page_break(0)
.
我遇到了这个问题,这是我的解决方案.希望对您有帮助!
Please try by disabling automatic page break mode in fpdf. To do this, please call set_auto_page_break(0)
.
I faced this problem and this was my solution. Hope it helps!
from fpdf import FPDF
pdf = FPDF()
pdf.set_auto_page_break(0)
有关更多信息,请查阅最新文档: http://pyfpdf.readthedocs.io/en/latest/reference/set_auto_page_break/
For more information, please consult the latest documentation: http://pyfpdf.readthedocs.io/en/latest/reference/set_auto_page_break/