Image to PDF HTTP API Examples
These examples demonstrate common Image to PDF API workflows via HTTP API.
You can run the examples below with the displayed API credentials. Update the input URLs and filenames as needed.
Basic examples
PNG file to PDF file
curl -f -s -S \ -u 'demo:demo' \ -o logo.pdf \ -F file=@logo.png \ -F input_format=image \ https://api.pdfcrowd.com/convert/24.04/
PNG url to PDF file
curl -f -s -S \ -u 'demo:demo' \ -o logo.pdf \ -F url=https://your-server.com/logo.png \ -F input_format=image \ https://api.pdfcrowd.com/convert/24.04/
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:
curl -f -s -S \ -u 'demo:demo' \ -o a4.pdf \ -F file=@scan.png \ -F input_format=image \ -F dpi=150 \ -F margin_bottom=12mm \ -F margin_left=12mm \ -F margin_right=12mm \ -F margin_top=12mm \ -F page_size=A4 \ -F print_page_mode=fit \ https://api.pdfcrowd.com/convert/24.04/
Letter landscape:
curl -f -s -S \ -u 'demo:demo' \ -o landscape.pdf \ -F file=@scan.png \ -F input_format=image \ -F dpi=150 \ -F margin_bottom=12mm \ -F margin_left=12mm \ -F margin_right=12mm \ -F margin_top=12mm \ -F orientation=landscape \ -F page_size=Letter \ -F print_page_mode=fit \ https://api.pdfcrowd.com/convert/24.04/
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.
curl -f -s -S \ -u 'demo:demo' \ -o custom-page.pdf \ -F file=@scan.png \ -F input_format=image \ -F dpi=150 \ -F page_background_color=EEF2F6 \ -F page_height=6in \ -F page_width=4in \ -F print_page_mode=fit \ https://api.pdfcrowd.com/convert/24.04/
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.
curl -f -s -S \ -u 'demo:demo' \ -o print-size.pdf \ -F file=@scan.png \ -F input_format=image \ -F dpi=300 \ https://api.pdfcrowd.com/convert/24.04/
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:
curl -f -s -S \ -u 'demo:demo' \ -o chart.pdf \ -F file=@scan.png \ -F input_format=image \ -F crop_area_height=384px \ -F crop_area_width=1024px \ -F crop_area_x=96px \ -F crop_area_y=370px \ -F dpi=96 \ https://api.pdfcrowd.com/convert/24.04/
Remove a uniform border:
curl -f -s -S \ -u 'demo:demo' \ -o trimmed.pdf \ -F file=@scan.png \ -F input_format=image \ -F dpi=150 \ -F remove_borders=true \ https://api.pdfcrowd.com/convert/24.04/
Correct image rotation
Rotate scan-sideways.png 90 degrees clockwise to restore the upright orientation, then save upright.pdf.
curl -f -s -S \ -u 'demo:demo' \ -o upright.pdf \ -F file=@scan-sideways.png \ -F input_format=image \ -F dpi=150 \ -F rotate=90 \ https://api.pdfcrowd.com/convert/24.04/
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.
curl -f -s -S \ -u 'demo:demo' \ -o compact.pdf \ -F file=@scan.png \ -F input_format=image \ -F dpi=72 \ -F margin_bottom=12mm \ -F margin_left=12mm \ -F margin_right=12mm \ -F margin_top=12mm \ -F page_size=A4 \ -F print_page_mode=fit \ https://api.pdfcrowd.com/convert/24.04/