Image to PDF Command line Examples
Use these command-line examples for common Image to PDF tasks. See the CLI guide for installation, input and output handling, and diagnostics.
You can run the examples below without account setup. The CLI uses demo credentials unless you have configured your own API credentials. Update the input URLs and filenames as needed.
Commands use POSIX-shell syntax, as in Bash or Zsh, and save results in the current directory.
Basic examples
These commands save the result with --output. See Handle the Result for output choices and failure handling.
Convert a file
Upload an existing logo.png file.
image2pdf --output logo.pdf \ logo.png
Convert a URL
image2pdf --output logo.pdf \ https://your-server.com/logo.png
Read bytes from stdin
Read logo.png through stdin. Use the same - input for bytes piped from another program.
image2pdf --output logo.pdf \ - < logo.png
Customize the PDF
These examples use scan.png, a 1224 × 1584 pixel image with text, a chart, and a uniform white border. The rotation example uses its sideways variant, scan-sideways.png.
Fit an image onto paper
Fit the whole image onto A4 portrait or Letter landscape paper with 12mm margins and 150 DPI. The fit mode preserves the image's aspect ratio. Setting a page size without it can clip a larger image.
A4 portrait
image2pdf --dpi=150 \ --margin-bottom=12mm \ --margin-left=12mm \ --margin-right=12mm \ --margin-top=12mm \ --page-size=A4 \ --print-page-mode=fit \ --output a4.pdf \ scan.png
Letter landscape
image2pdf --dpi=150 \ --margin-bottom=12mm \ --margin-left=12mm \ --margin-right=12mm \ --margin-top=12mm \ --orientation=landscape \ --page-size=Letter \ --print-page-mode=fit \ --output landscape.pdf \ scan.png
Create a custom-size PDF
Fit scan.png onto a 4 × 6 inch page and save custom-page.pdf. Preserve the aspect ratio and fill the unused page area with a pale blue background.
image2pdf --dpi=150 \ --page-background-color=EEF2F6 \ --page-height=6in \ --page-width=4in \ --print-page-mode=fit \ --output custom-page.pdf \ scan.png
Set the physical print size
Interpret scan.png at 300 pixels per inch without setting a fixed page size. Its 1224 × 1584 pixels produce a 4.08 × 5.28 inch page in print-size.pdf, with the original image pixels retained.
image2pdf --dpi=300 \ --output print-size.pdf \ scan.png
Crop or trim an image
Extract the chart from scan.png into chart.pdf, or remove its uniform outer border and save trimmed.pdf.
The chart starts 96 pixels from the left and 370 pixels from the top, and measures 1024 × 384 pixels. Set 96 DPI so the px crop coordinates match the source image pixels; adjust the region for your image. Automatic border removal works on solid-color borders; use an explicit crop for uneven scan edges.
Extract a selected region
image2pdf --crop-area-height=384px \ --crop-area-width=1024px \ --crop-area-x=96px \ --crop-area-y=370px \ --dpi=96 \ --output chart.pdf \ scan.png
Remove a uniform border
image2pdf --dpi=150 \ --remove-borders \ --output trimmed.pdf \ scan.png
Correct image rotation
Rotate scan-sideways.png 90 degrees clockwise to restore the upright orientation, then save upright.pdf.
image2pdf --dpi=150 \ --rotate=90 \ --output upright.pdf \ scan-sideways.png
Create a smaller PDF
Render scan.png onto A4 paper at 72 DPI and save compact.pdf. Keep the same fit and 12mm margins as the 150 DPI A4 example above, while reducing resolution for screen viewing. Smaller files come at the cost of fine detail.
image2pdf --dpi=72 \ --margin-bottom=12mm \ --margin-left=12mm \ --margin-right=12mm \ --margin-top=12mm \ --page-size=A4 \ --print-page-mode=fit \ --output compact.pdf \ scan.png