PDF-lib icon

PDF-lib

Work with PDFs using pdf-lib

Add Images

AI-generated

Summary

Add one or more PNG or JPEG images to an existing PDF loaded from a URL or binary data, or create a new PDF document and add images to it, positioning and transforming each image as specified.

Inputs

  • PDF Source (required) — Select the source of the PDF to add images to: from a URL, from binary data in the workflow, or create a new PDF.
  • PDF URL (required) — If PDF Source is 'From URL', specify the URL of the PDF to add images to.
  • Binary Property (required) — If PDF Source is 'From Binary Data', specify the name of the binary property containing the PDF file in the input data.
  • Page Size (required) — If PDF Source is 'Create New PDF', select the page size for the new document (A4, Letter, or Custom).
  • Images (required) — Add one or more images to insert. For each, specify the image source (from URL or binary), URL or binary property of the image, X and Y position on the page, width, height, 0-indexed page number, and rotation in degrees.
  • Output Property Name — Name of the binary property to store the resulting PDF; defaults to 'data'.

Output shape

a list of items each containing the modified PDF as a binary property

Each output item corresponds to an input item and contains the input JSON unchanged plus a binary property (name configurable) with the resulting PDF file. The operation supports PNG and JPEG image formats only. When specifying page numbers for image placement, the pages must exist in the PDF (0-indexed). If creating a new PDF, one page is added with the selected page size and images are added there.

Examples

Example 1: Add images to an existing PDF loaded from URL

Set PDF Source to 'From URL', provide PDF URL, add one or more images with sources and positions, and set output property name if needed.

Example 2: Add images to a PDF from binary data in the input

Set PDF Source to 'From Binary Data', specify the binary property name, configure images similarly.

Example 3: Create new PDF and add images

Set PDF Source to 'Create New PDF', select a page size, add images to the single created page.

Discussion