支持多頁的 TIFF 到 PDF
IronPDF for Python 的 ImageToPdfConverter 類別支援將 TIFF 檔案轉換為 PDF 文件。 當使用 ImagePdfConverter.ImageToPdf 處理包含多個訊框的 TIFF 檔案時,它會將 TIFF 檔案的每個影格放置在單獨的頁面上。
以下範例展示如何使用 ImageToPdfConverter 將多幀 TIFF 影像轉換為 PDF 文件:
程式碼說明
1.導入模組:
PdfDocumentandImageToPdfConverterare imported from theironpdfpackage to handle the PDF conversion.
- Function
convert_tiff_to_pdf(tiff_path: str, pdf_output_path: str):- This function takes a TIFF file (via
tiff_path) and converts it into a PDF document, saving it to the specified path (pdf_output_path).
- This function takes a TIFF file (via
3.ImageToPdfConverter實例:
- An instance of
ImageToPdfConverteris created to utilize itsimage_to_pdfmethod for conversion.
- PDF轉換:
- The method
image_to_pdf(tiff_path)converts the multi-frame TIFF by placing each frame on a separate page in the resulting PDF.
- The method
5.保存 PDF 檔:
- The converted PDF is saved using the
savemethod of thePdfDocumentclass at the specified path.
將 'path/to/your/tiff_file.tiff' 和 'path/to/output/pdf_document.pdf' 替換為您的實際檔案路徑以執行轉換。






