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文件,其中每個圖片位於不同的頁面。

  • 匯入必要的模組:FPDF 來建立PDF檔案,Image 從 PIL 來處理圖片,以及 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 Iron Suite
預約您的免費即時演示
Booking Badge

全球數百萬工程師的信賴

Iron Software的客戶標誌
獲取您的無義務諮詢
填寫以下表格或發送電子郵件至sales@ironsoftware.com
您的詳細資訊將始終保密。
全球數百萬工程師的信賴
Iron Software的客戶標誌
立即獲取您的30天試用金鑰。
無需信用卡或帳戶建立
PDF的Python模塊下載
使用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起的授權