diff --git a/Digital Signature/Digital-Signature-Validation/.NET/Digital-Signature-Validation/Digital-Signature-Validation.csproj b/Digital Signature/Digital-Signature-Validation/.NET/Digital-Signature-Validation/Digital-Signature-Validation.csproj index 369e3baf..720aa9ba 100644 --- a/Digital Signature/Digital-Signature-Validation/.NET/Digital-Signature-Validation/Digital-Signature-Validation.csproj +++ b/Digital Signature/Digital-Signature-Validation/.NET/Digital-Signature-Validation/Digital-Signature-Validation.csproj @@ -12,4 +12,22 @@ + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + diff --git a/Digital Signature/Digital-Signature-Validation/.NET/Digital-Signature-Validation/Program.cs b/Digital Signature/Digital-Signature-Validation/.NET/Digital-Signature-Validation/Program.cs index 422fe9ec..3df7eaf6 100644 --- a/Digital Signature/Digital-Signature-Validation/.NET/Digital-Signature-Validation/Program.cs +++ b/Digital Signature/Digital-Signature-Validation/.NET/Digital-Signature-Validation/Program.cs @@ -3,44 +3,31 @@ using System.Security.Cryptography.X509Certificates; using System.Text; -string dataPath = Path.GetFullPath(@"Data/"); - -// Load signed PDF document +//Open the signed PDF document. using PdfLoadedDocument ldoc = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); - -// Get signature field +//Retrieve the signature field from the document form. PdfLoadedSignatureField lSigFld = ldoc.Form.Fields[0] as PdfLoadedSignatureField; - -// Root and Intermediate Certificates +//Create a collection to store the root and intermediate certificates. X509CertificateCollection collection = new X509CertificateCollection(); - string[] certificates = { "Root.cer", "Intermediate0.cer", "Intermediate1.cer" }; - +//Load certificates and add them to the certificate collection. foreach (string certFile in certificates) { - byte[] certData = File.ReadAllBytes(Path.Combine(dataPath, certFile)); - - X509Certificate2 certificate = new X509Certificate2(certData); - - collection.Add(certificate); + collection.Add(new X509Certificate2(File.ReadAllBytes(Path.GetFullPath(@"Data/" + certFile)))); } - -// Validate signature +//Verify the digital signature using the certificate chain. PdfSignatureValidationResult result = lSigFld.ValidateSignature(collection); - StringBuilder builder = new StringBuilder(); - builder.AppendLine("Signature is " + result.SignatureStatus); builder.AppendLine(); builder.AppendLine("----------Validation Summary----------"); builder.AppendLine(); - -// Modified check +//Check whether the signed document has been modified. if (result.IsDocumentModified) { builder.AppendLine("The document has been altered or corrupted since the signature was applied."); @@ -49,64 +36,49 @@ { builder.AppendLine("The document has not been modified since the signature was applied."); } - -// Certificate details +//Add signer certificate information to the report. builder.AppendLine("Digitally signed by: " + lSigFld.Signature.Certificate.IssuerName); - builder.AppendLine("Valid From: " + lSigFld.Signature.Certificate.ValidFrom); - builder.AppendLine("Valid To: " + lSigFld.Signature.Certificate.ValidTo); - builder.AppendLine("Signature Algorithm: " + result.SignatureAlgorithm); - builder.AppendLine("Hash Algorithm: " + result.DigestAlgorithm); - -// Revocation details +//Include revocation status details. builder.AppendLine("OCSP Revocation Status: " + result.RevocationResult.OcspRevocationStatus); - if (result.RevocationResult.OcspRevocationStatus == RevocationStatus.None && result.RevocationResult.IsRevokedCRL) { builder.AppendLine("CRL is revoked."); } - builder.AppendLine(); builder.AppendLine("--------Revocation Information---------"); builder.AppendLine(); - +//Extract OCSP and CRL validation details for each signer certificate. foreach (PdfSignerCertificate signerCertificate in result.SignerCertificates) { if (signerCertificate.OcspCertificate != null) { builder.AppendLine("------------OCSP Certificate-------------"); - foreach (X509Certificate2 item in signerCertificate.OcspCertificate.Certificates) { builder.AppendLine("The OCSP Response was signed by: " + item.SubjectName.Name); } - builder.AppendLine("Is Embedded: " + signerCertificate.OcspCertificate.IsEmbedded); - builder.AppendLine("Valid From: " + signerCertificate.OcspCertificate.ValidFrom); - builder.AppendLine("Valid To: " + signerCertificate.OcspCertificate.ValidTo); - builder.AppendLine(); } if (signerCertificate.CrlCertificate != null) { builder.AppendLine("------------CRL Certificate--------------"); - foreach (X509Certificate2 item in signerCertificate.CrlCertificate.Certificates) { builder.AppendLine("The CRL was signed by: " + item.SubjectName.Name); } - builder.AppendLine("Is Embedded: " + signerCertificate.CrlCertificate.IsEmbedded); builder.AppendLine("Valid From: " + signerCertificate.CrlCertificate.ValidFrom); builder.AppendLine("Valid To: " + signerCertificate.CrlCertificate.ValidTo); builder.AppendLine(); } } -//Save to file -File.WriteAllText(Path.GetFullPath(@"Output/Output.txt"),builder.ToString()); \ No newline at end of file +//Write the validation report to a text file. +File.WriteAllText(Path.GetFullPath(@"Output/Output.txt"), builder.ToString()); \ No newline at end of file diff --git a/Digital Signature/Multiple-digital-signature/.NET/Multiple-digital-signature/Program.cs b/Digital Signature/Multiple-digital-signature/.NET/Multiple-digital-signature/Program.cs index 45271bed..f754f5cc 100644 --- a/Digital Signature/Multiple-digital-signature/.NET/Multiple-digital-signature/Program.cs +++ b/Digital Signature/Multiple-digital-signature/.NET/Multiple-digital-signature/Program.cs @@ -5,57 +5,39 @@ // Open the existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/SignatureFields.pdf")); - // Retrieve the first page from the PDF document. PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; - // Access the first signature field available in the PDF form. PdfLoadedSignatureField signatureField1 = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; - // Create a certificate object using the PFX file and its password. PdfCertificate certificate1 = new PdfCertificate(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion"); - // Digitally sign the first signature field. signatureField1.Signature = new PdfSignature(loadedDocument, page, certificate1, "Signature1", signatureField1); - // Load the signature image for the first signer. FileStream imageStream1 = new FileStream(Path.GetFullPath(@"Data/Student Signature.jpg"), FileMode.Open, FileAccess.Read); - PdfBitmap signatureImage = new PdfBitmap(imageStream1); - - // Render the signature image within the signature field appearance. signatureField1.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, signatureField1.Bounds.Width, signatureField1.Bounds.Height); - // Save the signed PDF into a memory stream. MemoryStream stream = new MemoryStream(); loadedDocument.Save(stream); - // Close the original PDF document instance. loadedDocument.Close(true); // Reopen the partially signed PDF from the memory stream. PdfLoadedDocument signedDocument = new PdfLoadedDocument(stream); - // Retrieve the first page of the signed document. PdfLoadedPage loadedPage = signedDocument.Pages[0] as PdfLoadedPage; - // Access the second signature field in the PDF form. PdfLoadedSignatureField signatureField2 = signedDocument.Form.Fields[1] as PdfLoadedSignatureField; - // Apply a digital signature to the second signature field. signatureField2.Signature = new PdfSignature(signedDocument, loadedPage, certificate1, "Signature2", signatureField2); - // Load the signature image for the second signer. FileStream imageStream2 = new FileStream(Path.GetFullPath(@"Data/Teacher Signature.png"), FileMode.Open, FileAccess.Read); - PdfBitmap signatureImage1 = new PdfBitmap(imageStream2); - // Display the signature image in the second signature field appearance. signatureField2.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage1, 0, 0, signatureField2.Bounds.Width, signatureField2.Bounds.Height); - // Save the fully signed PDF document. signedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); - // Close the signed PDF document. signedDocument.Close(true); diff --git a/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages.csproj b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages.csproj index c2c79df1..161bab2e 100644 --- a/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages.csproj +++ b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages.csproj @@ -12,4 +12,34 @@ + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + diff --git a/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Program.cs b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Program.cs index 2aa0e24f..0573c7f0 100644 --- a/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Program.cs +++ b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Program.cs @@ -2,19 +2,19 @@ using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; -// Load the PDF document +//Open the existing PDF document. using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - // Initialize OCR processor + //Create an OCR processor instance. OCRProcessor processor = new OCRProcessor(); - //Sets Unicode font to preserve the Unicode characters in a PDF document. + //Assign a Unicode font to retain multilingual characters in the OCR output PDF. processor.UnicodeFont = new PdfTrueTypeFont(Path.GetFullPath(@"Data/ARIALUNI.ttf"), 8); - // Set OCR language + //Specify the languages to be recognized during OCR processing. processor.Settings.Language = "eng+deu+ara+ell+fra"; // English, German, Arabic, Greek, French - // Set the path to the Tesseract language data folder + //Set the directory containing Tesseract language data files. processor.TessDataPath = Path.GetFullPath(@"Tessdata"); - // Perform OCR + //Run OCR on the PDF document and make its content searchable. processor.PerformOCR(loadedDocument); - // Save the PDF document + //Save the OCR-processed PDF to the output location. loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Data/ARIALUNI.TTF b/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Data/ARIALUNI.TTF deleted file mode 100644 index de9b19d1..00000000 Binary files a/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Data/ARIALUNI.TTF and /dev/null differ diff --git a/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Perform-OCR-on-image-file.csproj b/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Perform-OCR-on-image-file.csproj index 983b16f5..78f8fd48 100644 --- a/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Perform-OCR-on-image-file.csproj +++ b/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Perform-OCR-on-image-file.csproj @@ -13,9 +13,6 @@ - - Always - Always diff --git a/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Program.cs b/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Program.cs index d36101d8..60f81ff6 100644 --- a/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Program.cs +++ b/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Program.cs @@ -1,22 +1,14 @@ using Syncfusion.OCRProcessor; -using Syncfusion.Pdf.Graphics; -//Initialize the OCR processor by providing the path of the tesseract binaries. +//Create an OCR processor instance. using (OCRProcessor processor = new OCRProcessor()) { - //Get stream from the image file. + //Open the input image as a file stream. FileStream stream = new FileStream(Path.GetFullPath(@"Data/Input.jpg"), FileMode.Open); - - //Set OCR language to process. + //Specify English as the language for text recognition. processor.Settings.Language = Languages.English; - - //Sets Unicode font to preserve the Unicode characters in a PDF document. - FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/ARIALUNI.ttf"), FileMode.Open); - - processor.UnicodeFont = new PdfTrueTypeFont(fontStream, 8); - - //Perform the OCR process for an image steam. + //Extract text from the image using the OCR engine and tessdata path. string ocrText = processor.PerformOCR(stream, processor.TessDataPath); - - System.IO.File.WriteAllText(Path.GetFullPath(@"Output/Output.txt"), ocrText); + //Save the recognized text to a text file. + File.WriteAllText(Path.GetFullPath(@"Output/Output.txt"), ocrText); }