feat(转换能力): 已修复PDF附件名称兼容问题
build.yaml / build (push) Successful in 49s

This commit is contained in:
xiaoqidun committed 2026-10-15 09:55:16 +08:00
1 parent 97a00cf1a8
commit fa476f18a3
2 files changed
+11 -2

No files matched your search

-1
View File
@@ -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;
+11 -1
View File
@@ -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
}