Mpdf : Set 0 margin for page 1 only

后端 未结 1 1111
说谎
说谎 2021-01-21 20:36
$mpdf = new \\Mpdf\\Mpdf([
        \'tempDir\' => __DIR__ . \'/temp\'
    ]);
$mpdf->SetMargins(0, 0, 0); // will set it to 0 for all pages.

Is i

1条回答
  •  抹茶落季
    2021-01-21 21:11

    If you do not need automatic content overflow for page 1 and other pages, you can use AddPageByArray() method:

    $mpdf = new \Mpdf\Mpdf([]);
    
    $mpdf->AddPageByArray([
        'margin-left' => 0,
        'margin-right' => 0,
        'margin-top' => 0,
        'margin-bottom' => 0,
    ]);
    
    $mpdf->WriteHTML($html1); // first page
    
    $mpdf->AddPageByArray([
        'margin-left' => '15mm',
        'margin-right' => '20mm',
        'margin-top' => '15mm',
        'margin-bottom' => '15mm',
    ]);
    
    $mpdf->WriteHTML($html2); // other pages
    
    // All other pages will then have margins of the second `AddPageByArray()` call.
    

    In a case of content overflow from the first page, the next, automatically created page will also have zero margins.


    Alternatively, you can set zero margins in the constructor and reset margins for following pages using pseudo-HTML tag:

    $mpdf = new \Mpdf\Mpdf([
        'margin_left' => 0,
        'margin_right' => 0,
        'margin_top' => 0,
        'margin_bottom' => 0,
    ]);
    
    $html = 'Content of the first page
        
     Other content';   
    
    $mpdf->WriteHTML($html1);
    

    0 讨论(0)
提交回复
热议问题