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.91k stars 357 forks source link

PDF generated with unexpected spacing margin and not align center like html. #853

Open 1s1y opened 2 years ago

1s1y commented 2 years ago

Between <img /> and <div />, a confused spacing margin has been rendered. And align center in html is broken.

Here is the html source.

<html lang="zh-CN">
<head>
    <style>
        body {
            margin: 0 48px;
            line-height: 1.5;
            font-size: 16px;
        }

        img {
            width: 100%;
            height: auto;
            object-fit: cover;
        }
    </style>
    <title>demo</title>
</head>
<body>

<div class="image">
    <div style="margin: 10px auto; width: 768px;">
        <img src="https://upload-images.jianshu.io/upload_images/5809200-caf66b935fd00e18.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="aa"/>
        <div style="background-color: #e5e7eb; width: 100%">
            <span style="min-width: 4em;">author: <span>any</span></span>
        </div>
    </div>
</div>

</body>
</html>
prashants007 commented 2 years ago

Facing the same issue... Did you find any solution? Thanks in advance

1s1y commented 2 years ago

Facing the same issue... Did you find any solution? Thanks in advance

No. I just adjust my css style to make it like normal, use a negative padding and other fixes.