f
This commit is contained in:
@@ -151,8 +151,8 @@ func (g *PDFGeneratorRefactored) generatePDF(product *entities.Product, doc *ent
|
||||
|
||||
// 创建PDF文档 (A4大小,gofpdf v2 默认支持UTF-8)
|
||||
pdf := gofpdf.New("P", "mm", "A4", "")
|
||||
// 优化边距,减少空白
|
||||
pdf.SetMargins(15, 25, 15)
|
||||
// 上边距与 ContentStartYBelowHeader 一致,这样自动分页后新页内容从 logo 下方开始,不被遮挡
|
||||
pdf.SetMargins(15, ContentStartYBelowHeader, 15)
|
||||
|
||||
// 加载黑体字体(用于所有内容,除了水印)
|
||||
// 注意:此时工作目录应该是根目录(/),这样gofpdf处理路径时就能正确解析
|
||||
@@ -176,9 +176,22 @@ func (g *PDFGeneratorRefactored) generatePDF(product *entities.Product, doc *ent
|
||||
// 创建页面构建器
|
||||
pageBuilder := NewPageBuilder(g.logger, g.fontManager, g.textProcessor, g.markdownProc, g.tableParser, g.tableRenderer, g.jsonProcessor, g.logoPath, g.watermarkText)
|
||||
|
||||
// 添加第一页(产品信息)
|
||||
// 页眉只画 logo+横线。水印用 SetFooterFunc 画:gofpdf 在每页内容画完后再调 Footer,水印最后画,z 层在最上,不会被表格等盖住
|
||||
pdf.SetHeaderFunc(func() {
|
||||
pageBuilder.addHeader(pdf, chineseFontAvailable)
|
||||
})
|
||||
pdf.SetFooterFunc(func() {
|
||||
pageBuilder.addWatermark(pdf, chineseFontAvailable)
|
||||
})
|
||||
|
||||
// 添加第一页(封面:产品信息 + 产品描述 + 价格)
|
||||
pageBuilder.AddFirstPage(pdf, product, doc, chineseFontAvailable)
|
||||
|
||||
// 产品详情单独一页(左对齐,段前两空格)
|
||||
if product.Content != "" {
|
||||
pageBuilder.AddProductContentPage(pdf, product, chineseFontAvailable)
|
||||
}
|
||||
|
||||
// 如果是组合包,需要特殊处理:先渲染所有文档,最后统一添加二维码
|
||||
if product.IsPackage {
|
||||
// 如果有关联的文档,添加接口文档页面(但不包含二维码和说明,后面统一添加)
|
||||
|
||||
Reference in New Issue
Block a user