pdfcpu

Logo

A PDF processor written in Go.

View the Project on GitHub pdfcpu/pdfcpu


Changelog

Import

Convert one or more image files into a PDF file. Have a look at some examples.

Usage

pdfcpu import -- [description] outFile imageFile...


Common Flags

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


Arguments

name description required
description configuration string no
outFile PDF output file yes
imageFile… one or more input image files yes


Description

A configuration string to specify the details of the image layout on the page.

parameter values default
dimensions (width, height) in user units eg. ‘400 200’ 595 842
dpi destination resolution in dots per inches 72
formsize, papersize paper size to be used. Append L or P to enforce landscape/portrait mode A4
position one of full or the anchors: tl, tc, tr, l, c, r, bl, bc, br full
offset (dx,dy) float vals in user units eg. ‘15 20’ or ‘15.0 20.0’ 0 0
scalefactor 0.0 <= s <= 1.0 followed by optional abs or rel 0.5 rel
gray Convert to grayscale (on/off, true/false, t/f) off
sepia Apply sepia effect (on/off, true/false, t/f) off
backgroundcolor, bgcol color none


Anchors for positioning

       
  left center right
top tl tc tr
  l c r
bottom bl bc br


Default description

'f:A4, dim:595 842, dpi:72, pos:full, off:0 0, scale:0.5 rel, gray:off, sepia:off'


Examples

Create a single page photo.pdf containing photo.png using the default positioning pos:full. The page size dimensions will match the dimensions of the image:

$ pdfcpu import photo.pdf photo.png


Create a single page PDF using paper size f:A5 using the default orientation portrait which could also be expressed with f:A5P. Use the positioning parameter pos:c to center the image on the page and the default relative scaling sc:0.5 rel:

$ pdfcpu import -- "f:A5, pos:c" photo.pdf photo.jpg


Create a single page PDF using paper size f:A5L using the orientation landscape. Use the positioning parameter pos:c to center the image on the page and the default relative scaling sc:0.5 rel:

$ pdfcpu import -- "f:A5L, pos:c" photo.pdf photo.jpg


Create a single page PDF using A5 landscape mode, a relative scaling of 0.5 and the positioning pos:bl which anchors the picture to the bottom left page corner:

$ pdfcpu import -- "form:A5L, pos:bl" photo.pdf photo.jpg


Create a single page PDF using A5 landscape mode, relative scaling 0.5, positioning pos:r which anchors the picture to the right side vertically centered. Use a negative horizontal offset off:-20 0 to impose a margin:

$ pdfcpu import -- "form:A5L, pos:r, off:-20 0" photo.pdf photo.jpg


Import photo.jpg into a 500 x 500 single page PDF anchoring the image to the top left corner using a relative scaling of 0.3:

$ pdfcpu import -- "d:500 500, pos:tl, sc:0.3 rel" photo.pdf photo.jpg


Import photo.jpg into a 500 x 500 single page PDF anchoring the image to the top left corner using a relative scaling of 1:

$ pdfcpu import -- "d:500 500, pos:tl, sc:1" photo.pdf photo.jpg


Generate a PDF photo album assuming pics/ contains image files (jpg, png, tif):

$ pdfcpu import album.pdf pics/*


Generate a PDF photo album with images centered on the page using the default relative scaling of 0.5:

$ pdfcpu import -- "pos:c" album.pdf pics/*


The following command also generates a PDF album but additionally configures the paper size Letter and positions the images to be anchored to the bottom left corner with a horizontal offset of 10 points and a vertical offset of 20 points with a scaling of 0.3 relative to page dimensions:

$ pdfcpu import -- "f:Letter, pos:bl, off:10 20, scale:0.3" album.pdf *.jpg *.png


If an album created by Import ends up having some pages with images not in upright position the Rotate command comes to the rescue. Let’s say we just have created an album and the images on page 3 and 4 need to be rotated counter clockwise by 90 degrees. This happens frequently. We can fix this situation with:

$ pdfcpu rotate -pages 3-4 album.pdf -90


You can also convert your input images to grayscale:

$ pdfcpu import -- "gray:true" gray.pdf test.jpg 
   


Or you can apply a sepia effect:

$ pdfcpu import -- "sepia:true" sepia.pdf test.jpg