有人可以教我如何使用fpdf并排创建表格:
我正在尝试将多列与创建表教程结合使用但是失败了。任何帮助,将不胜感激。谢谢。
答案 0 :(得分:1)
如果您对fpdf感到挣扎,可以尝试使用Debenu Quick PDF。 此C#代码返回图片上的确切结果。它由合并的单元格完成,但您也可以使用零边框宽度 - 这取决于您的需求。当然,您可以更改边框的宽度和颜色。
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");
您可以在此网站上找到相关功能的说明:
http://www.debenu.com/docs/pdf_library_reference/CreateTable.php