플래트닝
기본 플래트닝
작성된 폼 PDF를 열고 모든 필드를 정적 콘텐츠로 플래트닝합니다.
doc, _ := gpdf.Open(filledFormPDF)
if err := doc.FlattenForms(); err != nil {
log.Fatal(err)
}
result, _ := doc.Save()
플래트닝 + 워터마크
폼 필드를 플래트닝하고 "FINAL" 워터마크를 추가합니다.
doc, _ := gpdf.Open(filledFormPDF)
// 폼 플래트닝
doc.FlattenForms()
// 워터마크 추가
doc.EachPage(func(_ int, p *template.PageBuilder) {
p.Absolute(document.Mm(50), document.Mm(140), func(c *template.ColBuilder) {
c.Text("FINAL",
template.FontSize(72),
template.TextColor(pdf.Gray(0.9)),
)
})
})
result, _ := doc.Save()
플래트닝 + 페이지 번호
폼 필드를 플래트닝하고 모든 페이지에 페이지 번호를 추가합니다.
doc, _ := gpdf.Open(filledFormPDF)
// 폼 플래트닝
doc.FlattenForms()
// 페이지 번호 추가
count, _ := doc.PageCount()
doc.EachPage(func(i int, p *template.PageBuilder) {
p.Absolute(document.Mm(170), document.Mm(285), func(c *template.ColBuilder) {
c.Text(fmt.Sprintf("%d / %d", i+1, count),
template.FontSize(10),
template.AlignRight(),
)
}, template.AbsoluteWidth(document.Mm(20)))
})
result, _ := doc.Save()
안전한 플래트닝 (폼 없음)
FlattenForms()는 모든 PDF에서 안전하게 호출할 수 있습니다 — 폼 필드가 없으면 아무 작업도 수행하지 않습니다.
// 폼이 있든 없든 모든 PDF에서 동작
doc, _ := gpdf.Open(anyPDF)
doc.FlattenForms() // AcroForm이 없으면 아무 작업도 수행하지 않음
result, _ := doc.Save()