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.
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
Asked: 2021-09-14 11:00:00 +0000
Seen: 13 times
Last updated: Mar 22 '23
How can a HTTP header be inserted in WordPress?
How can data be stored in a data attribute and utilized through Ajax?
How can an array be passed using typo3 flexform xml and itemsProcConfig?
How to use Composer autoload in implementing PHP namespaces?
What is the difference between highlighting HTML code in a .php file in VSCode?
Does JSON encode fail to retrieve data from the database?
Why isn't the cell text appearing when using easytable and fpdf in PHP version 7.4?
Can the GS1 128 barcode decoder in PHP or Jquery be utilized?
How can Xdebug be used in conjunction with VSCode for Laravel on Sail and WSL2?