Repository navigation
Extract Fonts
huzpsb edited this page Oct 25, 2026
·
1 revision
Export embedded font files from a PDF. Currently supported font type: TrueType.
pdfcpu2 extract -m font in.pdf outDir
pdfcpu2 extract -m font -p 1-5 in.pdf outDirEach extracted font lands in outDir as <inBase>_page_<n>.ttf (deduplicated across pages).
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.
pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers