Image to PDF

Convert one or more images to a PDF document.

POSThttps://api.morphopdf.com/v1/convert/image-to-pdf

Authentication

AuthorizationBearer

Retrieve your API Key from Dashboard.

Request Body

Provide images using one of the following methods.

fileFile | File[]

One or more image files uploaded via multipart/form-data. Supported formats: JPEG, PNG, WebP, GIF, TIFF

urlsstring[]Optional

Array of public URLs pointing to images. Alternative to file upload.

pageSizestringOptionalDefault: Original

Page size for the PDF. Options: 'A4', 'Letter', 'Original' (fit page to image dimensions)

marginnumberOptionalDefault: 0

Margin around images in pixels.

backgroundColorstringOptionalDefault: #FFFFFF

Background color for the PDF pages (hex format).

fitModestringOptionalDefault: contain

How images should fit the page. Options: 'contain' (fit within bounds), 'cover' (fill bounds, may crop), 'fill' (stretch to fit)

imageOrderarrayOptional

Array of objects specifying order and rotation for each image: [{name: 'image.jpg', rotation: 90, order: 0}]

Query Parameters

formatstringOptionalDefault: json

Response format. Use 'binary' to receive the PDF directly, or 'json' (default) to receive metadata with a download URL.

Supported Image Formats

This endpoint accepts: JPEG, PNG, WebP, GIF, TIFF

Response

When using format=json (default):

successboolean

Indicates whether the operation completed successfully.

messagestring

Human-readable status message.

fileNamestring

Name of the generated PDF document.

downloadUrlstring

Presigned URL to download the file. Valid for 1 hour.

pageCountnumber

Number of pages in the generated PDF.

originalImageCountnumber

Number of images that were successfully processed.

processingTimenumber

Time taken to process the conversion in milliseconds.

pageSizestring

Page size used for the PDF (e.g. 'A4').

methodstring

Conversion method used (e.g. 'sharp').

outputSizenumber

Size of the generated PDF in bytes.

failedImagesnumber

Number of images that failed to process.

Binary Response

Add ?format=binary to receive the PDF directly with these headers:

  • Content-Type: application/pdf
  • Content-Disposition: attachment; filename="images.pdf"

Error Responses

StatusCodeDescription
400INVALID_INPUTNo images provided or invalid image format
401AUTHENTICATION_REQUIREDMissing or invalid API key
413FILE_TOO_LARGEFile exceeds maximum size limit
500PROCESSING_FAILEDInternal processing error
POST/v1/convert/image-to-pdf
curl -X POST "https://api.morphopdf.com/v1/convert/image-to-pdf?format=binary" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@image1.jpg" \
  -F "file=@image2.png" \
  --output images.pdf
200OK
{
  "success": true,
  "message": "File processed successfully",
  "fileName": "images.pdf",
  "downloadUrl": "https://files.morphopdf.com/sessions/abc123/output/images.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&...",
  "pageCount": 3,
  "originalImageCount": 3,
  "processingTime": 1200,
  "pageSize": "A4",
  "method": "sharp",
  "outputSize": 512000,
  "failedImages": 0
}