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

Floating elements disappear when duplicating page #991

Closed
ewingrj opened this issue Nov 8, 2019 · 3 comments
Closed

Floating elements disappear when duplicating page #991

ewingrj opened this issue Nov 8, 2019 · 3 comments
Labels
bug Existing features not working as expected

Comments

@ewingrj
Copy link

ewingrj commented Nov 8, 2019

Notice the date does not render on the 2nd page.

#!/usr/bin/env python
from weasyprint import HTML

if __name__ == "__main__":
    doc = HTML(string='''
    <style>
    h2 {
        margin-top: 8px;
        margin-bottom: 8px;
    }

    .items {
        clear: both;
        border-collapse: collapse;
        color: #333;
        width: 100%;
    }


    .items tr:nth-child(even) {
        background: #eee;
    }

    .items tr:first-child {
        background: white;
    }

    .items td, th {
        border: 1px solid #ccc;
        padding: 0.5em;
    }

    .items th {
        border: none;
        text-align: center;
    }

    .items tbody {
        border-bottom: 3px solid black;
    }

    .items .qty {
        text-align: right;
        width: 40px;
    }
</style>


<h3 style="">Disappearing header</h3>
<p style="float: right">Oct. 24, 2019</p>

<table class="items">
    <tr>
        <th>Item</th>
        <th class="qty">Qty</th>
    </tr>

    <tbody>
    
        <tr>
            <td>shirt</td>
            <td class="qty">1</td>
        </tr>
   
    </tbody>
</table>
''').render()

    doc = doc.copy(doc.pages + doc.pages)
    doc.write_pdf('example.pdf')
@liZe liZe added conformance bug Existing features not working as expected and removed conformance labels Nov 8, 2019
@Tontyna
Copy link
Contributor

Tontyna commented Nov 9, 2019

There is no need to copy the doc to make floats disappear -- just write_* twice:

snippet = '<div style="float:left">lorem ipsum</div>'
doc = HTML(string=snippet).render()

doc.write_pdf('example.pdf')
doc.write_png('example.png')

There is no "lorem ipsum" in the png.

This is a feature of StackingContext.from_page(), manipulating the (original! Pointers! no copies!) page box tree to facilitate the correct paint order (z-index, floats etc.) -- floating boxes are removed from the original tree.

@balliegojr
Copy link

I am having the same problem.

In my case, I'm using the PdfGenerator from the Tips & Tricks page, to generate the headers of the document.
Floating elements will appear only in the header of the first page

First page:
image

Second Page:
image

@liZe
Copy link
Member

liZe commented Aug 2, 2021

Discussion continues in #1081, with other infamous examples.

@liZe liZe closed this as completed Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

No branches or pull requests

4 participants