因此下面的代码将图像添加到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
之外不会采用任何其他参数不是这个答案所暗示的Link
答案 0 :(得分:1)
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags always come first -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
</head>
<body>
<p id="demo"></p>
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML =
this.responseText;
console.log("Up to this line works.");
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
</script>
</body>
</html>
我找到了一个新模块并完成了这个解决方案