【发布时间】:2017-06-25 19:52:51
【问题描述】:
所以下面的代码将图像添加到 PDF 中
def __create(self):
if len(self.__DLImages) == 0:
raise Exception("No images to add to PDF")
else:
maxWidth = max([Image.open(imgPath).size[0] for imgPath in self.__DLImages])
maxHeight = max([Image.open(imgPath).size[1] for imgPath in self.__DLImages])
PDF = FPDF(unit = "pt", format = (maxWidth, maxHeight))
for imgPath in self.__DLImages:
PDF.add_page()
PDF.image(imgPath, x = self.__margin, y = self.__margin)
PDF.output(self.__outputFile)
但我必须将高度和宽度设置为最大尺寸,以便图像适合,从而导致较小的图像周围有巨大的空间。
文档说我可以在图像Link 上设置宽度和高度,但是当我没有做任何更改时,因为我已经设置了页面的尺寸(我必须这样做以使其适合),否则默认为 A4
它还说我可以更改页面的尺寸Link,但是在查看源代码之后,add_page() 方法除了orientation 之外不采用任何其他参数这不是这个答案所暗示的@987654323 @
【问题讨论】: