danfickle / openhtmltopdf

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!
https://danfickle.github.io/pdf-templates/index.html
Other
1.93k stars 359 forks source link

"html" element viewport width not adjusted when pagesize is set to landscape in a named @page (unnamed works ok) #948

Open florimon opened 1 year ago

florimon commented 1 year ago

Hi, first of all thanks for creating an amazing utility.

I ran into the following issue though, here is my 'testcase' html in condensed form:

<html lang="en" class="landscape">
    <head>
        <style>
            @page portrait {
                size: a4 portrait;
            }
            @page landscape {
                size: a4 landscape;
                border: 5px solid red;
            }
            html.portrait {
                page: portrait;
            }
            html.landscape {
                page: landscape;
            }
            html {
                height: 100%;
                border: 5px solid green;
            }
        </style>
    </head>
    <body></body>
</html>

By putting a 'landscape' CSS class on the "html" element, the "@page landscape" rule is activated, which is evidenced by the produced PDF being in landscape mode, and the page having a thick red border box. Inside this red box however is a much narrower green box around the "html" element - I would have expected this to align on all sides to the red box instead. When you change the "@page landscape" selector to just "@page", the green box does indeed have the same width as the red box.

lindamarieb commented 8 months ago

I'm experiencing the same. Is there a solution for this?

siegelzc commented 8 months ago

Why not just apply the styles to the body element? Is there a reason why that doesn't work?

lindamarieb commented 8 months ago

That does work. I have solved it by setting a fixed size on the container element on the landscape page.

On Thu, Mar 14, 2024 at 6:38 AM Zachary Siegel @.***> wrote:

Why not just apply the styles to the body element? Is there a reason why that doesn't work?

— Reply to this email directly, view it on GitHub https://github.com/danfickle/openhtmltopdf/issues/948#issuecomment-1996388307, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDWMKA2SQ5HJH5KUUUF2CTYYESSDAVCNFSM6AAAAAA53ZE5ZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJWGM4DQMZQG4 . You are receiving this because you commented.Message ID: @.***>