IRONSOFTWAREHOME
图片转PDF
from ironpdf import *

# One or more images as a list. This example selects all JPEG images in a specific 'assets' folder.
image_files = [os.path.join("assets", f) for f in os.listdir("assets") if f.lower().endswith(('.jpg', '.jpeg'))]

directory_list = List[str]()
for i in range(len(image_files)):
    directory_list.Add(image_files[i])

# Converts the images to a PDF and save it.
ImageToPdfConverter.ImageToPdf(directory_list).SaveAs("composite.pdf")

# Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails
pip install ironpdf
图片转PDF

图片转PDF

ImageToPdfConverter类从图像创建PDF文档。

使用指向一个有效图像文件路径的ImageToPdfConverter.ImageToPdf函数调用来生成包含该图像的新PDF文档。

使用图像路径列表调用ImageToPdfConverter.ImageToPdf将生成包含每个图像的单个PDF文档,每个图像都在不同的页面上。

  • 导入必要模块:用于创建PDF文件的os
  • image_to_pdf方法接收一个或多个图像路径并将其转换为PDF文件,保存到指定的输出路径。
  • 图像转换为RGB以确保兼容性。
  • 使用临时文件保持图像格式的一致性。
  • 该方法可以无缝处理单个图像路径和图像路径列表。
了解如何使用 IronPDF 将 PDF 转换为图像
在 GitHub 上查看

准备开始了吗?

版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

OR
bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户
Python 模块下载 PDF
using pip 安装

版本: 2026.9

  1. 下载 并安装 Python 3.7+。
  2. 如果尚未安装,请从 pypi.org 安装 pip
  3. 在终端中执行上述命令。
Python PDF 模块
下载 模块

版本: 2026.9

手动安装到您的项目中

  1. 下载软件包
  2. 在终端中运行此命令
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

$999