Repository navigation
Import Images
huzpsb edited this page Oct 25, 2026
·
1 revision
Turn image files into a PDF page sequence — the quickest way to build a PDF from scans, photos or screenshots. If the output file already exists, pages are appended.
pdfcpu2 import [description] outFile imageFile...
Supported formats: JPEG, PNG, TIFF (incl. multi-page), WebP. - reads one image from stdin; - writes the PDF to stdout.
<description> — comma-separated, defaults "dim:595 842, f:A4, pos:full, off:0 0, sc:0.5 rel, dpi:72, gray:off, sepia:off":
| Entry | Meaning |
|---|---|
dim: <w> <h> |
page size in display units (media box) |
form: A4|LetterL|… |
named paper size, L/P enforce orientation (see Paper) |
pos: |
full (image = page) or anchor: tl tc tr l c r bl bc br
|
off: <dx> <dy> |
offset from anchor |
sc: <f> abs|rel |
scale factor |
dpi: |
target resolution, e.g. 300
|
gray:, sepia:
|
grayscale / sepia conversion |
bgcol: |
background color |
pdfcpu2 import img.pdf img.jpg # one image, page = image size
pdfcpu2 import 'f:A5, pos:c' out.pdf *.jpg # centered on A5
pdfcpu2 import 'pos:full, dpi:300' out.pdf scan*.png
cat logo.png | pdfcpu2 import - - > logo.pdf # stdin -> stdoutpackage main
import (
"context"
"github.com/huzpsb/pdfcpu2/pkg/api"
"github.com/huzpsb/pdfcpu2/pkg/pdfcpu/types"
)
func main() {
ctx := context.Background()
// Parse the same description string the CLI uses
imp, err := api.Import("f:A4, pos:c", types.POINTS)
if err != nil {
panic(err)
}
err = api.ImportImagesFile(ctx, []string{"a.jpg", "b.png"}, "out.pdf", imp, nil)
if err != nil {
panic(err)
}
}api.DefaultImportConfig() gives you the defaults to tweak in code; api.ImportImages(ctx, rs, w, readers, imp, conf) accepts []io.Reader for in-memory images.
pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers