how to print a cell inside a cell using fpdf - php

I'm making some pdf document from php code using fpdf library. In that document i have created two cell like this
$pdf->Cell(100,100,"Text inside first column",1,0,'L');
$pdf->Cell(35,35,'Text inside second column ',1,0,'C');
above code works well, out put have two cells, first one has size of 100x100 and second has 35x35 , and second cell was just right to the first cell.
but i need to print that second sell inside the first cell
is there any way in fpdf ?
can anyone help me?

I'm not sure what you want exactly achive, but maybe this AddOn could help you to do this:
http://www.interpid.eu/fpdf-table
Other way would be moving the pointer, something like this:
$pdf->Cell(100,100,"Text inside first column",1,0,'L');
$pdf->SetX($pdf->GetX() - 35);
$pdf->Cell(35,35,'Text inside second column ',1,0,'C');

In Nested cell X-axis and Y-axis, I have achieved like this
`$pdf->Cell(190,20,"",1,0,'L');
$pdf->SetX($pdf->GetX() - 189);
$pdf->Cell(100,10,'First ',2,0,'L');
$pdf->Cell(90,10,'March/2020 ',2,0,'R');
$pdf->SetY($pdf->GetY() +5);
$pdf->Cell(100,10,'MCB,UBl Omni, HBL Konnect, Alfalah , Mobi Cash ',2,0,'L');
$pdf->SetY($pdf->GetY() +5);`enter code here`
$pdf->Cell(139,10,'third text he`enter code here`re ',2,0,'L');
$pdf->Cell(50,10,'Lahore',2,0,'R');`

Related

How to set conditional format to color each second row with phpspreadsheet

Does somebody know how set conditional format with phpspreadsheet that each second row is shadowed like in the picture below?
sorry, I had to delete all the data, but I think its clear what I've meant
As it looks like there is no "function" inside phpspreadsheet to color the background of each 2nd row(?). If somebody knows such an easy way I'm still interested. In the meantime see my own amateurish way:
As long as you have the variables $col and $rowNumber available somewhere inside your script you can loop thrue all lines and set a background color for all lines with an odd number. Even lines you could address with the "else part".
if ($rowNumber%2) {
$spreadsheet->getActiveSheet()->getStyle($col.$rowNumber)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('e2efda'); //e2efda
};

Cannot use L,R,C to align the box center, right or left on the pdf page

I am trying to write a PHP script to upload the data from the database to pdf page (FPDF) and I am trying to center the box which contains the data from the database on the pdf page but always I get an error saying "Use of undefined constant L - assumed 'L' (this will throw an Error in a future version of PHP) " Is there a solution for this, I guess I am doing some mistake while writing the code please help me with my problem.
Thanks in advance
If PHP gives the error 'Use of undefined constant X, assumed 'X', you are using the value as a constant, you need to enclose the value with quotes to use it as a string.
This is probably your current code:
$this->Cell(0,10,'Left text',0,0,L);
this is what it should be:
$this->Cell(0,10,'Left text',0,0,'L');
The alignment feature within the cell function is for text-alignment within the cell, not the cell alignment itself. http://fpdf.org/en/doc/cell.htm
As far as I know there is no method to align an object within the page. You should manually calculate the X position and set it before calling the method you are using. There are multiple ways to do this, but you could get the pageWidth, get the element width, substract the element width from the page width and devide by 2. That should be your X starting position for the element that needs to be centered.

PhpSpreadsheet conditional formatting cell (fill)

I have set theese conditions:
$objConditionalRed->setConditionType(conditional::CONDITION_CELLIS);
$objConditionalRed->setOperatorType(conditional::OPERATOR_LESSTHAN);
$objConditionalRed->addCondition('50');
$objConditionalRed->getStyle()->getFill()->setFillType(fill::FILL_SOLID);
$objConditionalRed->getStyle()->getFill()->getStartColor()->setARGB('FFFF0000');
$objConditionalRed->getStyle()->getFont()->setBold(true);
Font formating works well (even if I change getFill to getFont and color font, it works), however, cell would not fill if condition is met, what might be wrong?
Looks like the problem was, that I needed to use getEndColor() instead of getStartColor(),
if someone knows, why this one should be used, will be pleased to hear.
T.Y.

How to check if a cell has a bottom border with Phpexcel

How to check if a cell has a bottom border using PHPexcel? I am working on a very funky template the sales force of my company have assembled.
The lines could go on and on inside the "Why?" block so that is why I need to check for that last bottom border to move on in my loop.
Example:
This will check the entire G column until it is empty
NumCells = Range("G" & Rows.Count).End(xlUp).Row +1
If Range("G" & NumCells).Borders(xlEdgeBottom).LineStyle = xlContinuous Then
*Continue with code
I ended up using something like this (didn't really find the bottom border a reliable solution). This will just simply grab the data inside of the following cell ranges (B25:B29):
$objPHPExcel->setActiveSheetIndex($sheetIndex)->rangeToArray('B25:B29');

TCPDF: Two Independent Columns with page break

I want to create a page with 2 independent columns. If the text does not fit in one colum on one page it should be continued on the next page with the same column setup.
I tried using setColumnsArray and selectColumn the problem with this is, that if the first column is full it continues on the next column instead on the next page.
It there a posibility to achive this?
Thank You
See Sample10 which is doing exactly what you are asking for:
PHP Source code: http://www.tcpdf.org/examples/example_010.phps
Final PDF: http://www.tcpdf.org/examples/example_010.pdf
Sample7 might help too but column spreads over multiple pages:
PHP Source code: http://www.tcpdf.org/examples/example_007.phps
Final PDF: http://www.tcpdf.org/examples/example_007.pdf
I solved the problem now without writing everything in html.
I used to following aproache:
Save the top of the columns with getY and getPage.
Write the first column
Use setY and setPage to go back to the top of the second column
Use setX to move the seconds column on the right side.
Using the following hack to get around the problem with different page borders on right and left pages on the second column:
if ($curPage<>$pdf->getPage())
{
$curPage=$pdf->getPage();
if (($curPage % 2)==1)
{
$xPos+=15;
}
else
{
$xPos-=15;
}
}
$pdf->SetX($xPos);

Categories