我使用PdfContentByte创建了矩形。现在我想在这个矩形中添加一个文本。我怎样才能做到这一点。如果有人有想法请与我分享。我的矩形代码是
Document doc = new Document(new Rectangle(570, 924f));
PdfWriter writer = PdfWriter.GetInstance(doc,Response.OutputStream);
PdfContentByte cb = writer.DirectContent;
cb.Rectangle(doc.PageSize.Width -90f, 830f, 50f,50f);
cb.Stroke();
答案 0 :(得分:8)
您正在绘制一个这样的矩形:
PdfContentByte cb = writer.DirectContent;
cb.Rectangle(doc.PageSize.Width -90f, 830f, 50f,50f);
cb.Stroke();
这与此Rectangle
:
Rectangle rect = new Rectangle(
doc.PageSize.Width - 90f, 830f,
doc.PageSize.Width - 40f, 880f);
您可以在此矩形内添加文字,如下所示:
ColumnText ct = new ColumnText(cb);
ct.SetSimpleColumn(rect);
ct.AddElement(new Paragraph("This is the text added in the rectangle"));
ct.Go();