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)
Explanation of the Code
Importing Modules:
PdfDocument
andImageToPdfConverter
are imported from theironpdf
package 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
ImageToPdfConverter Instance:
- An instance of
ImageToPdfConverter
is created to utilize itsimage_to_pdf
method for conversion.
- An instance of
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.
- The method
- Saving the PDF:
- The converted PDF is saved using the
save
method of thePdfDocument
class at the specified path.
- The converted PDF is saved using the
Replace 'path/to/your/tiff_file.tiff'
and 'path/to/output/pdf_document.pdf'
with your actual file paths to perform the conversion.