我已经创建了一个有图形的pdf文件,现在我试图在这些图形下添加一个表格。我的问题是表格是在图形上,我如何指定位置/位置,我希望我的表格放在PDF文件?如何在c#中使用iTextsharp指定PDF文件中表格的位置#
这是我的代码
docl.Open();
docl.Add(new Paragraph("My first PDF file"));
PdfContentByte cb = writer.DirectContent;
//employee
// position y,position x,length,height, unknown
cb.RoundRectangle( 20f, 745f, 200f, 35f, 10f);
//title
cb.RoundRectangle(235f, 745f, 35f, 35f, 10f);
//identity number
cb.RoundRectangle(280f, 745f, 105f, 35f, 10f);
//date of birth
cb.RoundRectangle(390f, 745f, 105f, 35f, 10f);
//employee number
cb.RoundRectangle(500f, 745f, 105f, 35f, 10f);
//address
cb.RoundRectangle(20f, 660f, 200f, 80f, 10f);
//pay method
cb.RoundRectangle(235f, 700f, 35f, 35f, 10f);
//brantch code
cb.RoundRectangle(235f, 660f, 35f, 35f, 10f);
//bank
cb.RoundRectangle(280f, 700f, 215f, 35f, 10f);
//account type
cb.RoundRectangle(500f, 700f, 105f, 35f, 10f);
//account number
cb.RoundRectangle(280f, 660f, 160f, 35f, 10f);
//pay point
cb.RoundRectangle(445f, 660f, 35f, 35f, 10f);
//date of payment
cb.RoundRectangle(506f, 660f, 90f, 35f, 10f);
//marital status
cb.RoundRectangle(20f, 600f, 35f, 35f, 10f);
//gender
cb.RoundRectangle(60f, 600f, 35f, 35f, 10f);
//date of appointment
cb.RoundRectangle(100f, 600f, 70f, 35f, 10f);
//Tax number
cb.RoundRectangle(175f, 600f, 70f, 35f, 10f);
cb.Stroke();
PdfPTable table = new PdfPTable(2);
table.HorizontalAlignment = 0;
table.SetTotalWidth(new float[] { 800, 200 });
PdfPCell cell = new PdfPCell(new Phrase("EARNINGS"));
cell.Colspan = 2;
cell.HorizontalAlignment = 1;
table.AddCell(cell);
table.AddCell("Description");
table.AddCell("Amount");
我使用这条线来指定文件上的图形的位置:未知 cb.RoundRectangle //位置y,位置x,长度,高度,(20F ,745f,200f,35f,10f);
我想表放置图形下方。
你可能想强调的是,这CodeProject上回答的焦点想法和你的代码是需要用'SpacingAfter添加一个空段落'在添加表之前匹配跳过高度的值。 – mkl
谢谢你的建议,其实我是iTextSharp的初学者,所有关于asp.net的。我已经尝试了这一点,也做了第一张没有边框和空头的表格。这样我就在我的项目中获得了我的要求。谢谢你一次收到评论我会在下次改善我的回答。 –