This commit is contained in:
@@ -68,9 +68,30 @@ func (g *PDFGenerator) getChineseFontPaths() []string {
|
||||
fontPaths = []string{
|
||||
"/usr/share/fonts/truetype/wqy/wqy-microhei.ttc",
|
||||
"/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc",
|
||||
"/usr/share/fonts/truetype/wqy/wqy-microhei.ttf",
|
||||
"/usr/share/fonts/truetype/wqy/wqy-zenhei.ttf",
|
||||
"/usr/share/fonts/truetype/arphic/uming.ttc",
|
||||
"/usr/share/fonts/truetype/arphic/ukai.ttc",
|
||||
"/usr/share/fonts/truetype/arphic/uming.ttf",
|
||||
"/usr/share/fonts/truetype/arphic/ukai.ttf",
|
||||
"/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf",
|
||||
"/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc",
|
||||
"/usr/share/fonts/truetype/noto/NotoSansCJK-Bold.ttc",
|
||||
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.otf",
|
||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
||||
"/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
|
||||
"/usr/local/share/fonts/simhei.ttf",
|
||||
"/usr/local/share/fonts/simsun.ttf",
|
||||
"/usr/local/share/fonts/simkai.ttf",
|
||||
"/opt/fonts/simhei.ttf",
|
||||
"/opt/fonts/simsun.ttf",
|
||||
"/opt/fonts/simkai.ttf",
|
||||
"/home/.fonts/simhei.ttf",
|
||||
"/home/.fonts/simsun.ttf",
|
||||
"/home/.fonts/simkai.ttf",
|
||||
"/root/.fonts/simhei.ttf",
|
||||
"/root/.fonts/simsun.ttf",
|
||||
"/root/.fonts/simkai.ttf",
|
||||
}
|
||||
} else if runtime.GOOS == "darwin" {
|
||||
// macOS系统字体路径
|
||||
@@ -99,23 +120,37 @@ func (g *PDFGenerator) findLogo() {
|
||||
_, filename, _, _ := runtime.Caller(0)
|
||||
baseDir := filepath.Dir(filename)
|
||||
|
||||
// 优先使用相对路径(Linux风格,使用正斜杠)
|
||||
logoPaths := []string{
|
||||
filepath.Join(baseDir, "天远数据.png"), // 相对当前文件
|
||||
"天远数据.png", // 当前目录
|
||||
filepath.Join(baseDir, "..", "天远数据.png"), // 上一级目录
|
||||
filepath.Join(baseDir, "..", "..", "天远数据.png"), // 上两级目录
|
||||
"internal/shared/pdf/天远数据.png", // 相对于项目根目录(最常用)
|
||||
"./internal/shared/pdf/天远数据.png", // 当前目录下的相对路径
|
||||
filepath.Join(baseDir, "天远数据.png"), // 相对当前文件
|
||||
}
|
||||
|
||||
// 尝试相对路径
|
||||
for _, logoPath := range logoPaths {
|
||||
if _, err := os.Stat(logoPath); err == nil {
|
||||
// 直接使用相对路径,不转换为绝对路径
|
||||
g.logoPath = logoPath
|
||||
g.logger.Info("找到logo文件", zap.String("logo_path", logoPath))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
g.logger.Warn("未找到logo文件", zap.Strings("尝试的路径", logoPaths))
|
||||
// 尝试服务器绝对路径(后备方案)
|
||||
if runtime.GOOS == "linux" {
|
||||
serverPaths := []string{
|
||||
"/www/tyapi-server/internal/shared/pdf/天远数据.png",
|
||||
"/app/internal/shared/pdf/天远数据.png",
|
||||
}
|
||||
for _, logoPath := range serverPaths {
|
||||
if _, err := os.Stat(logoPath); err == nil {
|
||||
g.logoPath = logoPath
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 只记录关键错误
|
||||
g.logger.Warn("未找到logo文件")
|
||||
}
|
||||
|
||||
// GenerateProductPDF 为产品生成PDF文档(接受响应类型,内部转换)
|
||||
|
||||
Reference in New Issue
Block a user