diff --git a/Digital Signature/Create-LTV-when-signing-PDF-documents-externally/.NET/Create-LTV-when-signing-PDF-documents-externally/Data/Input.pdf b/Digital Signature/Create-LTV-when-signing-PDF-documents-externally/.NET/Create-LTV-when-signing-PDF-documents-externally/Data/Input.pdf index 6d10bb53..4de703ac 100644 Binary files a/Digital Signature/Create-LTV-when-signing-PDF-documents-externally/.NET/Create-LTV-when-signing-PDF-documents-externally/Data/Input.pdf and b/Digital Signature/Create-LTV-when-signing-PDF-documents-externally/.NET/Create-LTV-when-signing-PDF-documents-externally/Data/Input.pdf differ diff --git a/Digital Signature/Create-LTV-when-signing-PDF-documents-externally/.NET/Create-LTV-when-signing-PDF-documents-externally/Program.cs b/Digital Signature/Create-LTV-when-signing-PDF-documents-externally/.NET/Create-LTV-when-signing-PDF-documents-externally/Program.cs index d18574ed..c6ad637e 100644 --- a/Digital Signature/Create-LTV-when-signing-PDF-documents-externally/.NET/Create-LTV-when-signing-PDF-documents-externally/Program.cs +++ b/Digital Signature/Create-LTV-when-signing-PDF-documents-externally/.NET/Create-LTV-when-signing-PDF-documents-externally/Program.cs @@ -13,14 +13,9 @@ //Load an existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); -//Get the page of the existing PDF document. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Create a new PDF signature without PdfCertificate instance. -PdfSignature signature = new PdfSignature(loadedDocument, loadedPage, null, "Signature1"); - -//Hook up the ComputeHash event. -signature.ComputeHash += Signature_ComputeHash; +//Gets the first signature field of the PDF document +PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; +PdfSignature signature = signatureField.Signature; //Create X509Certificate2 from your certificate to create a long-term validity. X509Certificate2 x509 = new X509Certificate2(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion"); @@ -37,23 +32,3 @@ //Close the document. loadedDocument.Close(true); - -void Signature_ComputeHash(object sender, PdfSignatureEventArgs ars) -{ - //Get the document bytes - byte[] documentBytes = ars.Data; - - SignedCms signedCms = new SignedCms(new ContentInfo(documentBytes), detached: true); - - //Compute the signature using the specified digital ID file and the password - X509Certificate2 certificate = new X509Certificate2(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion"); - CmsSigner cmsSigner = new CmsSigner(certificate); - - //Set the digest algorithm SHA256 - cmsSigner.DigestAlgorithm = new Oid("2.16.840.1.101.3.4.2.1"); - - signedCms.ComputeSignature(cmsSigner); - - //Embed the encoded digital signature to the PDF document - ars.SignedData = signedCms.Encode(); -} diff --git a/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/Input.pdf b/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/Input.pdf new file mode 100644 index 00000000..4de703ac Binary files /dev/null and b/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/Input.pdf differ diff --git a/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/PDF.pfx b/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/PDF.pfx deleted file mode 100644 index cc69dcf4..00000000 Binary files a/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/PDF.pfx and /dev/null differ diff --git a/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/syncfusion_logo.png b/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/syncfusion_logo.png deleted file mode 100644 index 02194707..00000000 Binary files a/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Data/syncfusion_logo.png and /dev/null differ diff --git a/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Enable-LTV-PDF-signature.csproj b/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Enable-LTV-PDF-signature.csproj index 3afe1e3a..bc051276 100644 --- a/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Enable-LTV-PDF-signature.csproj +++ b/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Enable-LTV-PDF-signature.csproj @@ -13,10 +13,7 @@ - - Always - - + Always diff --git a/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Program.cs b/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Program.cs index 18652d89..ef88225e 100644 --- a/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Program.cs +++ b/Digital Signature/Enable-LTV-PDF-signature/.NET/Enable-LTV-PDF-signature/Program.cs @@ -1,57 +1,26 @@ // See https://aka.ms/new-console-template for more information -using Syncfusion.Drawing; -using Syncfusion.Pdf; -using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Security; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Adds a new page. -PdfPageBase page = document.Pages.Add(); - -//Create graphics for the page. -PdfGraphics graphics = page.Graphics; - -//Creates a certificate instance from PFX file with private key. -FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read); -PdfCertificate pdfCert = new PdfCertificate(certificateStream, "DigitalPass123"); - -//Creates a digital signature. -PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature"); -signature.Settings.CryptographicStandard = CryptographicStandard.CADES; -signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA256; - - -//Sets an image for signature field. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/syncfusion_logo.png"), FileMode.Open, FileAccess.Read); - -//Sets an image for signature field. -PdfBitmap image = new PdfBitmap(imageStream); - -//Adds time stamp by using the server URI and credentials. -signature.TimeStampServer = new TimeStampServer(new Uri("http://time.certum.pl/ ")); +//Get the stream from the document. +FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +//Load an existing PDF document. +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); +//Gets the first signature field of the PDF document +PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; +PdfSignature signature = signatureField.Signature; //Enable LTV on Signature. signature.EnableLtv = true; -//Sets signature info. -signature.Bounds = new RectangleF(new PointF(0, 0), image.PhysicalDimension); -signature.ContactInfo = "johndoe@owned.us"; -signature.LocationInfo = "Honolulu, Hawaii"; -signature.Reason = "I am author of this document."; - -//Draws the signature image. -signature.Appearance.Normal.Graphics.DrawImage(image, 0, 0); - //Create file stream. using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) { //Save the PDF document to file stream. - document.Save(outputFileStream); + loadedDocument.Save(outputFileStream); } //Close the document. -document.Close(true); +loadedDocument.Close(true);