This commit is contained in:
2025-12-04 16:17:27 +08:00
parent d9c2d9f103
commit 0f5c4f4303
9 changed files with 227 additions and 55 deletions

View File

@@ -177,7 +177,7 @@ func (g *PDFGeneratorRefactored) generatePDF(product *entities.Product, doc *ent
// 这样gofpdf在Output时使用相对路径 app/resources/pdf/fonts 就能正确解析
var buf bytes.Buffer
// 在Output前验证字体文件路径此时工作目录应该是根目录/
if workDir, err := os.Getwd(); err == nil {
// 验证绝对路径
@@ -188,7 +188,7 @@ func (g *PDFGeneratorRefactored) generatePDF(product *entities.Product, doc *ent
zap.String("work_dir", workDir),
)
}
// 验证相对路径gofpdf可能使用的路径
fontRelPath := "app/resources/pdf/fonts/simhei.ttf"
if relAbsPath, err := filepath.Abs(fontRelPath); err == nil {
@@ -207,14 +207,14 @@ func (g *PDFGeneratorRefactored) generatePDF(product *entities.Product, doc *ent
)
}
}
g.logger.Debug("准备生成PDF",
zap.String("work_dir", workDir),
zap.String("resources_pdf_dir", resourcesDir),
zap.Bool("work_dir_changed", workDirChanged),
)
}
err = pdf.Output(&buf)
if err != nil {
// 记录详细的错误信息
@@ -222,7 +222,7 @@ func (g *PDFGeneratorRefactored) generatePDF(product *entities.Product, doc *ent
if wd, e := os.Getwd(); e == nil {
currentWorkDir = wd
}
// 尝试分析错误:如果是路径问题,记录更多信息
errStr := err.Error()
if strings.Contains(errStr, "stat ") && strings.Contains(errStr, ": no such file") {