How to make a table like this with fpdf using PHP? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How do you make a table like this with FPDF using PHP?
I can't seem to figure out how to do this with $this->Cell.

OK .. let's try. Just an example .. an idea. ok ?
$pdf->SetFillColor(255,0,0);
$pdf->SetTextColor(255);
$pdf->SetDrawColor(128,0,0);
$pdf->SetLineWidth(.3);
// Title row
$pdf->SetFont('', 'B');
$pdf->Cell(100, 8, "LEARNING POTENTIAL", 1, 0, 'L', true);
$pdf->SetFont('', '');
$pdf->Cell(20, 8, "Score", 1, 0, 'C', true);
$pdf->Cell(20, 8, "Results", 1, 0, 'C', true);
$pdf->>Ln();
// Data rows
// (loop) foreach($data as $row) {
$pdf->SetFont('', 'B');
$pdf->Cell(100, 8, "Reasoning", "LTR", 0, 'L');
$pdf->Cell(20, 8, "", "LTR");
$pdf->Cell(20, 8, "", "LTR");
$pdf->>Ln();
$pdf->SetFont('', 'B');
$pdf->Cell(100, 8, "The ability to interpret information and", "LR", 0, 'L');
$pdf->SetFont('', '');
$pdf->Cell(20, 8, "6", "LR");
$pdf->Cell(20, 8, "Effective", "LR");
$pdf->>Ln();
$pdf->SetFont('', 'B');
$pdf->Cell(100, 8, "drawing accurate conclusions", "LBR", 0, 'L');
$pdf->Cell(20, 8, "", "LBR");
$pdf->Cell(20, 8, "", "LBR");
$pdf->>Ln();
// (end loop)
I divided each data row in 3 rows.

Related

How to add a custom paper size on FPDF?

I am using FPDF to create a document. My problem is the paper size requirement is 8.5 by 13 inches. Is there a way to add a custom page size. I tried searching still no avail. When I used 'Legal' the printing is warped.
$pdf = new myPDF('P','in',[8.5,13]);
$pdf->AddPage('P', 'Legal', 0);
$pdf->SetMargins('15', '20', '15');
$pdf->SetFont('Arial', 'B', 12);
$pdf->Ln(5);
$pdf->Cell(0, 5, 'PAGE 1', 0, 1, 'C');
$pdf->AddPage('P', 'Legal', 0);
$pdf->Cell(0, 5, 'PAGE ', 0, 1, 'C');
As the documentation says, when you create the instance the 3rd parameter may be an array that specifies the width and height. So you may use:
$pdf = new myPDF('P','in',[8.5,13]);

Implode php array [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have an array like this:
$Array = [
[1, 33, 55, 18],
[8, 9, 12, 67],
[3, 33, 76, 88],
];
And I want add ; to output like this:
1, 33, 55, 18;
8, 9, 12, 67;
3, 33, 76, 88
Anyone know how to do this?
Use array map to achieve this
$temp = array_map(function($item){
return implode(", ", $item);
}, $Array);
foreach($temp as $v){
// implode with ';' and \n for line break
// you can use "<br/>" if you are using web.
echo $v.";\n";
}
Demo.
One looper:
foreach($Array as $v){
echo implode(", ",$v).";\n";
}
Demo.
Output
1, 33, 55, 18;
8, 9, 12, 67;
3, 33, 76, 88;

Radio button groups generated with TcPDF cutting off in adobe reader

I'm using TcPDF to generate a PDF file with radio button groups in it.
When one of these crosses over to the next page the labels remain but the radio button itself disappears. This only happens in Adobe Reader and not in any of my other readers like Firefox / Chrome / Foxit.
$this->ln(5);
$this->MultiCell(0, 5, '4. Question1', 1, 'L', 1, 1);
$this->Ln(3);
$val[$answers['v4']] = true;
$this->radio('v4', $val['good_verygood']);
$this->Cell(50, 0, 'Good/very good', 0, 0, 'L', 0);
$this->Cell(150, 0, '(= luxe)', 0, 1, 'L', 0);
$this->radio('v4', $val['above_average']);
$this->Cell(50, 0, 'Above average', 0, 0, 'L', 0);
$this->Cell(150, 0, '(= modernised)', 0, 1, 'L', 0);
$this->radio('v4', $val['average']);
$this->Cell(50, 0, 'Average', 0, 0, 'L', 0);
$this->Cell(150, 0, '(= on par)', 0, 1, 'L', 0);
$this->radio('v4', $val['moderate']);
$this->Cell(50, 0, 'Moderate', 0, 0, 'L', 0);
$this->Cell(150, 0, '(= not on par)', 0, 1, 'L', 0);
$this->radio('v4', $val['bad']);
$this->Cell(50, 0, 'Bad', 0, 0, 'L', 0);
$this->Cell(150, 0, '(= Needs short term maintenance)', 0, 1, 'L', 0);
$val[$answers['v4']] = false;
I've fixed one of these PDF's quickly by just adding a new page on the one question this happened
$this->addPage();
But now there are dozens of occurences in multiple PDF's.
I've found a solution.
Although I do not know why only Adobe has this problem and only if the group of buttons is on a page break, the problem is the name of the radio button.
In my example the buttons are all named v4.
If you name them v4.1 through v4.5 or other unique names, the PDF renders correctly.

How to create multi table side by side with fpdf

Can someone teach me how to create a table side by side like this with fpdf:
I'm trying to combine the multiple column with the creating table tutorial but failed. Any help would be appreciated. Thank you.
If you got struggled with fpdf, you can try to do it with Debenu Quick PDF.
This C# code returns the exact result which is on your picture. It is done with merged cells, but also you can use zero border width - it depends on your needs. Of course you can change the width and the color of the borders.
DPL.LoadFromFile("blank.pdf", "");
DPL.SetOrigin(1); //the top left page corner will be used for the origin
DPL.SetMeasurementUnits(0); //the units are approximately the same as a "point"
string content1, content2, content3;
content1 = "1<br>2<br>3<br>4<br>5<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>20";
content2 = "21<br>22<br>23<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>30";
content3 = "31<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>40";
int tableID1 = DPL.CreateTable(20, 3); //20 rows, 3 columns
DPL.SetTableColumnWidth(tableID1, 1, 1, 20); //width of the first column
DPL.SetTableColumnWidth(tableID1, 2, 3, 40); //width of the second and third column
DPL.SetTableRowHeight(tableID1, 1, 20, 10); //height of all rows
DPL.MergeTableCells(tableID1, 2, 1, 20, 1); //merge the cells from second row to 20. row and from 1. column to 1. column - merge the cells of the first column
DPL.MergeTableCells(tableID1, 2, 2, 20, 2); //merge the cells of the second column
DPL.MergeTableCells(tableID1, 2, 3, 20, 3); //merge the cells of the third column
DPL.SetTableCellContent(tableID1, 2, 1, content1); //add the content
DPL.DrawTableRows(tableID1, 50, 50, 700, 1, 0); //draw the table to the page
int tableID2 = DPL.CreateTable(20, 3); // second table
DPL.SetTableColumnWidth(tableID2, 1, 1, 20);
DPL.SetTableColumnWidth(tableID2, 2, 3, 40);
DPL.SetTableRowHeight(tableID2, 1, 20, 10);
DPL.MergeTableCells(tableID2, 2, 2, 20, 2);
DPL.MergeTableCells(tableID2, 2, 3, 20, 3);
DPL.MergeTableCells(tableID2, 2, 1, 20, 1);
DPL.SetTableCellContent(tableID2, 2, 1, content2);
DPL.DrawTableRows(tableID2, 160, 50, 700, 1, 0);
int tableID3 = DPL.CreateTable(20, 3); //third table
DPL.SetTableColumnWidth(tableID3, 1, 1, 20);
DPL.SetTableColumnWidth(tableID3, 2, 3, 40);
DPL.SetTableRowHeight(tableID3, 1, 20, 10);
DPL.MergeTableCells(tableID3, 2, 2, 20, 2);
DPL.MergeTableCells(tableID3, 2, 3, 20, 3);
DPL.MergeTableCells(tableID3, 2, 1, 20, 1);
DPL.SetTableCellContent(tableID3, 2, 1, content3);
DPL.DrawTableRows(tableID3, 270, 50, 700, 1, 0);
DPL.SaveToFile("tables.pdf");
You can find the description of the functions on this site:
http://www.debenu.com/docs/pdf_library_reference/CreateTable.php

Tcpdf multiple bookmarks on single page

Is it possible to have PDF with multiple Bookmarks on one page? I have a page with multipe tables, and each table need to be bookmarked. These tables may increase and go on next page.
The documentation supports explains how to do this here.
The syntax is as follows:
// Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0))
$pdf->AddPage();
$pdf->Bookmark('Paragraph 1.1', 1, 0, '', '', array(0,0,0));
$pdf->Cell(0, 10, 'Paragraph 1.1', 0, 1, 'L');
$pdf->Bookmark('Paragraph 1.2', 1, 0, '', '', array(0,0,0));
$pdf->Cell(0, 10, 'Paragraph 1.2', 0, 1, 'L');

Categories