Home > front end >  Set margin on every page dompdf plugin
Set margin on every page dompdf plugin

Time:12-03

I need to set margin on every page using dompdf like image below (page 2)

page 2

this my fully code

Can anyone help for my problem ? Thanks

CodePudding user response:

To set the margin on every page when using the DOMPDF plugin, you can use the set_paper() method to specify the page size and margins. This method accepts a string argument that specifies the page size and margins in the format "size:widthxheight;margin:topxrightxbottomxleft".

Here is an example of how you can use the set_paper() method to set the margin on every page:

// Create a new DOMPDF instance
$dompdf = new DOMPDF();

// Set the page size and margins
$dompdf->set_paper("A4", "margin:1in");

// Load and render your HTML content
$dompdf->load_html($html);
$dompdf->render();

// Output the PDF document
$dompdf->stream();

In the example above, we create a new DOMPDF instance and use the set_paper() method to set the page size to "A4" and the margins to 1 inch. We then load and render the HTML content, and output the PDF document using the stream() method.

You can customize the page size and margins by modifying the arguments passed to the set_paper() method. For example, if you want to set the margins to 0.5 inches on the top and bottom, and 1 inch on the left and right, you can use the following syntax:

$dompdf->set_paper("A4", "margin:0.5in 1in");

CodePudding user response:

solved the problem by changing some css.

@page {
        margin: 240px 25px 100px 25px;
    }

    header {
        position: fixed;
        top: -220px;
        left: 0px;
        right: 0px;
        height: 90px;
    }

and delete main css

/* main {
        margin-top: 120px;

    } */
  • Related