Configure Sheet Margins in FPDF

Asked

Viewed 3,373 times

-1

I have a problem in FPDF, I need to configure the page margins, but I could not find how I do it. If anyone knows and can answer me thank you, or if they know if it has been asked here in the forum send me the link I will look.

  • A little Google search should solve your problem

  • Also I do not understand the vote to close the question... The downvote was I who gave

  • Dude wouldn’t have come here if I’d found it on Google, would you??? type to 2 days researching it there and just redirects me to basic pages where no one who made the page cared to show it... but blza..

  • 1

    @Jesseseffrin did the research in English (set margin fpdf) and in Portuguese (define fpdf margins), and in both cases I found the answer with some ease. Already there is the answer, I hope they have helped you, but I keep my downvote for the reasons already mentioned

1 answer

4

First, it is important to set the page size correctly when creating it:

$pdf = new FPDF('P','mm',array(210,297)); // P = Portrait, em milimetros, e A4 (210x297)

The margins in the FPDF depend on the point of view you are dealing with. We have the logical margins, which are a reference to build the document, we have the automatic margin of the configurable footer, and the physical margins of the printer, which escape a bit of the question.


The logical margins you define by this function:

$pdf->SetMargins( 20, 20, 20, 20 );

However, nothing prevents you from moving out of the margins, depending on the drawing function you use.

This other setting causes an attempt to draw/write below a certain position on the screen to create a new page:

$pdf->SetAutoPageBreak(boolean auto, [float margin]);

In this case, you define whether you want to break automatically, and at what distance the footer will occur. Useful for generating reports, for example, without worrying about sheet size.

Important: If you want advanced margins for layout, as in a text editor, this depends exclusively on the logic of your software, using correctly the functions within the desired measures. Native FPDF functions are only for generating the basic page elements.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.