We are using the following basic code for signing the PDF:
ExternalSignature externalSignature = new ExternalSignature(certificate);
externalSignature.CustomAppearance = new Aspose.Pdf.Forms.SignatureCustomAppearance {
ShowContactInfo = false,
ShowLocation = false,
ShowReason = false
};
string inFile = System.IO.Path.Combine("Foo.pdf");
string outFile = System.IO.Path.Combine("FooSigned.pdf");
using (Document document = new Document(inFile))
{
using (PdfFileSignature signature = new PdfFileSignature(document))
{
signature.Sign(1, true, new System.Drawing.Rectangle(100, 100, 200, 100), externalSignature);
// Save output PDF file
signature.Save(outFile);
}
}
This adds the digital certificate with the default text: "Digitally signed by ‘{Subject Name}’
However, the subject name on the certificate is not concise so we need to change/regex/format the subject name to be more readable.
But there is no API to change the subject name or the value of the text.
Any solution or an API to resolve this would be helpful.
using Aspose.Pdf;
using Aspose.Pdf.Facades;
using Aspose.Pdf.Forms;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
using System.IO;
Setup
// Initialize license object
Aspose.Pdf.License license = new Aspose.Pdf.License();
try
{
// Set license
license.SetLicense("total.lic");
}
catch (Exception)
{
// something went wrong
throw;
}
var rawCert = File.ReadAllText("C:\\Dev\\cert.pfx");
var certificate = new X509Certificate2(
Convert.FromBase64String(rawCert),
"",
X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.UserKeySet);
ExternalSignature externalSignature = new ExternalSignature(certificate);
externalSignature.CustomAppearance = new Aspose.Pdf.Forms.SignatureCustomAppearance {
ShowContactInfo = false,
ShowLocation = false,
ShowReason = false
};
Work
string inFile = System.IO.Path.Combine("Foo.pdf");
string outFile = System.IO.Path.Combine("FooSigned.pdf");
using (Document document = new Document(inFile))
{
using (PdfFileSignature signature = new PdfFileSignature(document))
{
signature.Sign(1, true, new System.Drawing.Rectangle(100, 100, 200, 100), externalSignature);
// Save output PDF file
signature.Save(outFile);
}
}
We did some additional digging and found the following:
Seems that the certificate has x500 Subject string (IETF PKIX (latest version RFC 5280))
Aspose PDF library prints the entire Subject string.
However, we only need the Common Name (CN) printed.
We have logged the shared detail in our issue tracking system.
Currently, your issue is pending for analysis and is in the queue. Once we complete the analysis of your issue, we will then be able to provide you an estimate.
The issue has been logged under free support model and we are afraid that it has not been yet resolved. We will surely resolve and fix it on a first come first serve basis and let you know via this forum thread once we have some updates in this regard. Please spare us some time.