python - 在python中将多个png组合成一个pdf

我想知道是否有一种简单的方法可以在 python 中将多个 png 图像组合成一个 pdf。我希望每张图片都是 pdf 中的一页。 pypdf 是用于此的最佳库吗?任何帮助将不胜感激。

谢谢!

最佳答案

我也遇到了同样的问题。

所以我创建了 python 函数来将多张图片合并到一个 pdf 中。 代码可在我的 github 页面上找到 https://github.com/wizard1989/Unite-multiple-pictures-into-pdf . 它使用“reportlab”。

代码基于以下链接的答案:
Create PDF from a list of images
Combining multiple pngs in a single pdf in python
png images to one pdf in python
How can I convert all JPG files in a folder to PDFs and combine them? https://www.blog.pythonlibrary.org/2012/01/07/reportlab-converting-hundreds-of-images-into-pdfs/

这里是如何将图像合并为 pdf 的示例。

我们有文件夹“D:\pictures”,其中包含 png 和 jpg 类型的图片。 我们想从中创建文件 pdf_with_pictures.pdf 并将其保存在同一文件夹中。

outputPdfName = "pdf_with_pictures"
pathToSavePdfTo = "D:\\pictures"
pathToPictures = "D:\\pictures"
splitType = "none"
numberOfEntitiesInOnePdf = 1
listWithImagesExtensions = ["png", "jpg"]
picturesAreInRootFolder = True
nameOfPart = "volume"

unite_pictures_into_pdf(outputPdfName, pathToSavePdfTo, pathToPictures, splitType, numberOfEntitiesInOnePdf, listWithImagesExtensions, picturesAreInRootFolder, nameOfPart)

https://stackoverflow.com/questions/30154846/

相关文章:

unity3d - 团结 |查找具有指定父对象的子游戏对象

java - 有没有办法清除JAVA中对象的所有字段?

ruby-on-rails - 使用 Rails 将带连字符的单词的两个部分都大写

spring-mongo - Spring Mongo 从 json 字符串转换为文档

git - 我如何将 openshift git 存储库连接到 bitbucket

opengl-es - 使用具有多个颜色纹理附件的 FrameBufferObject

google-api - YouTube API 直播

r - 加载 Data.Table 后遮盖的润滑对象

php - 第 2 行超出范围 (2 - 1) laravel-excel

r - 如何在函数 rowsum 中使用 'group' 参数