如何使用iTextSharp的在PdfContentByte矩形添加文字? [英] How to add text in PdfContentByte rectangle using itextsharp?

查看:2137
本文介绍了如何使用iTextSharp的在PdfContentByte矩形添加文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用PdfContentByte创建矩形。现在我想这个ADDA矩形内的文字。我怎样才能做到这一点。如果任何人有想法,请与me.My长方形code分享的是

I have created rectangle using PdfContentByte. Now I want to adda text inside this rectangle. How can I do this. If anybody have idea please share with me.My rectangle code is

 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();

推荐答案

您正在绘制矩形是这样的:

解决方案
You are drawing a rectangle like this:

这相当于本长方形

This corresponds with this Rectangle:

您可以在此矩形像这里面添加文本

You can add text inside this rectangle like this:

 ColumnText ct = new ColumnText(cb);
 ct.SetSimpleColumn(rect);
 ct.AddElement(new Paragraph("This is the text added in the rectangle"));
 ct.Go();

这篇关于如何使用iTextSharp的在PdfContentByte矩形添加文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆