【发布时间】:2013-11-13 06:04:37
【问题描述】:
我需要一个示例代码或参考,通过使用 itextsharp 动态读取签名字段名称将签名图像放置在签名字段中。图片应该放在签名字段的上方,签名字段的大小对应。有人可以帮我吗..
我正在尝试将签名图像放置在签名字段中,但图像未放置在签名字段中。签名字段矩形的宽度和高度不同,如果更改比例以适应,图像大小会有所不同。这是我的代码:
PdfContentByte pdfContentByte = stamper.GetOverContent(1);
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
iTextSharp.text.pdf.AcroFields fields = stamper.AcroFields;
IList<iTextSharp.text.pdf.AcroFields.FieldPosition> signatureArea = fields.GetFieldPositions("DoctorSign");
TextSharp.text.Rectangle rect = signatureArea.First().position;
image.ScaleAbsolute(rect.Width, rect.Height);
image.SetAbsolutePosition(rect.Left -image.ScaledWidth +(rect.Width -image.ScaledWidth )/2, rect.Bottom+ (rect.Height-image.ScaledHeight)/2 );
pdfContentByte.AddImage(image)
【问题讨论】:
-
嗨,Noctis..感谢您的即时回复。我正在尝试将签名图像放置在签名字段中,但图像未放置在签名字段中。签名字段矩形的宽度和高度不同,如果更改比例以适应,图像大小在这里得到不同我的代码
-
PdfContentByte pdfContentByte = stamper.GetOverContent(1);iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);iTextSharp.text.pdf.AcroFields fields = stamper.AcroFields;IList
signatureArea = fields.GetFieldPositions("DoctorSign");TextSharp.text.Rectangle rect = signatureArea.First().position;image.ScaleAbsolute(rect.Width, rect.Height); image.SetAbsolutePosition(rect.Left -image.ScaledWidth +(rect.Width -image.ScaledWidth )/2, rect.Bottom+ (rect.Height-image.ScaledHeight)/2 );pdfContentByte.AddImage(image); -
@raj 通常您应该向问题本身添加新信息。您可以添加评论来回答对这些信息的请求,并带有指向这些添加的指针。我在这里为你做的。话虽如此,为什么要更改页面内容而不是签名字段外观?
标签: c# pdf itextsharp