Wrong rendering while generating pdf from html in Java

a4dev92 :

I'm trying to convert simple html to pdf but the styling in my browser is different than the one in pdf. I'm using flying-saucer-pdf v9.1.18. Do you have any idea why?

here is how it looks on web browser and how it looks in the generated pdf: https://i.stack.imgur.com/MB7DB.jpg

Here is my simple html template:

<html>

<head>
    <style>
        .aligned {
            vertical-align: bottom;
        }
        
        .colored {
            color: red;
            font-weight: bold;
        }
    </style>
</head>

<body>
    <table border="1" width="300px" height="300px">
        <tr>
            <td>1</td>
            <td>2</td>
        </tr>
        <tr>
            <td>3</td>
            <td class="colored">4</td>
        </tr>
        <tr>
            <td>5</td>
            <td class="aligned">6</td>
        </tr>
    </table>
</body>

</html>

luca.vercelli :

From docs:

No support for legacy or "street" HTML, although there are several open source Java HTML cleaners of varying quality available. We render well-formed XML; XHTML is a well-formed XML document which uses a special set of tags. We can't render most HTML "in the wild". At best, you can "clean up" old HTML with TagSoup or JTidy or similar library and hope for the best. But without a bunch of work, you won't be able to use Flying Saucer for a real web browser component. However, note that's not a technical limitation, just a lack of time and resources.

The "height" attribute of TABLE tag is standard at all, I guess flying-saucer is ignoring it.

See e.g. Setting the height of a table in HTML has no effect

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=159136&siteId=1