Ask Your Question
3

How can divs be displayed beside each other using PHP mPDF?

asked 2021-09-14 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-03-22 18:00:00 +0000

devzero gravatar image

To display divs beside each other using PHP mPDF, you can use the CSS display property to set the divs to inline or inline-block. Here's an example:

<?php

// Create new mPDF document
$mpdf = new \Mpdf\Mpdf();

// Define CSS styles
$css = "
    .inline {
        display: inline-block;
        width: 50%;
        padding: 5px;
    }
";

// Add CSS to document
$mpdf->WriteHTML($css, \Mpdf\HTMLParserMode::HEADER_CSS);

// Define content with two divs
$content = "
    <div class='inline' style='background-color: red;'>Div 1</div>
    <div class='inline' style='background-color: blue;'>Div 2</div>
";

// Add content to document
$mpdf->WriteHTML($content, \Mpdf\HTMLParserMode::HTML_BODY);

// Output PDF
$mpdf->Output();

In this example, we define a CSS style that sets the display property of the divs to inline-block and sets their width and padding. We then add this CSS to the document using the WriteHTML method with mode HEADER_CSS.

We define the content as two divs with the class "inline" and different background colors. These divs will be displayed beside each other due to the inline-block display property.

Finally, we add the content to the document using the WriteHTML method with mode HTML_BODY and output the PDF.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-09-14 11:00:00 +0000

Seen: 13 times

Last updated: Mar 22 '23