Adding Font Colour by Settextcolor
Adding Font Colour by Settextcolor
<?Php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->SetFillColor(1,99,255); // input R ,G , B
$pdf->SetTextColor(255,254,254);// input R , G , B
$pdf->Cell(80,10,'Hello World!',1,0,C,true,'https://www.plus2net.com');
$pdf->Output('my_file.pdf','I'); // Send to browser and display
?>
Saving the PDF file
We used $pdf->Output('my_file','D'); to get output directly. This line will force
download to user machine as pdf file my_file.pdf. We can change this output to save the file
in local ( server ) side machine.
$pdf->Output('my_file.pdf','I'); // Send to browser and display
$pdf->Output('my_file.pdf','D'); // Force file download with name given
( name can be changed )
$pdf->Output('my_file.pdf','F'); // Saved in local computer with the file
name given
$pdf->Output('my_file.pdf','S'); // Return the document as a string.
Text string wrap into next line after reaching the border of the MultiCell. In case of Cell the text
crosses and flows out of the Cell border. MultiCell is used when we are not sure about the length of
the string to display.
$pdf->Ln(20);
$pdf->SetX(50);
$pdf->MultiCell(100,10,'Alignment = C',1,C,false);
$pdf->Ln(20);
$pdf->SetX(50);
$pdf->MultiCell(100,10,'Demo About MultiCell Alignment = J',1,J,false);
$pdf->SetX(50);
$pdf->MultiCell(100,10,'SetFillColor is not set, value =false',1,J,false);
$pdf->SetFillColor(1,255,255);
$pdf->Ln(20);
$pdf->SetX(50); // abscissa of Horizontal position
$pdf->MultiCell(100,10,'$pdf->SetFillColor(1,255,255);',1,C,true);
$pdf->SetFillColor(255,255,1);
$pdf->Ln(20); // Line gap
$pdf->SetX(50); // abscissa of Horizontal position
$pdf->MultiCell(100,10,'$pdf->SetFillColor(255,255,1);',1,C,true);
$pdf->SetFillColor(255,1,255);
$pdf->Ln(20);
$pdf->SetX(50);
$pdf->MultiCell(100,10,'$pdf->SetFillColor(255,1,255);',1,C,true);
We can control the starting point of MultiCell by using top margin and left margin. In the
example below we have displayed the X and Y position by reading the value using GetX and
GetY functions.
?Php
require('fpdf.php');
$pdf = new FPDF();
$pdf->SetLeftMargin(50); // before adding a page
$pdf->SetTopMargin(30); // before adding a page
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$h=15; // default height of each MultiCell
$w=100;// Width of each MultiCell
$y=$pdf->GetY(); // Getting Y or vertical position
$x=$pdf->GetX(); // Getting X or horizontal position
$pdf->MultiCell($w,$h,'X='.round($x).',Y='.round($y),LRTB,L,false);
$y=$pdf->GetY();
$x=$pdf->GetX();
$pdf->MultiCell($w,$h,'X='.round($x).',Y='.round($y),LRTB,L,false);
$y=$pdf->GetY();
$x=$pdf->GetX();
$pdf->MultiCell($w,$h,'X='.round($x).',Y='.round($y),LRTB,L,false);
$y=$pdf->GetY();
$x=$pdf->GetX();
$pdf->MultiCell($w,$h,'X='.round($x).',Y='.round($y).' ( Added more text
inside MultiCell for text to Wrap around )',LRTB,L,false);
$y=$pdf->GetY();
$x=$pdf->GetX();
$pdf->MultiCell($w,$h,'X='.round($x).',Y='.round($y),LRTB,L,false);