MRTY
MRTY

Reputation: 81

MPDF how can i delete the white space margin

$style='<style>@page *{
margin-top: 0cm;
margin-bottom: 0cm;
margin-left: 0cm;
margin-right: 0cm;
}</style>';

$html ='<img src="temppng/'.$_GET['memid'].'.png"  width="325.03937" height="204.094488"  `/>';   

include("MPDF54/mpdf.php");

$mpdf = new mPDF('utf-8', 'Letter', 0, '', 1, 1, 1, 1, 8, 8);
$mpdf->useAdobeCJK = true;
$mpdf->SetAutoFont(AUTOFONT_ALL);
`$mpdf->SetMargins(0);
$mpdf->WriteHTML('<pagebreak sheet-size="86mm  54mm" />');
$mpdf->WriteHTML($style);


$mpdf->WriteHTML($html);
$mpdf->WriteHTML('<tocentry content="150mm square" />')

$mpdf->DeletePages(1,1);
$mpdf->Output();

Hi,any one know how to delete the bottom white space of the pdf,here is image 'http://tinypic.com/view.php?pic=xfdixj&s=8',i want to delete the bottom white space,any one know how to do?THX

Upvotes: 8

Views: 25317

Answers (3)

RodneyO
RodneyO

Reputation: 125

You can adjust the margins using by setting parameters as below

new Pdf([
      'mode' => '', // leaner size using standard fonts
      'format' => Pdf::FORMAT_A4,
      'orientation' => Pdf::ORIENT_LANDSCAPE,
      'marginTop' => 0,
      'marginBottom' => 0,
      'marginLeft' => 0,
      'marginRight' => 0,
      'destination' => Pdf::DEST_BROWSER,
      'content' => $this->renderPartial('certificate_pdf', ['']),
      'options' => [
        // any mpdf options you wish to set
      ],
      'methods' => [
        'SetTitle' => '',
        'SetSubject' => '',
        'SetHeader' => [''],
        'SetFooter' => [''],
        'SetAuthor' => 'Ajira Tracking',
        'SetCreator' => 'Ajira Tracking',
        'SetKeywords' => 'Ajira Tracking',
      ]
    ]);

Upvotes: 0

Abdul Qadir R.
Abdul Qadir R.

Reputation: 1201

mpdf page layout can be customize with the following approach

For mpdf version 6.0 we can use

$mpdf=new mPDF('utf-8', 'A4', 0, '', 0, 0, 0, 0, 0, 'L'); // use this customization

The default settings of mPDf in version 6.0 along with the parameters looks like

function mPDF($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P')

For mpdf version 7.0 or greater we can use

$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]); //use this customization

The default settings of mPDf in version 7.0 along with the parameters looks like

$constructor = [
        'mode' => '',
        'format' => 'A4',
        'default_font_size' => 0,
        'default_font' => '',
        'margin_left' => 15,
        'margin_right' => 15,
        'margin_top' => 16,
        'margin_bottom' => 16,
        'margin_header' => 9,
        'margin_footer' => 9,
        'orientation' => 'P',
    ];

Futher detail regarding the available options of mPDF class can be get from the official documentaion https://mpdf.github.io/reference/mpdf-functions/construct.html

Upvotes: 6

Amien
Amien

Reputation: 974

Create it with 0 margins or whatever you'd like accordingly

$mpdf=new mPDF('utf-8', 'Letter', 0, '', 0, 0, 0, 0, 0, 0);




class mPDF ([ string $mode [, mixed $format [, float $default_font_size [, string $default_font [, float $margin_left , float $margin_right , float $margin_top , float $margin_bottom , float $margin_header , float $margin_footer [, string $orientation ]]]]]])

Upvotes: 14

Related Questions