This commit is contained in:
2025-12-04 12:30:33 +08:00
parent 7b45b43a0e
commit 4ce8fe4023
10 changed files with 224 additions and 107 deletions

View File

@@ -65,7 +65,7 @@ func (pb *PageBuilder) AddFirstPage(pdf *gofpdf.Fpdf, product *entities.Product,
pb.addWatermark(pdf, chineseFontAvailable)
// 封面页布局 - 居中显示
pageWidth, pageHeight := pdf.GetPageSize()
pageWidth, _ := pdf.GetPageSize()
// 标题区域(页面中上部)
pdf.SetY(80)
@@ -128,14 +128,21 @@ func (pb *PageBuilder) AddFirstPage(pdf *gofpdf.Fpdf, product *entities.Product,
}
}
// 底部信息(价格等
// 价格信息(右下角,在产品详情之后
if !product.Price.IsZero() {
pdf.SetY(pageHeight - 60)
// 获取产品详情结束后的Y坐标稍微下移显示价格
contentEndY := pdf.GetY()
pdf.SetY(contentEndY + 5)
pdf.SetTextColor(0, 0, 0)
pb.fontManager.SetFont(pdf, "", 12)
_, lineHt = pdf.GetFontSize()
pdf.CellFormat(0, lineHt, fmt.Sprintf("价格:%s 元", product.Price.String()), "", 1, "C", false, 0, "")
pb.fontManager.SetFont(pdf, "", 14)
_, priceLineHt := pdf.GetFontSize()
priceText := fmt.Sprintf("价格:%s 元", product.Price.String())
textWidth := pdf.GetStringWidth(priceText)
// 右对齐从页面宽度减去文本宽度和右边距15mm
pdf.SetX(pageWidth - textWidth - 15)
pdf.CellFormat(textWidth, priceLineHt, priceText, "", 0, "R", false, 0, "")
}
}
// AddDocumentationPages 添加接口文档页面