How to Convert PNG to PDF with cURL

See how to convert a PNG screenshot, scan, or diagram into a PDF resource with cURL and the pdfRest API.
Share this page

Learn how to convert PNG to PDF with cURL and the Convert to PDF API Tool. We'll move from the local input and service URL through the multipart request, then explain how the returned resource supports later processing after you convert PNG to PDF.

Why Convert PNG to PDF with cURL?

Screenshots, diagrams, and lossless scans are commonly stored as PNG files, while formal reports and case packets are usually assembled as PDFs. Conversion makes the image easier to combine with pages from other document sources.

A support system might capture a troubleshooting screenshot and later include it in an incident report. Converting the PNG first produces a managed PDF resource that can be merged, protected, downloaded, or passed to another pdfRest operation.

The example sends one PNG through the shared /pdf endpoint. If several images belong in one document, convert each separately and merge the resulting PDF resource IDs in the desired page order.

cURL Code Example

# By default, we use the US-based API service. This is the primary endpoint for global use.
API_URL="https://api.pdfrest.com"

# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
# API_URL="https://eu-api.pdfrest.com"

curl -X POST "$API_URL/pdf" \
  -H "Accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
  -F "file=@/path/to/input.png" \
  -F "output=pdfrest_png_to_pdf"

Source for Convert PNG to PDF: View the cURL sample on GitHub. The repository's generic Convert to PDF scaffold is configured here with a .png input for this tutorial.

Breaking Down the Code

Choose the pdfRest service region

# By default, we use the US-based API service. This is the primary endpoint for global use.
API_URL="https://api.pdfrest.com"

# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
# API_URL="https://eu-api.pdfrest.com"

This PNG workflow uses the US service unless the commented EU hostname is selected. A resource created in one environment cannot be handed to a later call in the other, so keep the conversion chain regional.

Build the authenticated multipart request

curl -X POST "$API_URL/pdf" \
  -H "Accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \

The command combines the PNG file and output name in one multipart POST to /pdf. Accept selects a JSON response, and the API key header authenticates the shell request.

Upload the input file data

-F "file=@/path/to/input.png" \

The Convert PNG to PDF request reads the local source from the path after @ and sends its bytes in the multipart file field. For Convert PNG to PDF, cURL treats the path as an upload rather than ordinary form text.

Set the operation-specific fields

-F "output=pdfrest_png_to_pdf"

Here, output gives the generated PDF a useful requested name. No separate format parameter is needed because the uploaded .png filename already identifies the input.

Read the generated resource response

curl -X POST "$API_URL/pdf" \

The PNG request produces a managed PDF resource rather than returning PDF bytes inside JSON. Read its output ID or download URL promptly so the converted screenshot or diagram can move to the next workflow stage.

Beyond the Tutorial

After following the example, you can convert a PNG into a PDF without adding local image or PDF rendering software to the shell environment.

Pixel dimensions and embedded resolution affect how an image occupies the generated PDF page. Check screenshots and scans from several sources so orientation, scale, and readability remain predictable.

Continue exploring the Convert PNG to PDF workflow in API Lab. For the complete Convert PNG to PDF request contract, accepted values, defaults, and limitations, consult the Convert to PDF API Tool documentation.

Note: The Convert PNG to PDF example above uploads a file with multipart form data. For source content already stored in pdfRest, the Convert PNG to PDF JSON payload example shows the resource-ID request shape.

Generate a self-service API Key now!
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.