TIFF to PDF with Multi-Page Support

IronPDF for Python's ImageToPdfConverter class supports the conversion of TIFF files into PDF documents. When using ImagePdfConverter.ImageToPdf with a TIFF containing multiple frames, it will place each frame of the TIFF on separate pages.

Here is an example of how you can use the ImageToPdfConverter to convert a multi-frame TIFF image into a PDF document:

# Import the PdfDocument module from the IronPdf package
from ironpdf import PdfDocument, ImageToPdfConverter

def convert_tiff_to_pdf(tiff_path: str, pdf_output_path: str):
    """
    Converts a multi-frame TIFF file to a PDF document.

    :param tiff_path: Path to the TIFF file that needs to be converted.
    :param pdf_output_path: Path where the output PDF should be saved.
    """
    # Instantiate the ImageToPdfConverter
    converter = ImageToPdfConverter()

    # Convert the TIFF file to a PDF document
    # Each frame in the TIFF file will be placed on a separate page in the PDF
    pdf_document = converter.image_to_pdf(tiff_path)

    # Save the resulting PDF document to the specified output path
    pdf_document.save(pdf_output_path)

# Example usage
tiff_file_path = 'path/to/your/tiff_file.tiff'
output_pdf_path = 'path/to/output/pdf_document.pdf'

# Convert the TIFF file to a PDF document
convert_tiff_to_pdf(tiff_file_path, output_pdf_path)
# Import the PdfDocument module from the IronPdf package
from ironpdf import PdfDocument, ImageToPdfConverter

def convert_tiff_to_pdf(tiff_path: str, pdf_output_path: str):
    """
    Converts a multi-frame TIFF file to a PDF document.

    :param tiff_path: Path to the TIFF file that needs to be converted.
    :param pdf_output_path: Path where the output PDF should be saved.
    """
    # Instantiate the ImageToPdfConverter
    converter = ImageToPdfConverter()

    # Convert the TIFF file to a PDF document
    # Each frame in the TIFF file will be placed on a separate page in the PDF
    pdf_document = converter.image_to_pdf(tiff_path)

    # Save the resulting PDF document to the specified output path
    pdf_document.save(pdf_output_path)

# Example usage
tiff_file_path = 'path/to/your/tiff_file.tiff'
output_pdf_path = 'path/to/output/pdf_document.pdf'

# Convert the TIFF file to a PDF document
convert_tiff_to_pdf(tiff_file_path, output_pdf_path)
PYTHON

Explanation of the Code

  1. Importing Modules:

    • PdfDocument and ImageToPdfConverter are imported from the ironpdf package to handle the PDF conversion.
  2. 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).
  3. ImageToPdfConverter Instance:

    • An instance of ImageToPdfConverter is created to utilize its image_to_pdf method for conversion.
  4. PDF Conversion:

    • The method image_to_pdf(tiff_path) converts the multi-frame TIFF by placing each frame on a separate page in the resulting PDF.
  5. Saving the PDF:
    • The converted PDF is saved using the save method of the PdfDocument class at the specified path.

Replace 'path/to/your/tiff_file.tiff' and 'path/to/output/pdf_document.pdf' with your actual file paths to perform the conversion.