From 2522849b19b413541d58bc370dbccc5a383c40ec Mon Sep 17 00:00:00 2001 From: Gunnsteinn Hall Date: Mon, 24 Sep 2018 19:50:58 +0000 Subject: [PATCH] Fix for handling non-widget annotations per page when flattening --- pdf/model/flatten.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pdf/model/flatten.go b/pdf/model/flatten.go index 88fe6f7e..864eba2b 100644 --- a/pdf/model/flatten.go +++ b/pdf/model/flatten.go @@ -36,6 +36,8 @@ func (pdf *PdfReader) FlattenFields(allannots bool) error { fields := acroForm.AllFields() for _, field := range fields { for _, wa := range field.Annotations { + // TODO(gunnsth): Check if wa.Flags() has Print flag then include, otherwise exclude. + // XXX/FIXME: May be better to check field.V only if no appearance stream available. if field.V != nil { ftargets[wa.PdfAnnotation] = true @@ -56,8 +58,8 @@ func (pdf *PdfReader) FlattenFields(allannots bool) error { } // Go through all pages and flatten specified annotations. - annots := []*PdfAnnotation{} for _, page := range pdf.PageList { + annots := []*PdfAnnotation{} for _, annot := range page.Annotations { hasV, toflatten := ftargets[annot] if !toflatten { @@ -96,7 +98,7 @@ func (pdf *PdfReader) FlattenFields(allannots bool) error { page.Resources.SetXObjectFormByName(name, xform) // XXX/TODO: Take Matrix and potential scaling of annotation Rect and appearance BBox into account. - // Have yet to find a case where that actually happens. + // Have yet to find a case where that actually is required. // Placement for XForm. xRect := math.Min(rect.Llx, rect.Urx)