mpdf icon indicating copy to clipboard operation
mpdf copied to clipboard

Cannot set margins with SetMargins

Open medilies opened this issue 2 years ago • 1 comments

Guidelines

Description of the bug

SetMargins does not support margin-bottom as the constructor config does, plus margin-left and margin-right are not taken into consideration.

This how I fixed the output in my project https://github.com/elaborate-code/row-bloom/commit/683fcd483b428328280fd43263f261afce2b98b6

mPDF version

v8.1.6

PHP Version and environment (server type, cli provider etc., enclosing libraries and their respective versions)

PHP 8.1.6 (Simply running a script with php ./script.php)

Reproducible PHP+CSS+HTML snippet suffering by the error

// script.php

use Mpdf\HTMLParserMode;
use Mpdf\Mpdf;

$mpdf = new Mpdf();

$mpdf->SetMargins(50,50,50);

$mpdf->SetHeader('foo');
$mpdf->SetFooter('foo');
$mpdf->WriteHTML('<p>foo</p>');
$mpdf->WriteHTML('', HTMLParserMode::HEADER_CSS);

$mpdf->OutputFile(__DIR__.'./bar.pdf');

medilies avatar Jul 08 '23 19:07 medilies

It seems that SetMargins is a method taken over from FPDI, not documented and not (even unofficially) supported in mPDF. Use other methods of setting margins - as parameters of Mpdf\Mpdf constructor, parameters of AddPage/AddPageByArray or by properties of <pagebreak> tag. The SetMargins method will eventually be deprecated and removed.

finwe avatar Sep 01 '23 11:09 finwe