This commit is contained in:
2025-12-04 13:42:32 +08:00
parent aaf17321ff
commit 81639a81e6
3 changed files with 126 additions and 127 deletions

View File

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