Signature value gets rotated on some landscape documents

Dear support,

We have some PDF documents with Landscape view that has some signature fields. We use Syncfusion PDF library to sign documents, but what it's happening, is that the signature value being placed in the fields is getting rotated.

I'm attaching the original document as well as the output document after signing the document. Also here is the code that I'm using to sign and fill signature fields.

//// Get the file data as binary

//var file = await _mediaFileService.GetMediaFileByIdAsync(doc.CurrentFileId);

//Load PDF document

PdfLoadedDocument loadedDocument = new PdfLoadedDocument(file.FileData);

//Gets the first page of the document

PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;

//Gets the first signature field of the PDF document

PdfLoadedSignatureField signatureField1 = loadedDocument.Form.Fields[currentSignatory.PdfFieldRef] as PdfLoadedSignatureField;


//Creates a certificate

Stream stream = new MemoryStream(userCert.CertificateFileData);

PdfCertificate certificate1 = new PdfCertificate(stream, model.CertificatePass);

signatureField1.Signature = new PdfSignature(loadedDocument, page, certificate1, currentSignatory.PdfFieldRef, signatureField1);

signatureField1.Signature.DocumentPermissions = PdfCertificationFlags.AllowComments | PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;

//Save the current graphics state

PdfGraphicsState state = signatureField1.Signature.Appearance.Normal.Graphics.Save();

PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 6);

PdfBitmap signatureImage;

if (userCert.SignatureImage != null)

{

//Draw image

RectangleF imageArea = new RectangleF(new PointF(0, 0), new SizeF(signatureField1.Signature.Bounds.Size.Width / 3, signatureField1.Signature.Bounds.Size.Height));

Stream signatureImageStream = new MemoryStream(userCert.SignatureImage);

signatureImage = new PdfBitmap(signatureImageStream);

signatureField1.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage, imageArea);

}


RectangleF textArea = new RectangleF(new PointF((signatureField1.Signature.Bounds.Size.Width / 3) + 2, 0), new SizeF(signatureField1.Signature.Bounds.Size.Width / (userCert.SignatureImage != null ? 3 : 1), signatureField1.Signature.Bounds.Size.Height));


signatureField1.Signature.ContactInfo = currentSignatory.StaffName;

signatureField1.Signature.Appearance.Normal.Graphics.DrawString(String.Format("{0} on {1}", signatureField1.Signature.ContactInfo, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss +03'00'").Replace("+0300", "+03\'00\'")), font, PdfBrushes.Black, textArea, new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top));

// Restore Graphics state

signatureField1.Signature.Appearance.Normal.Graphics.Restore(state);

//Save the document into stream

MemoryStream fileStream = new MemoryStream();

loadedDocument.Save(fileStream);


Appreciate your help.


Best regards,

Fady


Attachment: sample_document_original__signed_5ea49693.zip


2 Replies

IJ Irfana Jaffer Sadhik Syncfusion Team September 21, 2022 02:29 PM UTC

Hi Fady,


We were able to reproduce the reported behavior with the provided details in our end. currently we are validating on this and will provide the further details on September 23rd, 2022.


Regards,

Irfana J.



IJ Irfana Jaffer Sadhik Syncfusion Team September 26, 2022 01:54 AM UTC

Hi Fady,

A signature field or other form fields or annotations will be placed depending on the page rotation. Appearance for 0 degree left top position and 90 degree right top position and 180-degree right bottom and 270 degree left bottom position. This is our behavior of interactive field objects for rotated PDF documents. So, we updated the sample to meet your requirement by rotating the signature appearance look based on the page rotation angle. Please try the modified sample below on your end and let us know if you have any further assistance in this.

Sample: https://www.syncfusion.com/downloads/support/forum/177628/ze/ConsoleSample888955044.zip

Regards,

 Irfana J.


Loader.
Up arrow icon