SetDrawColor() is behaving like SetFillColor() - php

SetDrawColor() supposed to color Cell frame but instead another color is rendering as background color. This is the whole code :-
$pdf = new FPDF();
$pdf->SetTextColor(103, 58, 183);
$pdf->SetDrawColor(0, 80, 180);
// Fourth Page --
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(0, 10, "Hello Santanu", 1, 1, 'C', true);
$pdf->Output('helo.pdf', 'D');

You should try using SetFillColor before drawing any cell because it's taking black as default.
$pdf->SetFillColor(0, 0, 0);

Related

FPDF - PHP - Different styles on center cell

My problem is that I have a center text in a cell and I want the word "Client:" in bold and the rest in regular, like is centered I cant print "client:" first and after that print the name, neither use "write" function because is centered, please help.
$pdf->SetTextColor(102, 106, 117);
$pdf->SetFont('Arial', 'B', 15);
$pdf->Cell(626,25,"Client: ".$name,0,0,'C',0);
We have to calculate position of centered text like follows:
require("fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetTextColor(102, 106, 117);
$fullCellWidth = $pdf->GetPageWidth();
$pdf->SetFont("Arial", "", 15);
$regularCell = "some name";
$regularWidth = $pdf->GetStringWidth($regularCell);
$pdf->SetFont("Arial", "B", 15);
$boldCell = "Client: ";
$boldWidth = $pdf->GetStringWidth($boldCell);
$centerIndentX = ($fullCellWidth - $boldWidth - $regularWidth) / 2;
$pdf->SetX($centerIndentX);
$pdf->Cell($boldWidth, 25, $boldCell, 0, 0, "L");
$pdf->SetX($centerIndentX + $boldWidth);
$pdf->SetFont("Arial", "", 15);
$pdf->Cell($regularWidth, 25, $regularCell, 0, 0, "L");
$pdf->Output();
The output PDF example - part of screenshot:

TCPDF Cell text uppercase and color change

I have an TCPDF file where i want to set 1 cell with fill-background color, and to change the text in that cell to Upper-Case and color to white
$pdf->SetFont($pdfFont, 'B', 10);
$pdf->SetFillColor(59,78,135);
$pdf->Cell(50, 6, Lang::trans('supportticketsclient'), 0, 1, 'L', true);
I know i have to add "strtoupper" for uppercase letters but don't know where, and SetTextColor or something similar to it, but when i set that
$pdf->SetTextColor(0,0,0);
My whole pdf color is changed.
you just need to use the same function to change the colour back to the original(or a new colour)
$pdf->SetFont($pdfFont, 'B', 10);
$pdf->SetFillColor(59,78,135);
$pdf->SetTextColor(0,0,0);
$pdf->Cell(50, 6, strtoupper(Lang::trans('supportticketsclient')), 0, 1, 'L', true);
$pdf->SetTextColor(255,255,255);//change back to black
I have the same problem on changing the text in a cell to Upper-Case..
What I did was convert it on my query
$appName = $row['appFname']." ".$row['appMname']. " ".$row['appLname'];
$appNameUPPER = strtoupper($appName);
then I used that variable on my cell
$pdf->Cell(179,26,''.$appNameUPPER.'', 'B','', 'C', '','','','','','B');
then it works! Try converting it on your query~
It's my first time to answer here hope it works on you (^_^)/

Fpdf Send To back Change order of Cell

How to send cell() to the back because it currently show to pdf based on order in the code. This is the example.
$pdf->SetXY(10, 20);
$pdf->SetFillColor(240);
$pdf->Cell(10, 10, '', 0, 1, 'L', true); // Show up 1st: Cell 1
$pdf->SetXY(10, 20);
$pdf-> SetFillColor(100);
$pdf->Cell(10, 10, '', 0, 1, 'L', true); // Show up 2nd: Cell 2
So, how can I set which Cell will come first/send to the back without follow the order?

FPDF - Drawing a line that's centred across the width

Im trying to produce a PDF document using the PHP FPDF library,
Im trying to draw a line horizontal over the page which is indented the same amount both on the left and right sides.
Im having real difficulty trying to accomplish this.
My code is as follows, any help would be greatly appreciated.
$pdf = new FPDF( 'P', 'mm', 'A4' );
$pdf->AddPage();
$pdf->SetDisplayMode(real,'default');
$pdf->SetFillColor(0,0,0);
$pdf->SetFont('Arial','B',16);
$pdf->Image('logo.jpg',20,10,50,33.3);
$pdf->SetDrawColor(188,188,188);
$pdf->Line(20,45,150,45);
Given a portrait, A4 page is 210mm wide, a simple bit of maths should help you resolve this:
$pdf->Line(20, 45, 210-20, 45); // 20mm from each edge
$pdf->Line(50, 45, 210-50, 45); // 50mm from each edge
This is given that your declaration is as you stated in your original question:
$pdf = new FPDF( 'P', 'mm', 'A4' ); // A4, portrait, measurements in mm.
Use the following -
$pdf = new PDF('P','mm','A4'); //Set PDF as Potrait
$pdf->Ln(4); //Break
$pdf->Line(startpoint, 45, endpoint-50, 45); //Set the line
$pdf->Ln(4); //Break

mPDF importing page from another document

I'm trying to create PHP document in PHP using mPDF library. I want to import the last page from another PDF document. According to document I use, the imported page is too small (it's on 1/3 of the page) or too big (I see only part of the page). Is there any way to make it fit?
My code:
$mpdf = new mPDF('', '', 0, '', 0, 0, 0, 0, 0, 0, 'L');
$mpdf->WriteHTML($html);
$mpdf->AddPage();
$mpdf->SetImportUse();
$pagecount = $mpdf->SetSourceFile('application/views/default/pdf/nabidka-design.pdf');
$tplId = $mpdf->ImportPage($pagecount);
$mpdf->UseTemplate($tplId);
$mpdf->Output();
Thanks for help
You have to set page format for output PDF file like this:
$mpdf = new mPDF('utf-8', 'A4', '8', '', 10, 10, 7, 7, 10, 10);
Change 'A4' on your PDF source file format.

Categories