Setting Sheet Margins in FPDF

-1

I have a problem with FPDF, I need to set 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 already been asked this in the forum send me the link that I will look at.

    
asked by anonymous 16.12.2014 / 19:26

1 answer

4

First, it's 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 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 baseboard, configurable, and the physical margins of the printer, which run away from the question.


The logical margins you define by this function:

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

However, there is nothing to stop you from moving outside 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 wrap, and at what distance the footer will occur. It is useful for generating reports, for example, without worrying about the size of the sheet.

Important : If you want advanced margins for layout , such as in a text editor, this depends exclusively on the logic of your software, . The FPDF native functions are only for generating the basic elements of the page.

    
16.12.2014 / 19:28