编辑我浏览了该链接,但根据我的理解,我已将代码更新为以下内容,但它在最终签名的pdf中提供了空的签名矩形,并且未包含"pdfStamper.AddDirectTemplateSimple(t,new PdfName("n2")) );因为它给了错误.新生成的pdf: https://takeafile.com/?f=gexatugotu var imageData = Path.Combine(_env.WebRootPath, ImagePathere); var image = Image.GetInstance(imageData); signatureAppearance.SignatureGraphic = image; BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); var layer2Font = new iTextSharp.text.Font(bf, 7, iTextSharp.text.Font.NORMAL); signatureAppearance.Layer2Font = layer2Font; signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION; var t = signatureAppearance.GetLayer(2); signatureAppearance.Layer2Text = "Digitally Signed by CN= Random User Name\n([email protected]) \nDate: 11-05-2020 16:06 IST\nLocation: Some city ,Some location, India \nReason: Add tamper proof layer on platform"; t.BoundingBox = rect; if (image != null) { t.AddImage(image, rect.Width, 0, 0, rect.Height, 0, 0); } Font font; if (layer2Font == null) font = new Font(); else font = new Font(layer2Font); float size = font.Size; Rectangle dataRect = null; Rectangle signatureRect = null; float MARGIN = 2; // origin is the bottom-left signatureRect = new Rectangle( MARGIN, MARGIN, rect.Width / 2 - MARGIN, rect.Height - MARGIN); dataRect = new Rectangle( rect.Width / 2 + MARGIN / 2, MARGIN, rect.Width - MARGIN / 2, rect.Height - MARGIN); if (rect.Height > rect.Width) { signatureRect = new Rectangle( MARGIN, rect.Height / 2, rect.Width - MARGIN, rect.Height); dataRect = new Rectangle( MARGIN, MARGIN, rect.Width - MARGIN, rect.Height / 2 - MARGIN); } // for (renderingMode == RenderingMode.GRAPHIC_AND_DESCRIPTION) { int runDirection = PdfWriter.RUN_DIRECTION_NO_BIDI; ColumnText ct2 = new ColumnText(t); ct2.RunDirection = runDirection; ct2.SetSimpleColumn(signatureRect.Left, signatureRect.Bottom, signatureRect.Right, signatureRect.Top, 0, Element.ALIGN_RIGHT); Image im = Image.GetInstance(image); im.ScaleToFit(signatureRect.Width, signatureRect.Height); Paragraph p = new Paragraph(); // must calculate the point to draw from to make image appear in middle of column float x = 0; // experimentation found this magic number to counteract Adobe's signature graphic, which // offsets the y co-ordinate by 15 units float y = -im.ScaledHeight + 15; x = x + (signatureRect.Width - im.ScaledWidth) / 2; y = y - (signatureRect.Height - im.ScaledHeight) / 2; p.Add(new Chunk(im, x + (signatureRect.Width - im.ScaledWidth) / 2, y, false)); ct2.AddElement(p); ct2.Go(); }如果我理解错误,请引导我,请提供解决方案. 解决方案而不是使用以下签名模式:PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION;我切换到下面,并创建了想要的图像外观. PdfSignatureAppearance.RenderingMode.GRAPHIC;I want to adjust width of added Image along with description while signing pdf using itextsharp library C#.My code below regarding setting image and descreption in signature: var pdfStamper = PdfStamper.CreateSignature(reader, os, '\0', null, true); var signatureAppearance = pdfStamper.SignatureAppearance; var imageData = Path.Combine(_env.WebRootPath, ImagePathere); var image = Image.GetInstance(imageData); signatureAppearance.SignatureGraphic = image; BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); signatureAppearance.Layer2Font =new iTextSharp.text.Font(bf, 7, iTextSharp.text.Font.NORMAL); signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION; signatureAppearance.Layer4Text = PdfSignatureAppearance.questionMark; signatureAppearance.Acro6Layers = false; signatureAppearance.Layer2Text = "Digitally Signed by CN= Random User Name\n([email protected]) \nDate: 11-05-2020 16:06 IST\nLocation: Some city ,Some location, India \nReason: Add tamper proof layer on platform";End result of this looks like this on pdf :Please help me in doing resize image in digital signature make description part bigger and symbol smaller, also want to remove signature valid text but green tick should stay.EDITI went through the link but I have updated my code to below as per my understanding but it is giving empty signature rectangle in end signed pdf and I did not include "pdfStamper.AddDirectTemplateSimple(t, new PdfName("n2"));" as it was giving error. New generated pdf: https://takeafile.com/?f=gexatugotu var imageData = Path.Combine(_env.WebRootPath, ImagePathere); var image = Image.GetInstance(imageData); signatureAppearance.SignatureGraphic = image; BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); var layer2Font = new iTextSharp.text.Font(bf, 7, iTextSharp.text.Font.NORMAL); signatureAppearance.Layer2Font = layer2Font; signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION; var t = signatureAppearance.GetLayer(2); signatureAppearance.Layer2Text = "Digitally Signed by CN= Random User Name\n([email protected]) \nDate: 11-05-2020 16:06 IST\nLocation: Some city ,Some location, India \nReason: Add tamper proof layer on platform"; t.BoundingBox = rect; if (image != null) { t.AddImage(image, rect.Width, 0, 0, rect.Height, 0, 0); } Font font; if (layer2Font == null) font = new Font(); else font = new Font(layer2Font); float size = font.Size; Rectangle dataRect = null; Rectangle signatureRect = null; float MARGIN = 2; // origin is the bottom-left signatureRect = new Rectangle( MARGIN, MARGIN, rect.Width / 2 - MARGIN, rect.Height - MARGIN); dataRect = new Rectangle( rect.Width / 2 + MARGIN / 2, MARGIN, rect.Width - MARGIN / 2, rect.Height - MARGIN); if (rect.Height > rect.Width) { signatureRect = new Rectangle( MARGIN, rect.Height / 2, rect.Width - MARGIN, rect.Height); dataRect = new Rectangle( MARGIN, MARGIN, rect.Width - MARGIN, rect.Height / 2 - MARGIN); } // for (renderingMode == RenderingMode.GRAPHIC_AND_DESCRIPTION) { int runDirection = PdfWriter.RUN_DIRECTION_NO_BIDI; ColumnText ct2 = new ColumnText(t); ct2.RunDirection = runDirection; ct2.SetSimpleColumn(signatureRect.Left, signatureRect.Bottom, signatureRect.Right, signatureRect.Top, 0, Element.ALIGN_RIGHT); Image im = Image.GetInstance(image); im.ScaleToFit(signatureRect.Width, signatureRect.Height); Paragraph p = new Paragraph(); // must calculate the point to draw from to make image appear in middle of column float x = 0; // experimentation found this magic number to counteract Adobe's signature graphic, which // offsets the y co-ordinate by 15 units float y = -im.ScaledHeight + 15; x = x + (signatureRect.Width - im.ScaledWidth) / 2; y = y - (signatureRect.Height - im.ScaledHeight) / 2; p.Add(new Chunk(im, x + (signatureRect.Width - im.ScaledWidth) / 2, y, false)); ct2.AddElement(p); ct2.Go(); }Kindly guide me if I have understood something wrong and please provide solution. 解决方案 Instead of using below signature mode:PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION;I switched to below and created the appearance I want with image. PdfSignatureAppearance.RenderingMode.GRAPHIC; 这篇关于在GRAPHIC_AND_DESCRIPTION模式C#.net中添加数字签名时,在Itextsharp中调整图像的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-25 04:54