From 95dea33a9583103c88fa2fa243cabc0915324525 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Mon, 28 Sep 2026 17:00:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B3=A8=E8=A7=A3=E8=BD=AC=E6=8D=A2):=20?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B3=A8=E8=A7=A3=E8=BD=AC=E6=8D=A2=E4=B8=8E?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E4=BF=9D=E7=95=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 4 ++-- ofdgo_pdf_annot.go | 20 +++++++++++++++----- ofdgo_pdf_link.go | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index eefea99..638074d 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/tdewolff/canvas v0.0.0-20260923214215-09804640d00c github.com/tdewolff/font v0.0.0-20260913163313-54f98bb59ee6 github.com/xiaoqidun/jbig2 v1.1.1 - github.com/xiaoqidun/pdfgo v0.0.0-20260928081150-262fbd884f34 + github.com/xiaoqidun/pdfgo v0.0.0-20260928085418-08275755d188 golang.org/x/crypto v0.57.0 golang.org/x/image v0.46.0 golang.org/x/text v0.42.0 diff --git a/go.sum b/go.sum index 58f8ddb..bbb94e0 100644 --- a/go.sum +++ b/go.sum @@ -62,8 +62,8 @@ github.com/tdewolff/test v1.0.12 h1:7F21DqIajswxuche0geHdrUZRCWE4oko4b7bcmkkrxk= github.com/tdewolff/test v1.0.12/go.mod h1:XPuWBzvdUzhCuxWO1ojpXsyzsA5bFoS3tO/Q3kFuTG8= github.com/xiaoqidun/jbig2 v1.1.1 h1:SjliS9ZO0e9HX5oYUfBuXrfFsXhWricrSz+XY4zORDI= github.com/xiaoqidun/jbig2 v1.1.1/go.mod h1:8QonVWtENmh2kc6l+leqeGl7psb79DWlHDkCpdChjfQ= -github.com/xiaoqidun/pdfgo v0.0.0-20260928081150-262fbd884f34 h1:aZT7GSVDB8do4koXSACBncZDIHFpa8tG7ZEQeeOkZh8= -github.com/xiaoqidun/pdfgo v0.0.0-20260928081150-262fbd884f34/go.mod h1:4Pf0JO0BEf1uzRY+uZjlMjN/OPn3PYa0YMi6cqPPTLQ= +github.com/xiaoqidun/pdfgo v0.0.0-20260928085418-08275755d188 h1:XMOU0kQii0LW3BcFxPQLA7tgVfDmZ6zQcpZuU+eP+fk= +github.com/xiaoqidun/pdfgo v0.0.0-20260928085418-08275755d188/go.mod h1:4Pf0JO0BEf1uzRY+uZjlMjN/OPn3PYa0YMi6cqPPTLQ= github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU= github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= github.com/yuin/goldmark v1.8.5 h1:r6N5afV5qj/5S4UTch8agZHJ8UxNCMwX7WjkkJam2NA= diff --git a/ofdgo_pdf_annot.go b/ofdgo_pdf_annot.go index 6dc19a8..5f75680 100644 --- a/ofdgo_pdf_annot.go +++ b/ofdgo_pdf_annot.go @@ -81,6 +81,13 @@ func (p *pdfImporter) appearanceAnnotation(ctx context.Context, page *pdfgo.Page p.compositeNodes = stamp.compositeNodes } converted := Annotation{Type: pdfAnnotationType(annotation.Subtype), Subtype: string(annotation.Subtype), Appearance: Appearance{Boundary: pdfBoundary(box), Objects: stamp.objects}} + if annotation.Subtype == "Text" { + value, err := p.reader.Resolve(annotation.Dictionary["Open"]) + if err != nil { + return err + } + converted.Parameters = &AnnotationParameters{Parameter: []AnnotationParameter{{Name: "PDF.Text.Open", Value: strconv.FormatBool(value == pdfgo.Boolean(true))}}} + } popupObject := annotation.Dictionary["Popup"] if annotation.Subtype == "Popup" { popupObject = annotation.Dictionary @@ -90,10 +97,13 @@ func (p *pdfImporter) appearanceAnnotation(ctx context.Context, page *pdfgo.Page if err != nil { return err } - converted.Parameters = &AnnotationParameters{Parameter: []AnnotationParameter{ + if converted.Parameters == nil { + converted.Parameters = &AnnotationParameters{} + } + converted.Parameters.Parameter = append(converted.Parameters.Parameter, []AnnotationParameter{ {Name: "PDF.Popup.Open", Value: strconv.FormatBool(popup.Open)}, {Name: "PDF.Popup.Rect", Value: fmt.Sprintf("%g %g %g %g", popup.Rect.XMin, popup.Rect.YMin, popup.Rect.XMax, popup.Rect.YMax)}, - }} + }...) } if len(actions) != 0 { region, err := NewShape(ShapeRectangle, Box{W: box.W, H: box.H}) @@ -120,8 +130,8 @@ func (p *pdfImporter) appearanceAnnotation(ctx context.Context, page *pdfgo.Page visible := false converted.Visible = &visible } - converted.NoZoom = flags&8 != 0 - converted.NoRotate = flags&16 != 0 + converted.NoZoom = flags&8 != 0 || annotation.Subtype == "Text" + converted.NoRotate = flags&16 != 0 || annotation.Subtype == "Text" if value := annotation.Dictionary["T"]; value != nil { resolved, err := p.reader.Resolve(value) if err != nil { @@ -203,7 +213,7 @@ func pdfAnnotationType(subtype pdfgo.Name) string { return "Watermark" case "Highlight", "Underline", "Squiggly", "StrikeOut": return "Highlight" - case "Text", "FreeText", "Line", "Square", "Circle", "Polygon", "PolyLine", "Caret", "Ink", "FileAttachment", "Sound", "Movie", "Screen", "Link", "Popup", "Widget": + case "Text", "FreeText", "Line", "Square", "Circle", "Polygon", "PolyLine", "Caret", "Ink", "FileAttachment", "Sound", "Movie", "Screen", "Link", "Popup", "Widget", "PrinterMark", "TrapNet": return "Path" } return "" diff --git a/ofdgo_pdf_link.go b/ofdgo_pdf_link.go index 7afd500..3830d01 100644 --- a/ofdgo_pdf_link.go +++ b/ofdgo_pdf_link.go @@ -65,6 +65,21 @@ func (p *pdfImporter) annotations(ctx context.Context, page *pdfgo.Page, strict continue } dict := annotation.Dictionary + if annotation.Subtype == "Text" { + value, err := p.reader.Resolve(dict["Open"]) + if err != nil { + return err + } + if value != nil && value != pdfgo.Boolean(false) && value != pdfgo.Boolean(true) { + return fmt.Errorf("invalid PDF text annotation open state") + } + if value == pdfgo.Boolean(true) { + if strict { + return &pdfgo.UnsupportedError{Feature: "initially open text annotation"} + } + p.warning(pdfgo.Diagnostic{Page: p.page + 1, Message: "PDF text annotation open state retained as annotation parameter"}) + } + } popupObject := dict["Popup"] if annotation.Subtype == "Popup" { popupObject = dict