我在pdf文件上创建了两个表。现在我想把它们安排在水平位置。表1应位于页面左侧,表2应位于表1的正确位置。但是当Iam执行时,表1正确,但table2与table1.table 2不完全相同左对齐。如何将此表2与table1水平平行放置?
var doc1 = new Document(PageSize.A4);
PdfWriter.GetInstance(doc1, new FileStream(path + "/" + pdf_name + "", FileMode.Create));
doc1.Open();
var table1 = new PdfPTable(1); //table1
table1.HorizontalAlignment = Element.ALIGN_LEFT;
table1.SpacingBefore = 50;
table1.DefaultCell.Border = 1;
table1.WidthPercentage = 40;
PdfPCell cell = new PdfPCell(new Phrase(student_name, boldTableFont));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
table1.AddCell(cell);
doc1.Add(table1);
var table2= new PdfPTable(1); //table2
table2.DefaultCell.Border = 1;
table2.HorizontalAlignment = 2;
table2.SpacingBefore = 50;
table2.WidthPercentage = 40;
PdfPCell cell21 = new PdfPCell(new Phrase("success", body));
cell21.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table2.AddCell(cell21);
doc1.Add(table2);
doc1.Close();
答案 0 :(得分:1)
创建一个包含单行和两列的新表。
Place first table in the first row first column and second table in the first row second column
将第一列的对齐方式设为左侧,将另一条右侧对齐
希望这会有所帮助..