Repository navigation
Attachments
huzpsb edited this page Oct 25, 2026
·
1 revision
Manage embedded file attachments — the documents ride along inside the PDF.
pdfcpu2 attachments list in.pdf
pdfcpu2 attachments add in.pdf data.xlsx # add
pdfcpu2 attachments add in.pdf "song.mp3, audio" "film.mkv, video" # with descriptions
pdfcpu2 attachments extract in.pdf outDir # extract all
pdfcpu2 attachments remove in.pdf # remove all
pdfcpu2 attachments remove in.pdf data.xlsx # remove specificPipeline:
cat report.pdf | pdfcpu2 attachments add - source.xlsx > report-with-source.pdf
cat report.pdf | pdfcpu2 attachments extract - ./attachmentspackage main
import (
"context"
"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()
// Inventory
aa, err := api.Attachments(ctx, f, conf)
if err != nil {
panic(err)
}
for _, a := range aa {
fmt.Println(a.FileName, a.Desc)
}
// Add, remove, extract
_ = api.AddAttachmentsFile(ctx, "in.pdf", "out.pdf", []string{"data.xlsx"}, false, conf)
_ = api.RemoveAttachmentsFile(ctx, "in.pdf", "out2.pdf", nil, conf)
_ = api.ExtractAttachmentsFile(ctx, "in.pdf", "./files", nil, conf)
}The coll bool parameter routes files into a PDF collection instead of plain attachments — see Portfolio.
pdfcpu2 wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers