Fpdf Send To back Change order of Cell - php

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?

Related

SetDrawColor() is behaving like SetFillColor()

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);

How can I add multiple rows in the same cell - PDF

I have a text which contains ±50 words. So I want to add it in the same cell
here is my code:
//header
$this->SetX(30);
$this->Cell(270, 20, "Suggested Improvement ",0, 0, 'C', true);
$this->SetX(300);
$this->Cell(270, 20, "Current Situation ",0, 0, 'C', true);
//data retrieved from DB
$this->Ln(20);
$this->SetTextColor(0);
$this->SetFillColor(19, 68, 160);
$this->SetLineWidth(0.25);
$this->SetX(30.5);
$this->Cell(269, 100,$row1['Suggested Improvement'], 1, 0, 'C', false);
$this->SetX(300);
$this->Cell(269.5, 100,$row1['Current Situation'], 1, 0, 'L', false);
But the problem is that the text is not filled in the cell, it is printed as one line, as it is shown here:
How can I make the text to start from the top right and to be filled in this block only?
Think you are using fpdf for php..
Have a look at MultiCell. There you can youse \n for line-break.
$this->MultiCell(100,8,"Line 1\n Line2");
You have to do the line-break on your own. Its not automaticly added.
Here you can check the witdh with GetStringWidth and add some line-breaks.

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 (^_^)/

Add padding to a cell in TCPDF

I have to make invoices with TCPDF. I have a logo on top of the pdf and the title of the company has to come right next to it.
Now i'm doing this:
$pdf->Image(__DIR__.'/../../../assets/img/logo.png', 15, 10, 10, 0);
$pdf->Cell(110, 0, 'Company', 0, 0, 'L', 0, '', 3);
But "Company" is on top of the logo now. Is there a way to add padding left on that cell?
Try using:
$pdf->Image(__DIR__.'/../../../assets/img/logo.png', 15, 10, 10, 0, null, null,'T');
documentation

how to increase width according to value count

First of all i am really sorry for my english. I try to explain my wanted. I use fpdf to make dynamic invoice in pdf. I have more than one product to add one invoice and i must list them sub-bottom. But products counts change in all invoices. Some invoice has 5 products but some invoice has 2 products. My problem is i use code below but all lines overrided.
$invoices_query = mysql_query("SELECT * FROM invoice_bookings WHERE invoice_code = '$invoice_code'");
while ($invoices = mysql_fetch_array($invoices_query)) {
$customers_name = $invoices['customer_name'];
$pdf->Ln(0);
$pdf->Cell(21,123,$invoice_number,0,0,'L',0); // empty cell with left,top, and right borders
$pdf->Cell(30,123,$customers_name,0,0,'L',0);
$pdf->Cell(20,123,$date,0,0,'L',0);
$pdf->Cell(20,123,$time,0,0,'L',0);
$pdf->Cell(30,123,$suburb_from,0,0,'L',0);
$pdf->Cell(34,123,$suburb_to,0,0,'L',0);
$pdf->Cell(10,123,'% ' . $tax_percent,0,0,'L',0);
$pdf->Cell(25,123,'$ ' . $invoice_price,0,0,'R',0);
}
You can see value of margin. It's 123 as you can see. I must increase this value to 132 for example. And for other product 142 i must make. For example there are 5 products in this invoice i must make like this ;
first 123
second 133
third 143
fourth 153
fifth 163
but i really don't know how can i do this.
As this. Add a counter, initialize it, and always incrase with 10.
$cnt = 123; //Init the counter
while ($invoices = mysql_fetch_array($invoices_query)) {
$customers_name = $invoices['customer_name'];
$pdf->Ln(0);
$pdf->Cell(21, $cnt, $invoice_number, 0, 0, 'L', 0); // empty cell with left,top, and right borders
$pdf->Cell(30, $cnt, $customers_name, 0, 0, 'L', 0);
$pdf->Cell(20, $cnt, $date, 0, 0, 'L', 0);
$pdf->Cell(20, $cnt, $time, 0, 0, 'L', 0);
$pdf->Cell(30, $cnt, $suburb_from, 0, 0, 'L', 0);
$pdf->Cell(34, $cnt, $suburb_to, 0, 0, 'L', 0);
$pdf->Cell(10, $cnt, '% ' . $tax_percent, 0, 0, 'L', 0);
$pdf->Cell(25, $cnt, '$ ' . $invoice_price, 0, 0, 'R', 0);
$cnt = $cnt + 10; //Incrase it in the loop.
}
NOTE
Do not use mysql functions, they are deprecated. Use mysqli or PDO instead.
Avoid sql injections by escaping your variables comes from outside, or use prepared statements.

Categories