Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: condition for set FooterTemplate #1462

Open
olajoe opened this issue Apr 3, 2024 · 0 comments
Open

Question: condition for set FooterTemplate #1462

olajoe opened this issue Apr 3, 2024 · 0 comments

Comments

@olajoe
Copy link

olajoe commented Apr 3, 2024

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

@olajoe olajoe closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2024
@olajoe olajoe reopened this Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant