'render multiple inline boxes/tables in xhtml2pdf

I'm using xhtml2pdf library with Djanog to generate PDF reports. I am trying to generate a report where I'll be able to print multiple boxes for the context data.

Seems div width is not detected in xhtml2pdf, and my tables doesn't stay inlined as well.

Here's what I have done so far:

<!DOCTYPE html>
<html lang="en">
<head>
    <style>
        @page {
            size: a4 landscape;
            margin: 2cm;
        }
    </style>
</head>

<body>
    {% for item in items %}
        <table style="width: 20%; background-color: red;">
            <tr style="width: 30%;">
                <td style="width: 30%;">
                    <img class="logo" src="{{item.barcode | barcode_image}}" alt="Barcode" />
                    <p>{{ item.product_name }}</p> <br>
                    <small id="price">MRP: {{ barcode_item.price }} TK</small>
                    {% endif %}
                </td>
            </tr>
        </table>
    {% endfor %}
</body>

</html>

This code results: enter image description here

Expected Result Format/Layout: Expected Result

Is there any way to print the expected layout using xhtml2pdf?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source