在python中将单个pdf中的多个png组合在一起 [英] Combining multiple pngs in a single pdf in python

查看:172
本文介绍了在python中将单个pdf中的多个png组合在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am wondering if there is an easy way to combine multiple png images into a single pdf in python. I want each image to be a single page in the pdf. Is pypdf the best library to use for this? Any help would be greatly appreciated.

谢谢!

推荐答案

我我遇到了同样的问题。

I've got the same problem.

所以我创建了python函数来将多张图片合并为一个pdf。
码可在我的GitHub的页面上 https://开头github上。 COM / wizard1989 /团结,多图片 - 到 - PDF
它使用reportlab。

So I've created python function to unite multiple pictures in one pdf. Code is available at my github page on https://github.com/wizard1989/Unite-multiple-pictures-into-pdf. It uses "reportlab".

代码基于以下链接的答案:

从图像列表中创建PDF

Combining在单个PDF多个PNG图像在python 结果,
< href =https://stackoverflow.com/questions/40906463/png-images-to-one-pdf-in-python> png图像到python中的一个pdf

我怎么能转换文件夹中的所有JPG文件都是PDF并将它们组合起来?
https://www.blog.pythonlibrary.org/2012/01/07/reportlab-converting-hundreds-of-images-into-pdfs/

Code is based on answers from the following links:
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的示例。

Here is example of how to unite images into pdf.

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

We have folder "D:\pictures" with pictures of types png and jpg. We want to create file pdf_with_pictures.pdf out of them and save it in the same folder.

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)

这篇关于在python中将单个pdf中的多个png组合在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆