openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

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

Open florimon opened this issue 2 years ago • 3 comments
trafficstars

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.

florimon avatar Oct 11 '23 10:10 florimon

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

lindamarieb avatar Mar 13 '24 10:03 lindamarieb

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

zacharysiegel avatar Mar 14 '24 04:03 zacharysiegel

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: @.***>

lindamarieb avatar Mar 15 '24 10:03 lindamarieb