This commit is contained in:
2025-12-04 13:28:03 +08:00
parent a8a4ff2d37
commit aaf17321ff
2 changed files with 47 additions and 5 deletions

View File

@@ -139,10 +139,21 @@ func (g *PDFGeneratorRefactored) generatePDF(product *entities.Product, doc *ent
}
// 生成PDF字节流
// 注意pdf.Output 时会重新访问字体文件,确保使用绝对路径
var buf bytes.Buffer
// 在 Output 之前记录当前工作目录,以便调试路径问题
if workDir, err := os.Getwd(); err == nil {
g.logger.Debug("生成PDF前的环境信息",
zap.String("work_dir", workDir),
)
}
err = pdf.Output(&buf)
if err != nil {
// 错误已返回,不记录日志
g.logger.Error("PDF Output失败",
zap.Error(err),
)
return nil, fmt.Errorf("生成PDF失败: %w", err)
}