This commit is contained in:
2026-03-11 15:27:32 +08:00
parent 454e60dd72
commit 2741839cf3

View File

@@ -49,8 +49,11 @@ func (g *HTMLPDFGenerator) GenerateFromURL(ctx context.Context, url string) ([]b
chromedp.WaitVisible(".page", chromedp.ByQuery),
chromedp.ActionFunc(func(ctx context.Context) error {
g.logger.Info("开始通过 headless Chrome 生成企业报告 PDF", zap.String("url", url))
var err error
pdfBuf, err = page.PrintToPDF().
var (
buf []byte
err error
)
buf, _, err = page.PrintToPDF().
WithPrintBackground(true).
WithPaperWidth(8.27). // A4 宽度(英寸 -> 约 210mm
WithPaperHeight(11.69). // A4 高度(英寸 -> 约 297mm
@@ -59,6 +62,9 @@ func (g *HTMLPDFGenerator) GenerateFromURL(ctx context.Context, url string) ([]b
WithMarginLeft(0.4).
WithMarginRight(0.4).
Do(ctx)
if err == nil {
pdfBuf = buf
}
return err
}),
}