Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change top margin of second page using mPDF

Tags:

php

mpdf

I'm dynamically generating PDFs with an unknown page count. mPDF is working good, but the top margin on the second page is gone. How can I set the margins for all pages with the document?

I've tried the following, but it has no effect:

$mpdf = new mPDF('', '', 0, '', 15, 15, 15, 15, 8, 8);
like image 468
Paul Dessert Avatar asked May 14 '13 08:05

Paul Dessert


People also ask

How do I set margins in mPDF?

In standard usage, mPDF sets the following: margin-top = distance in mm from top of page to start of text (ignoring any headers) margin-header = distance in mm from top of page to start of header. margin-bottom = distance in mm from bottom of page to bottom of text (ignoring any footers)

How do I change page size in mPDF?

// Define a page size/format by array - page will be 190mm wide x 236mm height $mpdf = new \Mpdf\Mpdf(['format' => [190, 236]]); The format is an array of width and height in millimeters. Save this answer.

How do I add a page in mPDF?

php $mpdf->AddPage(); You can define or change all page characteristics when you add the new page: orientation. margins.

What is mPDF format?

mPDF is a PHP library which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF (see CREDITS), with a number of enhancements. mPDF was written by Ian Back and is released under the GNU GPL v2 licence.


2 Answers

You can use something like this. it seems to work.

define the margins using @page like:

<?php
    include("mpdf.php");
    $html='<style>@page {
     margin: 0px;
    }</style>


    ';
    $mpdf=new mPDF('','A4');
    $mpdf->WriteHTML($html);
    $mpdf->Output();
    ?>
like image 75
Srihari Goud Avatar answered Oct 04 '22 10:10

Srihari Goud


I was able to find an answer. Here it is in case anyone needs it:

define the margins using @page like:

@page *{
    margin-top: 2.54cm;
    margin-bottom: 2.54cm;
    margin-left: 3.175cm;
    margin-right: 3.175cm;
}
</style>';

Reference: http://www.mpdf1.com/forum/discussion/80

like image 33
Paul Dessert Avatar answered Oct 04 '22 12:10

Paul Dessert