Question: condition for set FooterTemplate
olajoe opened this issue · comments
Jaturon commented
How do I start numbering pages in footer and show header from the 2nd to lastest page?
I generate PDF reports from HTML templates,
Is it possible to set conditions in chromedp code or maybe I used CSS?
What versions are you running?
github.com/chromedp/chromedp v0.9.5
What did you do? Include clear steps.
func printContentToPDF(htmlContent string, res *[]byte) chromedp.Tasks {
return chromedp.Tasks{
chromedp.Navigate("about:blank"),
chromedp.ActionFunc(func(ctx context.Context) error {
frameTree, err := page.GetFrameTree().Do(ctx)
if err != nil {
return err
}
return page.SetDocumentContent(frameTree.Frame.ID, htmlContent).Do(ctx)
}),
chromedp.ActionFunc(func(ctx context.Context) error {
footerContent := `
<div style="width: 100%; font-size: 10px; font-weight: 100; text-align: center;">
Page <span class="pageNumber"></span>
<span>/</span>
<span class=totalPages></span>
</div>
`
_ = footerContent
buf, _, err := page.PrintToPDF().
WithDisplayHeaderFooter(true).
WithHeaderTemplate(" ").
WithFooterTemplate(footerContent).
WithPrintBackground(false).Do(ctx)
if err != nil {
return err
}
*res = buf
return nil
}),
}
}
Here is my body html like this
<body>
<!-- Cover Page -->
<div class="cover">
<div class="report-title">Cover Page</div>
<hr />
</div>
<!-- Content Start -->
<div class="content">
<!-- Rest of your content here -->
</div>
</body>
Here is my CSS
.cover {
font-size: 10px;
margin-top: 20px;
margin-bottom: 100px;
page-break-after: always;
page-break-before: always;
page-break-inside: avoid;
}
.content {
font-size: 10px;
margin-top: 20px;
margin-bottom: 100px;
page-break-after: always;
page-break-before: always;
page-break-inside: avoid;
}
What did you expect to see?
In Footer pageNumber/totalPages starting from second page to lastest page
What did you see instead?
It show Footer pageNumber/totalPages starting from first page to lastest