Friday, 29 November 2019

What css alternative can I use to the non-supported margin-top:auto using mpdf to emulate footer on a4 pages?

I am trying to generate 1:1 a4 pages from my primitive wyswyg to pdf using mpdf. So using this css:

#editor {
  background-color: gray;
  border: 1px black;
  padding: 1em 2em;
}

.page {
  background-color: white;
  border-style: solid;
  border-color: black;
  border-width: 1px;
  /*padding: 10em 2em;*/
  width: 595px;
  height: 841px;
  display: flex;
  flex-direction: column;
}

.content {
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  padding-left: 2cm;
  padding-bottom: 2cm;
  padding-top: 2cm;
  outline-color: white;
}

.header {
  background-color: red;
  text-align: center;
}

.footer {
  background-color: darkgray;
  margin-top: auto;
  height: 100px;
  page-break-after:right;
}

.brasao {
  height: 60px;
  width: 60px;
}

#template {
  display: none;
}

Applied on this HTML + JS: https://jsitor.com/FWvNJa7XN As you can see, using margin-top:auto on div footer, at least on web browsers, I was able to stick the footers on the bottom of each page.

But when I've tried to write using mpdf :

<?php

use Mpdf\Mpdf;
use Mpdf\Output\Destination;

include 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

$mpdf = new Mpdf();

 //via JS as I able to send each page outerHTML separated on hidden values
$pages = $_REQUEST['pages'];

$mpdf = new \Mpdf\Mpdf([
    'mode' => 'utf-8',
    'format' => 'A4',
    'margin_left' => 0,
    'margin_right' => 0,
    'margin_top' => 0,
    'margin_bottom' => 0,
    'margin_header' => 0,
    'margin_footer' => 0,
    'dpi' => 72
]);

$stylesheet = file_get_contents('redator.css');
$mpdf->WriteHTML($stylesheet, \Mpdf\HTMLParserMode::HEADER_CSS);
foreach ($pages as $page) {
    $mpdf->WriteHTML($page);
}
$mpdf->Output();

On firefox the rendered was this (including the editor div): https://i.imgur.com/UJldBr9.png

But, using mpdf, the result was not the expected: https://www.docdroid.net/vP4QALq/mpdf.pdf

So, How can try to render 1:1 on mpdf?



from What css alternative can I use to the non-supported margin-top:auto using mpdf to emulate footer on a4 pages?

No comments:

Post a Comment