feat(注解转换): 完善注解转换与状态保留
build.yaml / build (push) Successful in 45s

This commit is contained in:
xiaoqidun committed 2026-09-28 17:00:10 +08:00
1 parent 1d365d29db
commit 95dea33a95
4 files changed
+33 -8

No files matched your search

+1 -1
View File
@@ -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
+2 -2
View File
@@ -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=
+15 -5
View File
@@ -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 ""
+15
View File
@@ -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