Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Oct 29, 2020 4:06 am

I am facing the same issue. I have added the trial license key from the license file. I have to add one digital signature on multiple pages of the pdf file.
I have added a digital signature on each page of the pdf but when I open the pdf file it gives me an error like the attached screenshot.
Also, I have tried multiple ways but still, I am getting an error as "Signature Invalid, document altered". in this pdf only the last signature gets a valid signature, and remaining all other gets invalid.
Here is my code:-

Spire.License.LicenseProvider.SetLicenseKey("hIcUAQC31x1UZ5MB2N5VWWmr2FU/T+GIE2gY92ZqC4Y7iHiUuRemaFvaXlTGOvc8MJAaGUawQyLmtc9/TLzSJ/eV7t8wZg61kRZs38ZU94EjTGYeNvOY9lPLG7o9viDU3bR8z290sO6j+J5sPyECEMgEcDIMxiWoYGiDlAQCxcl+e5t07ohhC8kaK9rSG7/+eWjgV8/L79MhUvIv1lPesjBWZ+ODNeAbtfLt0uAbOTfKYbJJS80WROgDhJjXxI8Q295itpa38Rsl/UJPjxteiwtCjbVUftt5/GORb468R11bk0N/SF4NPrdp5aiHDKnctVDwdKdgt7+JQom6Ia8D1dekCieIDzc8M4vw5V7y4gi5mLHRfoVksT+dc6u5vUJMKfr+SJfYTYuIah04PFzWLR1hMoj+21gCIFQXkjOafKLjIr1jAvO0sEL6vaTFCErUS9OO4B9qwlOwWkTQ5pXqoxZplTjQ0sFaipaczId5sXv6etRZcSa8vD5pVsMz3isnRZtVK4QBn75l9hP4BUUiJwN+BlU8h8C1M4bhGs3aPIKl89kGDdvC7IIH0o6y03wq90MG1dye9msPMh0GYi9ixhhVhK9un2/OOACPg/Lgoy7nlP8ulyX7WQ+ymlYit9krliLjpndP5XBE6sjA9XNFYpPiEepiiWtkLjEBsoXRu6LucLjPAdO3q9UH9qLlbApMGdvz3QBALJwi+9pRY9S5U5jtrT+2PAWkIqLktJZIo81KMAie1wzVGScdphvURsPgv3geVDrAcZjkP+O+sPIM3CxUi1RfBSyh2+kVZoPaFbLYcPvt8KAjdeArqG+3r4pdoLz3803RIq5Sj/2W116NciUtqHmVri1VUc2xbOiIKkPMLb+KM+Yr2c9XpwpVymuH5Q2qq6FPFDBgPlDnuoCjoWu9WQlUGf229TiunFhvlaaChOBw7MN5a0xV76m7vi5pEUksXDa6O0xmQPqfydhGLV7rrs9axwqN7I16+zYyvZn8ewDa8zZY0sQn5LF6N1MZSVTpI1vvZAldncfXvZADHHw+wn/n/ng8nZVLFbo2JNZS+zDKunrktjbQTTPIRcCKbJ3OYHPPKv54yUMwdC2EYhWEdMgVI984iCmyhP91y8wS4P0cGADIGI3QLYSK3nxxrOaxTnxxwLfixNE4HqJRfa+jcxTZE8e95SB/4Eq04rvgNtwZRc6tVkfOmJLZ+/jFXvBiWGczH0M8IRVzBarWH/7p3cGNLySm2Cl1qyHaAnNjhxKyJg18Hp5Bbt5OwKMLtH8RUcBQn5mkq/mLcZW1lAz+o2LgpnrLWxHCmlvfJGH1Uy61qXAYpPUS9UgydpNAKqPE4I2DJ5xAZXQqmBSCgmWgqtP+R9ePx6zlJnk22+luWibVIoGeGEhjrlwjLlSpT+xHEigNaDV4OB3ER1uC9hDJoboj+KzBT3wP8tjU35Llz2hvDZHMQbSg47Bnh+yC5uCG/Y6FIk3sJCK25sYGdeFbJRaeShpiLurHO1Z7/i4mMYQckpP9iQ==");
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(inputFileName);
// PdfCertificate cert = new PdfCertificate(digitalID);
//cert.Import(scollection);
int PageCount = doc.Pages.Count;
MemoryStream ms = new MemoryStream();

for (int x = 0; x < PageCount; x++)
{

PdfCertificate cert = new Spire.Pdf.Security.PdfCertificate(digitalID);
var signature = new PdfSignature(doc, doc.Pages[x], cert, "DigitalSignature1");
signature.Bounds = new RectangleF(new PointF(380, 740), new SizeF(230, 80));
signature.ContactInfo = "DigitalSignature1";
signature.IsTag = true;
signature.Name = "KARAN";
signature.DigitalSignerLable = "Digitally signed by ";
signature.DigitalSigner = "Karan Gophane";

signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "PUNE";

signature.ReasonLabel = "Reason: ";
signature.Reason = "AUTHORISED";

signature.DateLabel = "Date: ";
signature.Date = DateTime.Now.Date;
signature.Certificated = false;
signature.SignInfoFont.Add(SignInfoType.SignInformation, new PdfFont(PdfFontFamily.TimesRoman, 8f, PdfFontStyle.Regular));

signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;


doc.SaveToStream(ms, FileFormat.PDF);
doc = new PdfDocument(ms);
doc.LoadFromStream(ms);


}

doc.SaveToStream(ms, FileFormat.PDF);
File.WriteAllBytes(outputFileName, ms.ToArray());

karangophane
 
Posts: 7
Joined: Fri Oct 23, 2020 4:37 am

Thu Oct 29, 2020 8:53 am

Hello

Thanks for your inquiry.
I tested your case with the latest Spire.PDF Pack(Hot Fix) Version:6.10.9, but did not reproduce your issue. Here I uploaded my testing project. you can run it directly.

To help us further investigate your issue, please provide us with following information.
1) Your source PDF file, your certificate, and the password.
2) The OS information and Region setting (e.g. Windows 7, 64bit, China/Chinese).
3) The project target framework (e.g. .NET Framework 4.5).
You can send them to us ([email protected]) via email. Thanks in advance for your assistance.

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Thu Oct 29, 2020 11:56 am

Hello,

I have checked your code. I add a certificate then it is working fine.
I am using a smart card for adding the digital signature into a pdf file instead of a .pfx file.
Is there any issue with the smartcard?
Please give me a solution for reading certificate details from the smartcard (USB).
Is there any method to export the .pfx file from a smartcard (USB) or directly we can add digital ID into our code?

karangophane
 
Posts: 7
Joined: Fri Oct 23, 2020 4:37 am

Fri Oct 30, 2020 4:48 am

Hello,

Here I have attached my testing pdf file.

I export my pdf file from the crystal report first and then add an input file for this.
Please test this PDF.

Crystal to PDF Conversion Code:-
string strReportName = "";
strReportName = @"F:\Invoice.rpt";
orpt = new ReportDocument();
orpt.Load(strReportName);
orpt.Refresh();
orpt.SetParameterValue(0, DocEntry);
ConnectionInfo crConnection = new ConnectionInfo();
crConnection.UserID = "username";
crConnection.ServerName = "servername";
crConnection.DatabaseName = "databasename";
crConnection.Password = "password";
orpt.SetDatabaseLogon(crConnection.UserID, crConnection.Password, crConnection.ServerName, crConnection.DatabaseName);

string FilePath = @"F:\Invoice_" + DateTime.Now.ToString("ddMMyyyy") + "_" + DateTime.Now.ToString("hhmmss") + "_" + DocNum + ".pdf";
ExportOptions CrExportOptions;

DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = FilePath;
CrExportOptions = orpt.ExportOptions;
{
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;

CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
orpt.Export(CrExportOptions);

after this, I used "FilePath" as an input pdf path for digital signature.
Is there any issue in converting the pdf?

karangophane
 
Posts: 7
Joined: Fri Oct 23, 2020 4:37 am

Fri Oct 30, 2020 9:24 am

Hi karangophane,

Thank you for providing your documents.
Regarding reading certificate details from the smartcard (USB), below is the corresponding code for your reference. And I did an initial test with your PDF file, I did find the signatures of the generated PDF are invalid. I have posted this issue to our Dev team with the ticket SPIREPDF-3731 for further investigation. If there is any update, we will let you know.
Sorry for the inconvenience caused.

Code: Select all
                X509Store store = new X509Store(StoreLocation.CurrentUser);
                store.Open(OpenFlags.ReadOnly);
               //Find the certificate based on the information of the certificate stored in the USB
                X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindByThumbprint, "F9B500AD95CDA70CD5157C3A1DF8C35049C3BEF0", false);
                X509Certificate2 cert = certs[0];
                PdfCertificate pdfcert = new PdfCertificate(cert);


Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Fri Oct 30, 2020 9:40 am

Hello,

Thanks for your reply.

Please give me best solution for this. I have generated that pdf file from crystal report.
For this I have already shared code with you.

Please let me know if any.

karangophane
 
Posts: 7
Joined: Fri Oct 23, 2020 4:37 am

Fri Oct 30, 2020 10:00 am

Hello,

Ok, our Dev department will conduct further investigations on the above issues. We will keep you informed if there is any progress.

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Tue Nov 03, 2020 10:23 am

Hello,

Is any update on this?

karangophane
 
Posts: 7
Joined: Fri Oct 23, 2020 4:37 am

Wed Nov 04, 2020 3:01 am

Hello,

Thanks for your post.
I just checked the status of your issue but found it has not been resolved. Please spare us more time. I will keep you informed regarding any available updates. Thanks for your understanding.

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Return to Spire.PDF