Skip to content

Extract Fonts

huzpsb edited this page Oct 25, 2026 · 1 revision

Extract Fonts

Export embedded font files from a PDF. Currently supported font type: TrueType.

Command line

pdfcpu2 extract -m font in.pdf outDir
pdfcpu2 extract -m font -p 1-5 in.pdf outDir

Each extracted font lands in outDir as <inBase>_page_<n>.ttf (deduplicated across pages).

Go API

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/huzpsb/pdfcpu2/pkg/api"
	"github.com/huzpsb/pdfcpu2/pkg/pdfcpu/model"
)

func main() {
	ctx := context.Background()
	conf := model.NewDefaultConfiguration()

	f, _ := os.Open("in.pdf")
	defer f.Close()

	// Custom sink
	err := api.ExtractFonts(ctx, f, nil, func(font pdfcpu.Font) error {
		fmt.Printf("page %d: %s\n", font.PageNr, font.Name)
		return nil
	}, conf)
	if err != nil {
		panic(err)
	}

	// Or simply to disk
	_ = api.ExtractFontsFile(ctx, "in.pdf", "./fonts", nil, conf)
}

Install extracted fonts for reuse in stamps: pdfcpu2 fonts install <file> — see Fonts.

Clone this wiki locally