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

Is automatic page break possible? #439

Open
mewebstudio opened this issue Nov 5, 2024 · 0 comments
Open

Is automatic page break possible? #439

mewebstudio opened this issue Nov 5, 2024 · 0 comments

Comments

@mewebstudio
Copy link

Hello, I opened an issue because I could not find a source related to my problem.

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>PDF</title>
    <style>
        @page {
            size: letter;
            margin: 0;

            @top-right {
                content: element(header);
            }

            @bottom-center {
                content: element(footer);
            }
        }

        body {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            font-size: 12px;
            color: #444;
        }

        header {
            display: block;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            padding: 30px 15px;
            height: 30px;
            background-color: #d9c597;
            border-top: 1px solid #fff;
            text-align: center;
            font-size: 22px;
            font-weight: 300;
            color: #fff;
            z-index: 1000;
        }

        footer {
            display: block;
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            padding: 30px 15px;
            height: 30px;
            background-color: #d9c597;
            border-bottom: 1px solid #fff;
            text-align: center;
            font-weight: 300;
            font-size: 22px;
            color: #fff;
        }

        section {
            display: block;
            padding: 100px 40px;
            page-break-after: always;
        }

        section:last-child {
            page-break-after: auto;
        }
    </style>
</head>
<body>

<section>
    <p>Lorem ipsum...</p>
</section>

<header>Header</header>

<footer>Footer</footer>

</body>
</html>

I'm trying to create a PDF with HTML like this. But when the page content is long, the header and footer rules are invalid on pages other than the first page.

Screenshot 2024-11-05 at 20 31 28

In order to solve the problem, when I want to define margin values ​​for page, give a negative top value for the header, and a negative bottom value for the footer, these areas remain below the layout. For example:

        @page {
            size: letter;
            display: block;
            margin: 90px 0;

            @top-right {
                content: element(header);
            }

            @bottom-center {
                content: element(footer);
            }
        }

        body {
            margin: 0;
            padding: 0;
            ...
        }

        header {
            display: block;
            position: fixed;
            top: -45px;
            left: 0;
            right: 0;
           ...
        }

        footer {
            display: block;
            position: fixed;
            bottom: -45px;
            left: 0;
            right: 0;
            ...
        }
Screenshot 2024-11-05 at 20 38 59

Do you have any suggestions to solve this problem? Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants