# [Tool Summary] img2pdf: Lossless Image-to-PDF Conversion Utility > `img2pdf` is one of the fastest and most efficient tools for converting images to PDF in a Linux environment. It's optimized for merging multiple images into a single PDF document or converting a single image, and it's Python-based. In this post, I'd like to introduce a tool I occasionally use and consistently find myself thinking, "This is truly excellent." Its overwhelming speed, Linux-native lightness, and seamless integration with pipes make it a favorite. ![Visualizing the image to PDF conversion process](/media/whitedec/blog_img/2ab5b1e13c8247bc98d6174c12c0c5c2.webp) ## 1. Working Principle {#sec-f8af2ee385bf} Its most significant feature is **'No Re-encoding'** during the merge process. * **Traditional Methods (e.g., ImageMagick):** These methods read image files, analyze pixel data, and then recompress them (lossily) to fit the PDF format. This process can be CPU-intensive and may lead to a reduction in image quality. * **img2pdf Method:** It directly embeds the binary data of the image files **as-is (Lossless)** into the PDF container. * **Advantages:** Offers overwhelmingly fast conversion speeds, preserves 100% of the original image quality, and results in efficient file sizes. ## 2. Installation & Removal {#sec-aa068551b507} ### Installation (Ubuntu/Debian based) {#sec-0dfc74ad579f} ```bash sudo apt update sudo apt install img2pdf ``` ### Removal {#sec-17fc6056a949} ```bash # Remove only the program sudo apt remove img2pdf # Remove configuration files and dependencies cleanly sudo apt purge img2pdf sudo apt autoremove ``` --- ## 3. Usage Guide {#sec-02dae59f6008} ### Basic Merging {#sec-002951a3397c} Use this to combine all PNG files in the current directory into a single PDF. ```bash img2pdf *.png -o output.pdf ``` ### Merging in a Specific Order {#sec-3136d0efa9f4} You can specify the order by listing filenames directly. ```bash img2pdf image1.png image2.png image3.png -o output.pdf ``` ### Setting Page Size and Margins (Advanced) {#sec-8dfce1207c34} This is useful when you want to fit images to a specific standard (e.g., A4) or add margins. ```bash # Fit image size to A4 and add 2cm border img2pdf --pagesize A4 --border 2cm *.png -o output.pdf ``` ### Specifying a Custom Resolution (DPI) {#sec-231f83e819d7} Use this when you want to force a specific output resolution for your images. ```bash img2pdf --dpi 300 *.png -o output.pdf ``` --- ## 4. Developer's Note {#sec-34c448091f29} * **Sorting Issue:** The wildcard (`*`) in the Linux terminal recognizes numbers as strings. * Example: Files might be merged in the order of `1.png`, `10.png`, `2.png`. * **Solution:** The safest approach is to save filenames with consistent padding, such as `01.png`, `02.png` ... `10.png`. * **Leveraging Pipes:** It goes without saying that pipe utilization is one of Linux's most convenient features. You can take the output of other commands and instantly create a PDF. ```bash find . -name "*.png" | sort | xargs img2pdf -o output.pdf ``` --- > **One-line Summary:** "The best tool for creating PDFs without quality loss, at maximum speed, in a truly Linux-native way."