Merge TIFF to PDF via Python

Merge TIFF documents into single formats PDF. Use Aspose.PDF for Python for .NET to modify files programmatically

Merge TIFF to PDF using Python

How to merge TIFF to PDF? With Aspose.PDF for Python via .NET library you can merge TIFF to PDF programmatically. PDF software from Aspose is ideal for individuals, small or large businesses. Since it is able to process a large amount of information, perform the concatenation quickly and efficiently and protect your data. A peculiar feature from Aspose.PDF is an API for merging TIFF to PDF. The trait of this approach is that you only need to open the NuGet package manager, search for ‘Aspose.PDF for .NET’, and install it without any special complex settings. (Use the command from the Package Manager Console for installing). Check the details of Installing the Library on the Documentation pages. To verify the benefits of the library, try using the conversion TIFF to PDF code snippet.

Console

pip install aspose-pdf

How to merge TIFF to PDF via Python


Python for .NET developers can easily load & merge TIFF files to PDF in just a few lines of code.

  1. Import necessary Python modules: aspose.pdf as apdf for PDF document handling, FileIO from io for reading files, and path from os for file path operations.
  2. Create a list of file streams by opening each input file in read-binary mode. Each file’s path is located using the data directory name combined with its filename. This allows reading individual files from the data directory into separate streams for image processing.
  3. Define the output file path by joining the output directory and the desired output filename. This ensures that the final merged document is saved in the correct location.
  4. Use the apfacades.PdfConverter.merge_images() function to merge input images into a single image. The function accepts parameters such as input streams, output format (TIFF), merge mode (centered positioning), and layout dimensions (2 columns by 2 rows). This step combines multiple images into one.
  5. Initialize an empty PDF document using apdf.Document(). This is where the merged image will be added as a page or element within the final document.
  6. Create a new page and add the merged image to this page within a specified rectangular area (595x842 pixels). This step inserts the merged image into a specific location on each page of the PDF document.
  7. Save the final PDF document with all pages and elements, including the merged image. The save operation writes the document to the previously defined output file path.
  8. Print a confirmation message showing how many images were merged into the output file. This helps verify that the processing was completed successfully and all input files have been included in the final document.

Here is an example that demonstrates how to merge TIFF to PDF in Python. Combine multiple documents into a single file with ease. If you are developing code in Python, this task can be simpler than it sounds. You can use fully qualified filenames for both TIFF reading and PDF writing. Check out this Python example that show how to merge multiple documents of either the same or different file types into one file using Python

Merge TIFF files using Python for .NET and save as PDF

Example Python: this sample code shows TIFF to PDF concatenation

Input file:

File not added

File not added

Output format:

PDF

Output file:

import aspose.pdf as apdf

from io import FileIO
from os import path
infiles_streams = [
    FileIO(path.join(self.data_dir, infile), "rb") for infile in infiles
]
path_outfile = path.join(self.data_dir, outfile)

image = apfacades.PdfConverter.merge_images(
    input_images_streams=infiles_streams,
    output_image_format=apdfdrw.ImageFormat.TIFF,
    merge_mode=apfacades.ImageMergeMode.CENTER,
    horizontal=2,
    vertical=2,
)
document = apdf.Document()
page = document.pages.add()
rectangle = apdf.Rectangle(0, 0, 595, 842, True)
page.add_image(image_stream=image, image_rect=rectangle, bbox=rectangle)
document.save(path_outfile)

print(str(infiles) + " merged into " + outfile)

API for Python to combine TIFF into PDF

Aspose.PDF for Python via .NET API supports most established PDF standards and PDF specifications. It allows developers to insert tables, graphs, images, hyperlinks, custom fonts - and more - into PDF documents. Moreover, it is also possible to compress PDF documents. Aspose.PDF for Python via .NET provides excellent security features to develop secure PDF documents. Some of the key features of Aspose.PDF for Python via .NET API include:

  • Ability to read & export PDF in multiple image formats including BMP, GIF, JPEG & PNG.
  • Set basic information (e.g. author, creator) of the PDF document.
  • Conversion Features: Convert PDF to Word, Excel, and PowerPoint. Convert PDF to Images formats. Convert PDF file to HTML format and vice versa. Convert PDF to EPUB, Text, XPS, etc.

You can find more information about Aspose.PDF for Python via .NET API on our documentation on how to use API.