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) ]


Common Flags

name description values
v(erbose) turn on logging  
vv verbose logging  
q(uiet) quiet mode  
-o(ffline) disable http traffic  
c(onf) config dir $path, disable
opw owner password  
upw user password  
u(nit) display unit po(ints),in(ches),cm,mm


Arguments

name description required
inFile PDF input file yes
imageFile image file yes
outFile PDF output file no
objNr object number no
pageNr page number no
Id resource id no


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                  │  1268 │    720 │  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