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 (^_^)/
Related
I wanted to show data with custom position. the currency is align left and the number align right.
So i'm trying to make a cell that looks like 1 cell but it's made of 2 cell .
Here is part of my code
$pdf->Cell(5, 10, ' $ ', 'L', 0, 'L');
$pdf->Cell(45, 10, $r_purchases_t['purchase_total'], 'R', 0, 'R');
It's result is this :
|$ 10,000.00|
Problem : It has no bottom border,how can i make custom cell border just left and bottom side ?
If possible, i want some code like $pdf->Cell(5, 10, ' $ ', 'L'||'B', 0, 'L');
SOLVED,
Apparently you can just combine border using , in border parameter.
So to add left and bottom border of the cell just using this code
$pdf->Cell(5, 10, ' $ ', 'L,B', 0, 'L');
$pdf->Cell(45, 10, ' $ '. $r_purchases_t['purchase_total'], 'L', 0, 'L');
Try This and adjust width of cell accordin to need.
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.
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?
I've have three cells and i'am trying to align the text to Left, Center and Right.
function Footer()
{
$this->SetY( -15 );
$this->SetFont( 'Arial', '', 10 );
$this->Cell(0,10,'Left text',0,0,'L');
$this->Cell(0,10,'Center text:',0,0,'C');
$this->Cell( 0, 10, 'Right text', 0, 0, 'R' );
}
When I ouput my PDF file, center text get automatically aligned right.
This is how it looks:
Can somebody tell me what I'm doing wrong here and how I can fix this issue?
The new position after a Cell call will be set to the right of each cell if you set the ln-parameter of the Cell method to 0. You have to reset the x-coordinate before the last 2 Cell calls:
class Pdf extends FPDF {
...
function Footer()
{
$this->SetY( -15 );
$this->SetFont( 'Arial', '', 10 );
$this->Cell(0,10,'Left text',0,0,'L');
$this->SetX($this->lMargin);
$this->Cell(0,10,'Center text:',0,0,'C');
$this->SetX($this->lMargin);
$this->Cell( 0, 10, 'Right text', 0, 0, 'R' );
}
}
Though Jan Slabon's answer was really good I still had issues with the center not being exactly centered on my page, maybe we have different versions of the library and that's what accounts for the slight differences, for instance he uses lMargin and on some versions that's not available. Anyway, the way it worked for me is this:
$pdf = new tFPDF\PDF();
//it helps out to add margin to the document first
$pdf->setMargins(23, 44, 11.7);
$pdf->AddPage();
//this was a special font I used
$pdf->AddFont('FuturaMed','','AIGFutura-Medium.ttf',true);
$pdf->SetFont('FuturaMed','',16);
$nombre = "NAME OF PERSON";
$apellido = "LASTNAME OF PERSON";
$pos = 10;
//adding XY as well helped me, for some reaons without it again it wasn't entirely centered
$pdf->SetXY(0, 10);
//with SetX I use numbers instead of lMargin, and I also use half of the size I added as margin for the page when I did SetMargins
$pdf->SetX(11.5);
$pdf->Cell(0,$pos,$nombre,0,0,'C');
$pdf->SetX(11.5);
//$pdf->SetFont('FuturaMed','',12);
$pos = $pos + 10;
$pdf->Cell(0,$pos,$apellido,0,0,'C');
$pdf->Output('example.pdf', 'F');
Seems that there is a parameter for this, so ('R' for right-aligning, 'C' for centering):
$pdf->Cell(0, 10, "Some text", 0, true, 'R');
will right align text.
Also, notice that the first parameter ('width') is zero, so cell has 100% width.
I want to create PDF using PHP and for this I am using FPDF. Now I want to add two images at top of PDF (one at left corner and one right). I am using following code for this,
Code:-
function Header () {
$this->Image('logo.png',10,20,33,0,'','http://www.fpdf.org/');
$this->SetFont('Arial', 'B', 20);
$this->SetFillColor(36, 96, 84);
$this->SetTextColor(28,134,238);
$this->Cell(0, 10, "Your Car Comparison Document", 0, 1, 'C', false);
$this->Cell(0, 5, "", 0, 1, 'C', false);
$this->Cell(0, 10, "Thanks for visiting CarConnect.", 0, 1, 'C', false);
$this->Cell(0, 5, "", 0, 1, 'C', false);
}
But when I add image code it will show 404 error on browser else it works properly.
I did the same thing last week. But an annotation:
404 error = page not found; your image or your path probably is wrong.
I used the following code with a image size of 20x10:
$imagenurl = "../imgs/incgaminglabs.png"; // in my case
// 1) left corner in coord x=1 and y=1
$pdf->Cell(0, 0, $pdf->Image($imagenurl, 1,1,20,10), 0, 0, 'C', false,'');
// 2) right corner in coord x=$pdf->GetX() - image width + 1 and y = $pdf->GetY() - image height + 1
$pdf->Cell(0, 0, $pdf->Image($imagenurl, $pdf->GetX()-20+1,$pdf->GetY()-10+1,20,10), 0, 0, 'C', false,'');
I hope it's works for you. Try changing the values.
The HTTP url is not looks proper image url, please use correct images url 'http://www.fpdf.org/logo.png' and the Image method params wrong, please see blow
//Image(string file [, float x [, float y [, float w [, float h [, string type [, mixed link]]]]]])
$this->Image('http://www.fpdf.org/logo.png',10,20,33,0);
$pdf->Image('PATH/logo.png',10,3,50);
Make sure that your img path is correct. Your script might lays in a different folder and gets included. In this case make sure you've choosen the right path.