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