2

I want to display text in center of the page. But, it's not display proper. I used mpdf and i want to display using mpdf in php.

What I tried :

<?php
require_once __DIR__ . '/../bootstrap.php';

$mpdf = new \Mpdf\Mpdf();

$mpdf->SetDisplayMode('fullwidth');
$stylesheet = '<style>' . file_get_contents('example1.css') . '</style>'; // external css
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML('<div id="center">
Hello World
</div>', 2);
$mpdf->Output('filename.pdf');

CSS :

#centrar{
    margin:0;
    width: 80%;
    background-color: #000;
}
body { text-align: center }

Output :

enter image description here

It's display center in first line. I want to display in full page center part.

How to do that? Please help me. Thanks.

4
  • One way to do it is to output using a table at 100% width and height and use vertical-align: middle Apr 9, 2020 at 10:40
  • Can you please add code in answer?
    – Niket
    Apr 9, 2020 at 10:41
  • I'm on phone at the moment so cannot test any code. Google "html table css vertical align" Apr 9, 2020 at 10:43
  • id="center", is not #centrar... And there is plenty of tutorials how to center everything on world wide web...
    – ikiK
    Apr 28, 2020 at 0:36

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.