Repository navigation
Attachments
huzpsb edited this page Nov 8, 2026
·
2 revisions
Manage embedded file attachments — the documents ride along inside the PDF.
hspdf attachments list in.pdf
hspdf attachments add in.pdf data.xlsx # add
hspdf attachments add in.pdf "song.mp3, audio" "film.mkv, video" # with descriptions
hspdf attachments extract in.pdf outDir # extract all
hspdf attachments remove in.pdf # remove all
hspdf attachments remove in.pdf data.xlsx # remove specificPipeline:
cat report.pdf | hspdf attachments add - source.xlsx > report-with-source.pdf
cat report.pdf | hspdf attachments extract - ./attachmentspackage main
import (
"context"
"os"
"github.com/huzpsb/hspdf/pkg/api"
"github.com/huzpsb/hspdf/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.
hspdf wiki
Getting started
Fork features
Inspect
Document
Pages
Content
Extract
Resources
Security
Viewer
Trust
Developers