pdfcpu

Logo

A PDF processor written in Go.

View the Project on GitHub pdfcpu/pdfcpu


Changelog

Update Images

This command lets you replace individual images by object number or page number and resource id.

This basic implementation allows for image replacement as long as there is no softmask or alpha channel involved and the image dimensions (width & height) match.

The necessary info to execute this command is retrieved from the output of pdfcpu images list.

Have a look at an example.

Usage

pdfcpu images update inFile imageFile [ outFile ] [ objNr | (pageNr Id) ] [flags]

Common Flags


Arguments

namedescriptionrequired
inFilePDF input fileyes
imageFileimage fileyes
outFilePDF output fileno
objNrobject numberno
pageNrpage numberno
Idresource idno

Example

List all contained images:

$ pdfcpu images list gallery.pdf
gallery.pdf:
1 images available (1.8 MB)

Page Obj# │ Id  │ Type  SoftMask ImgMask │ Width │ Height │ ColorSpace Comp bpc Interp │   Size │ Filters
━━━━━━━━━━┿━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━┿━━━━━━━┿━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━┿━━━━━━━━┿━━━━━━━━━━━━
   1    3 │ Im0 │ image                  │  1268720 │  DeviceRGB    3   8    *   │ 1.8 MB │ FlateDecode

Extract all images into the current dir:

$ pdfcpu images extract gallery.pdf .
extracting images from gallery.pdf into ./ ...
optimizing...
writing gallery_1_Im0.png

Update image with Id=Im0 on page=1 with gallery_1_Im0.png and write the result to updatedGallery.pdf.

Here page number and resource id are contained in the image file name:

$ pdfcpu images update gallery.pdf gallery_1_Im0.png updatedGallery.pdf

Update image with object number 3 with logo.png:

$ pdfcpu images update gallery.pdf logo.png 3

Update image with Id=Im0 on page=1 with logo.jpg:

$ pdfcpu images update gallery.pdf logo.jpg 1 Im0