Digitally sign PDF file which is rotated using Aspose.PDF for .NET

Hello,
I’ve written a code to digitally sign PDF document using “Sign” method of “PdfFileSignature” class. I’m using below overload for the same:
//public void Sign(int page, bool visible, System.Drawing.Rectangle annotRect, Signature sig);

It works absolutely fine on a normal PDF document. If document is rotated by 90 degree or 270 degree, then the digital signature doesn’t get printed on the document at correct location.
I used “RotationMatrix.Transform” function to get the correct co-ordinates of a rectangle which is to be passed as a parameter to “Sign” method. Still I’m not able to get the digital signature printed at correct location. Here printed digital also gets rotated by the same angle. Could you please advice the correct method or code to handle this situation ?

Thanks & regards,
Mandar

@mandarkaspose

Would you please share your sample PDF document along with complete code snippet. We will test the scenario in our environment and address it accordingly.

Thank you asad.ali for your response. Please see attached .zip file named DigitallySignbyAspose.zip.

DigitallySignbyAspose.zip (462.1 KB)

This .zip file contains 2 files as below:-

  1. CodeSnippetForAspose.txt
  2. TestDocRotatedby270.pdf

Thank you,
Mandar

@mandarkaspose

Thanks for sharing the sample file and code snippet.

We have checked the code snippet that you have shared and we were unable to execute it as it has some undefined objects e.g. shape. Would you please share complete sample code snippet which we can run without error and which is able to reproduce the issue. This would help us investigating the scenario accordingly.

Thank you Asad Ali!
I’ve attached fully executable code which demonstrates the difference between: digitally signing normal PDF file and a rotated PDF file. The question is with respect to the location and the way signature is being printed on PDF file. I’ve provided 3 sample PDF files, one is normal, one is rotated by 90 degree angle and one is rotated by 270 degree angle. Please sign all three documents and see the output PDF file. Even through Ive kept the location of the signature same, the signature is getting printed at different locations and also signature is flipped. My requirement is: even though document is rotated by any angle, the signature should be printed at the same location without flipping.

Note: Attached file is SignRotatedPDF.zip. Upon unzipping there are sample input PDF files and a source code. Before executing the code, please provide your digital certificate (.pfx) path with password at line number 58 and 60 in Form1.cs file.

Because of upload file size limitation, I’ve removed Aspose.PDF.dll (version 20.5.0.0) from project reference. Please add reference of this library to the project.
SignRotatedPDF.zip (512.6 KB)

Also I’ve provided sample output PDF files in “sample_output” folder of the project directory which are digitally signed documents. These output PDF files are 1. Normal(No Rotation) 2. Rotated by 90 degree 3. Rotated by 270 degree. These sample output files are for your reference to see how the signatures are printed.

Steps to execute:-

  1. Launch project and executable
  2. Browse desired input file
  3. Click on “SIgn PDF” button
  4. Open Output PDF file to see the output.

Please let me know if you face any issues in executing this project.

Thank you,
Mandar

@mandarkaspose

Thanks for sharing sample project along with further explanation.

We have been able to reproduce the issue in our environment which you are facing. We have used Aspose.PDF for .NET 20.7 for testing. A ticket as PDFNET-48573 has been logged in our issue tracking system for the sake of investigation of your requirements. We will further look into feasibility of required functionality and keep you informed about status of the logged-ticket. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hello,
Please let us know if you have any updates on ticket PDFNET-48573.

Thank you.

@mandarkaspose

The ticket is not yet resolved sadly. Please note that it will be investigated and resolved on first come first serve basis. We will inform you as soon as we have some progress update regarding its resolution. Please give us some time.

Hello,
Sorry to bother you again, as we badly need this ticket PDFNET-48573
to be resolved as early as possible.

Being paid customer of “ASPOSE TOTAL for .NET” since 2018, we’ve been using ASPOSE in our core product. Due to this issue our customers are impacted, and they are not able to use “Digital Sign” feature at all.
Please consider this request on priority.
Also please let me know if you need our ASPOSE licensing details in order to expedite the process.

Thank you.

@mandarkaspose

We do realize your concerns and will surely consider them during investigation of the logged issue. We have escalated the issue priority to next level by keeping your concerns in view. As soon as its investigation is completed, we will share updates with you. We highly appreciate your patience in this matter. Please spare us some time.

We apologize for your inconvenience.

Thank you for taking this ticket on priority.

Do we have any updates on it? Can you please give timeline so that we can convey the same to our customers ?

@mandarkaspose

At the moment, the investigation against the issue is not complete and we regret that we cannot share any ETA before it is done. However, we will surely review it and provide you an update as soon as we have some. We highly appreciate your patience and comprehension in this regard. Please spare us some time.

We are sorry for the inconvenience.

Please let us know if there are any updates on PDFNET-48573.

@mandardynabic

We have investigated the earlier logged ticket and would like to suggest you to try using following code snippet and let us know if you still face any issue:

PdfFileSignature pdfSign = new PdfFileSignature();
string sInputPDF = "48573-in.pdf";
pdfSign.BindPdf(sInputPDF);
var doc = new Document(sInputPDF);
string strCertificateFile = "48573.pfx";
//provide your digital certificate password
string passwordOfCert = "aa";
PKCS7 sigType = new PKCS7(strCertificateFile, passwordOfCert);
Page page = doc.Pages[1];
SignatureCustomAppearance signatureCustomAppearance = new SignatureCustomAppearance();
signatureCustomAppearance.FontSize = 6;
signatureCustomAppearance.FontFamilyName = "Times New Roman";
switch (page.Rotate)
{
 case Rotation.on90:
    signatureCustomAppearance.Rotation = Rotation.on270;
    break;
 case Rotation.on180:
    signatureCustomAppearance.Rotation = Rotation.on180;
    break;
 case Rotation.on270:
     signatureCustomAppearance.Rotation = Rotation.on90;
     break;
}
sigType.CustomAppearance = signatureCustomAppearance;
Aspose.Pdf.Rectangle r = new Aspose.Pdf.Rectangle(0,0,200,200);
r = page.RotationMatrix.Reverse().Transform(r);
pdfSign.Sign(1, true, r.ToRect(), sigType);
pdfSign.Save("48573-signed.pdf");

Thank you for your response!

I’ve tried this code with the latest Aspose.PDF version 20.9.0.0. But this library doesn’t have a definition of “signatureCustomAppearance.Rotation” property.
Could you please let us know which version of Aspose.PDF you are using ?

@mandarkaspose

We apologize for the confusion.

The mentioned property has been added in 20.10 version of the API which will be available next month. Once the new version is published, you will be able to use it.

Thank you for the sample code. We were able to download latest ASPOSE.PDF version 20.10 and the position of the signature is fixed now along with the correct signature angle.
Now the certificate text like “signed by”, “date” is still getting printed vertically. Please see attached screenshot and let us know the solution. thank you.

Screenshot 2020-10-15 at 2.42.35 PM.png (115.3 KB)

@mandardynabic

Thanks for your feedback.

We have updated the information of previously logged ticket and will further check it. Will inform you as soon as we have some results against our investigation. Please give us some time.

We apologize for the inconvenience.

@mandardynabic

We have logged a new ticket as PDFNET-48910 in our issue tracking system for vertical text strings inside signatures. We will let you know as soon as it is resolved. Please give us some time.

We are sorry for the inconvenience.