BoldDesk®Customer service software offering ticketing, live chat, and omnichannel support, starting at $49/mo. for 10 agents. Try it for free.
Hello,
I am following example on how to digitally sign the document. Everything works as expected except for the signature placement. The code below properly creates a signature but places it in upper left corner of the document (0,0) instead of coordinates specified:
// Load the PDF document.
FileStream docStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
// Get the loaded form
PdfLoadedForm loadedForm = loadedDocument.Form;
// Load the form field collections from the form.
PdfLoadedFormFieldCollection fieldCollection = loadedForm.Fields as PdfLoadedFormFieldCollection;
PdfLoadedField loadedField = null;
// Create PDF graphics for the page
PdfGraphics graphics = loadedDocument.Pages[0].Graphics;
// Creates a certificate instance from PFX file with private key
FileStream certificateStream = new FileStream(ConfigManager.Instance().GetValue(DefaultEnum.PdfCertificate), FileMode.Open, FileAccess.Read);
PdfCertificate pdfCert = new PdfCertificate(certificateStream, ConfigManager.Instance().GetValue(DefaultEnum.PdfCertificatePassword));
// Creates a digital signature
PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], pdfCert, "Signature");
// Sets an image for signature field.
FileStream imageStream = new FileStream(ConfigManager.Instance().GetValue(DefaultEnum.PdfCertificateSignature), FileMode.Open, FileAccess.Read);
// Sets an image for signature field.
PdfBitmap signatureImage = new PdfBitmap(imageStream);
// Sets signature information
signature.Bounds = new RectangleF(new PointF(0, 0), signatureImage.PhysicalDimension);
signature.ContactInfo = "xxx@lakecouxxxntyin.org";
signature.LocationInfo = "abc, CA";
signature.Reason = "I am authorized to sign this document.";
// Draws the signature image
graphics.DrawImage(signatureImage, 1.29f, 8.66f);
I appreciate any help in resolving this issue. Many thanks in advance!
Hi Mark,
We can specify the location of the signature field using the bounds property available in the PdfSignature instance. We have updated the code for your reference. Please try this on your end and let us know if you need any further assistance.
// Load the PDF document. FileStream docStream = new FileStream(Server.MapPath("~/App_Data/Input.pdf"), FileMode.Open, FileAccess.Read); PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
// Get the loaded form PdfLoadedForm loadedForm = loadedDocument.Form;
// Load the form field collections from the form. PdfLoadedFormFieldCollection fieldCollection = loadedForm.Fields as PdfLoadedFormFieldCollection; PdfLoadedField loadedField = null;
// Create PDF graphics for the page PdfGraphics graphics = loadedDocument.Pages[0].Graphics;
// Creates a certificate instance from PFX file with private key FileStream certificateStream = new FileStream(Server.MapPath("~/App_Data/pdf.pfx"), FileMode.Open, FileAccess.Read); PdfCertificate pdfCert = new PdfCertificate(certificateStream, "password123");
// Creates a digital signature PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], pdfCert, "Signature");
// Sets an image for signature field. FileStream imageStream = new FileStream(Server.MapPath("~/App_Data/syncfusion.jpg"), FileMode.Open, FileAccess.Read);
// Sets an image for signature field. PdfBitmap signatureImage = new PdfBitmap(imageStream);
// Sets signature information signature.Bounds = new RectangleF(new PointF(100, 100), signatureImage.PhysicalDimension); signature.ContactInfo = "xxx@lakecouxxxntyin.org"; signature.LocationInfo = "abc, CA"; signature.Reason = "I am authorized to sign this document.";
// Draws the signature image signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, signature.Bounds.Width, signature.Bounds.Height); |
In this above code we placed the signature at the position of x=100 and y=100 and drawn the image to the signature appearance instead of the PDF page graphics.
Regards,
Jeyalakshmi T
Hello Jeyalakshmi,
This was exactly it! Many thanks again for prompt reply and solution.
We are glad to hear, please get back to us if you need any further assistance on this. We always happy to assist you.