WeasyPrint icon indicating copy to clipboard operation
WeasyPrint copied to clipboard

`overflow: hidden` breaks order of tags in PDF/UA

Open florian-beetz opened this issue 6 months ago • 7 comments

Hello,

I'm facing an issue where the order of tags is generated out of order if an element is styled with overflow: hidden.

Minimal example:

<html lang="en">
    <head>
        <title>Test</title>
        <style>
            div { margin-bottom: 10rem; }
            .strange { overflow: hidden; }
        </style>
    </head>

    <body>
        <div>before</div>
        <div class="strange">this is last</div>
        <div>after</div>
    </body>
</html>
from weasyprint import HTML

if __name__ == "__main__":
    html = HTML("./test.html")
    html.write_pdf('test.pdf', pdf_variant="pdf/ua-1")

This results in the following tags being generated:

Image

Is there a way to generate the tag at the expected place?

florian-beetz avatar Jun 04 '25 13:06 florian-beetz

Hi!

This is another problem caused by #2444. We’re currently working on #2363, could you try the pdf/ua branch? It’s not ready to be used in production, but it should already help.

liZe avatar Jun 04 '25 14:06 liZe

Thanks for the quick reply! With pdf/ua it looks somewhat different but still the middle tag is generated last.

Image

florian-beetz avatar Jun 04 '25 14:06 florian-beetz

Here’s what I get using PAC.

Image

I think that it’s closer to what you want 😄. Which tool do you use?

(And I’m surprised by all these artifacts, did you add some decorations in your example?)

liZe avatar Jun 04 '25 19:06 liZe

No, I've kept the example as posted above. I was using Adobe Acrobat.

florian-beetz avatar Jun 05 '25 06:06 florian-beetz

No, I've kept the example as posted above. I was using Adobe Acrobat.

Hmm… That’s the order of the drawing stream, not the order of the tag tree. I’ll test as soon as I can get my Windows VM working…

liZe avatar Jun 05 '25 08:06 liZe

order of the drawing stream, not the order of the tag tree

🤦 You're right. The tag order is correct with pdf/ua branch.

Image

florian-beetz avatar Jun 05 '25 09:06 florian-beetz

I’ve also removed useless artifacts.

liZe avatar Jun 05 '25 10:06 liZe