Why is there a left pad in the cell using FPDF in php?

I am printing a cell using the FPDF class ( http://www.fpdf.org/ ) in php. The cell should be placed in the upper left corner.

Everything works fine, except that a left pad is added to the cell.

Here is my code:

$pdf = new FPDF('L', 'mm', array(50.8,88.9)); $pdf->addPage('L', array(50.8,88.9)); $pdf->SetDisplayMode(100,'default'); $pdf->SetTextColor(0,0,0); $pdf->SetMargins(0,0,0); $pdf->SetAutoPageBreak(0); $pdf->SetFont('Arial','',8.5); $pdf->SetXY(0, 0); //sets the position for the name $pdf->Cell(0,2.98740833, "Your Name", '1', 2, 'L', false); //Name 

Here is a screenshot of the PDF that is output using FPDF:

Screenshot of PDF output with FPDF

Why is there a left padding in a cell using FPDF in php and how can I remove a padding?

+6
source share
6 answers

I know this is super old, but I had and fixed the same problem, so maybe someone will find it useful.

There is a property in the FPDF class called $ cMargin that is used to calculate the x offset of the text before it is printed inside the cell, but there is no setting tool for it. This is a public property, so after you instantiate your FPDF class, just call:

 $pdf = new fpdf('P','mm','A4'); $pdf->cMargin = 0; 

And your cells will no longer have this add-on on the left.

+12
source

Small patch fix

 <?php require("fpdf.php"); class CustomFPDF extends FPDF{ function SetCellMargin($margin){ // Set cell margin $this->cMargin = $margin; } } ?> <?php $pdf = new CustomFPDF(); $pdf->setCellMargin(0); ?> 
+3
source

I can not decide how to remove the gasket.

As a workaround, it’s useful to know that it is 1 mm, regardless of font size. The same addition is applied on the right edge with the text aligned to the right.

+1
source

I ran into the same problem. Only 1st line has this unwanted margin, so my workaround was this:

  $pdf->Ln(); //workaround for 1st line $pdf->Cell(..); 
+1
source

Have you tried running SetMargins(0,0) ?

Setmargins

SetMargins(float left, float top [, float right])

Description

Defines left, top, and right margins. By default, they are 1 cm. Call this method to change them.

http://www.fpdf.org/en/doc/setmargins.htm

0
source

Use SetMargins before AddPage

Example:

 $pdf=new PDF(); $pdf->SetMargins(23, 44, 11.7); $pdf->AliasNbPages(); $pdf->AddPage(); 
0
source

Source: https://habr.com/ru/post/891368/


All Articles