From fa476f18a32c37cceafdaff8f8303e5a7e74a25b Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Thu, 15 Oct 2026 09:55:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=BD=AC=E6=8D=A2=E8=83=BD=E5=8A=9B):=20?= =?UTF-8?q?=E5=B7=B2=E4=BF=AE=E5=A4=8DPDF=E9=99=84=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=85=BC=E5=AE=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/webui/ofdgo.js | 1 - ofdgo_pdf_link_file.go | 12 +++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/assets/webui/ofdgo.js b/assets/webui/ofdgo.js index 6a523ea..5201618 100644 --- a/assets/webui/ofdgo.js +++ b/assets/webui/ofdgo.js @@ -10664,7 +10664,6 @@ function applyFit(updateStatus = true) { function setScale(nextScale, updateStatus = true, fitMode = "free") { const anchor = updateStatus && fitMode === "free" ? scaleAnchor() : null; - // 适配缩放不受手动下限限制,避免大页面撑出视区。 const scale = Math.min(4, fitMode === "free" ? Math.max(0.2, nextScale) : nextScale); const layoutChanged = scale !== state.scale || fitMode !== state.fitMode; state.fitMode = fitMode; diff --git a/ofdgo_pdf_link_file.go b/ofdgo_pdf_link_file.go index 9ab433e..da6f9bf 100644 --- a/ofdgo_pdf_link_file.go +++ b/ofdgo_pdf_link_file.go @@ -20,6 +20,7 @@ import ( "crypto/sha256" "errors" "fmt" + "strings" "github.com/xiaoqidun/pdfgo" ) @@ -242,7 +243,7 @@ func (p *pdfImporter) embeddedLinkAction(object pdfgo.Object, strict bool) (*Act return &Action{Event: "CLICK", GotoA: &GotoA{AttachID: id, NewWindow: action.NewWindow}}, nil, nil } -// attachmentFile 添加或复用PDF附件,缺少显示名时使用固定名称,不改原始文件内容 +// attachmentFile 按原名及数据复用附件,兼容末尾NUL,缺名使用固定名称 // 入参: name 附件显示名, data 原始文件数据 // 返回: string 附件标识, error 附件写入错误 func (p *pdfImporter) attachmentFile(name string, data []byte) (string, error) { @@ -253,6 +254,12 @@ func (p *pdfImporter) attachmentFile(name string, data []byte) (string, error) { if id, ok := p.attachmentIDs[key]; ok { return id, nil } + if p.warning != nil { + name = strings.TrimRight(name, "\x00") + if name == "" { + name = "Attachment" + } + } id, err := p.editor.AddAttachment(name, data) if err != nil { return "", err @@ -261,5 +268,8 @@ func (p *pdfImporter) attachmentFile(name string, data []byte) (string, error) { p.attachmentIDs = make(map[pdfAttachmentKey]string) } p.attachmentIDs[key] = id + if name != key.name { + p.warning(pdfgo.Diagnostic{Message: "PDF attachment name trailing NUL removed; file data retained"}) + } return id, nil }