← 返回命令列表

Linux command

img2pdf 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Convert images to PDF

img2pdf [image1.jpg] [image2.png] -o [output.pdf]

Convert all images in directory

img2pdf [*.jpg] -o [output.pdf]

Set page size to A4

img2pdf --pagesize [A4] [image.jpg] -o [output.pdf]

Fit image to page

img2pdf --fit [into] --pagesize [A4] [image.jpg] -o [output.pdf]

Set specific image size

img2pdf --imgsize [150mmx100mm] [image.jpg] -o [output.pdf]

Convert with custom page margins

img2pdf --border [1cm:1cm] [image.jpg] -o [output.pdf]

Set PDF title and author

img2pdf --title "[Document Title]" --author "[Author Name]" [image.jpg] -o [output.pdf]

Output a PDF/A-1b compliant document

img2pdf --pdfa [image.jpg] -o [output.pdf]

Pipe image from stdin

cat [image.jpg] | img2pdf -o [output.pdf]

说明

img2pdf converts images to PDF without re-encoding, preserving the original image quality. Unlike tools that rasterize images, img2pdf embeds the original JPEG, PNG, TIFF, or other image data directly into the PDF structure. This lossless approach means a 5MB JPEG becomes approximately a 5MB PDF (plus minimal PDF overhead), with no quality loss. Re-encoding tools would either lose quality or produce much larger files at equivalent quality. Supported input formats include JPEG, JPEG2000, PNG (including transparency), TIFF, GIF, and others. The tool automatically handles colorspace, bit depth, and multi-page TIFFs. Page sizing offers flexible options: natural image size (at specified DPI), fixed page sizes with fit modes, or explicit dimensions. The fit modes control how images are placed: into fits inside the page, fill fills the page (may crop), exact stretches to exact size, shrink only shrinks larger images, enlarge only enlarges smaller images. Multiple images become multi-page PDFs in argument order. Piping from stdin enables integration with image processing pipelines.

参数

-o, --output _file_
Output PDF file (required).
--pagesize _size_
Page size: A4, Letter, Legal, or WxH (e.g., 210mmx297mm).
--imgsize _LxL_
Image size on the PDF page: WxH with units (e.g., 150mmx100mm).
--fit _mode_
Fit mode: into, fill, exact, shrink, enlarge.
--border _margin_
Page borders/margins (e.g., 1cm, 1cm:2cm).
--rotation _angle_
Rotate pages: auto, none, ifvalid, 0, 90, 180, 270.
--title _string_
PDF title metadata.
--author _string_
PDF author metadata.
--subject _string_
PDF subject metadata.
--keywords _string_
PDF keywords metadata.
--creationdate _date_
PDF creation date.
--moddate _date_
PDF modification date.
--viewer-panes _panes_
Initial viewer panes: outlines, thumbs.
--viewer-initial-page _n_
Initial page to display.
--viewer-fullscreen
Open in fullscreen mode.
-D, --nodate
Suppress timestamps for deterministic output.
-S, --colorspace _space_
Force colorspace: RGB, L (grayscale).
-a, --auto-orient
Match page orientation to input image.
--pdfa
Output a PDF/A-1b compliant document.
--first-frame-only
Convert only the first frame of multi-frame images (e.g., animated GIF, multi-page TIFF).
--pillow-limit-break
Disable Pillow's decompression bomb size limit for very large images.
--from-file _FILE_
Read list of input images from FILE (NUL-separated paths).
-v, --verbose
Enable verbose mode, printing messages on standard error.

FAQ

What is the img2pdf command used for?

img2pdf converts images to PDF without re-encoding, preserving the original image quality. Unlike tools that rasterize images, img2pdf embeds the original JPEG, PNG, TIFF, or other image data directly into the PDF structure. This lossless approach means a 5MB JPEG becomes approximately a 5MB PDF (plus minimal PDF overhead), with no quality loss. Re-encoding tools would either lose quality or produce much larger files at equivalent quality. Supported input formats include JPEG, JPEG2000, PNG (including transparency), TIFF, GIF, and others. The tool automatically handles colorspace, bit depth, and multi-page TIFFs. Page sizing offers flexible options: natural image size (at specified DPI), fixed page sizes with fit modes, or explicit dimensions. The fit modes control how images are placed: into fits inside the page, fill fills the page (may crop), exact stretches to exact size, shrink only shrinks larger images, enlarge only enlarges smaller images. Multiple images become multi-page PDFs in argument order. Piping from stdin enables integration with image processing pipelines.

How do I run a basic img2pdf example?

Run `img2pdf [image1.jpg] [image2.png] -o [output.pdf]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o, --output _file_ do in img2pdf?

Output PDF file (required).