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 85a4ce1a..45271bed 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 @@ -3,48 +3,59 @@ using Syncfusion.Pdf.Security; using Syncfusion.Pdf; -//Load an existing PDF document. -using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/SignatureFields.pdf"))) -{ - - //Get the first page of the document. - PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; - //Get the first signature field of the PDF document. - PdfLoadedSignatureField signatureField1 = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField; - //Create a certificate instance from a PFX file with a private key. - FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read); - PdfCertificate certificate1 = new PdfCertificate(certificateStream, "syncfusion"); - //Add a signature to the signature field. - signatureField1.Signature = new PdfSignature(loadedDocument, page, certificate1, "Signature", signatureField1); - //Set an image for the signature field. - FileStream imageStream1 = new FileStream(Path.GetFullPath(@"Data/Student Signature.jpg"), FileMode.Open, FileAccess.Read); - PdfBitmap signatureImage = new PdfBitmap(imageStream1); - //Insert an image in the signature appearance. - signatureField1.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, 90, 20); - //Save the document into the stream. - MemoryStream stream = new MemoryStream(); - loadedDocument.Save(stream); - - //Load the signed PDF document. - using (PdfLoadedDocument signedDocument = new PdfLoadedDocument(stream)) - { - //Load the PDF page. - PdfLoadedPage loadedPage = signedDocument.Pages[0] as PdfLoadedPage; - - //Get the first signature field of the PDF document. - PdfLoadedSignatureField signatureField2 = signedDocument.Form.Fields[1] as PdfLoadedSignatureField; - - //Add a signature to the signature field. - signatureField2.Signature = new PdfSignature(signedDocument, loadedPage, certificate1, "Signature", signatureField2); - - //Set an image for the signature field. - FileStream imageStream2 = new FileStream(Path.GetFullPath(@"Data/Teacher Signature.png"), FileMode.Open, FileAccess.Read); - PdfBitmap signatureImage1 = new PdfBitmap(imageStream2); - - //Draw an image in the signature appearance. - signatureField2.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage1, 0, 0, 90, 20); - - //Save the PDF document - signedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); - } -} \ No newline at end of file +// 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/Program.cs b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Program.cs index 6608d460..2aa0e24f 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 @@ -12,9 +12,9 @@ // Set OCR language processor.Settings.Language = "eng+deu+ara+ell+fra"; // English, German, Arabic, Greek, French // Set the path to the Tesseract language data folder - processor.TessDataPath = Path.GetFullPath(@"../../Tessdata"); + processor.TessDataPath = Path.GetFullPath(@"Tessdata"); // Perform OCR processor.PerformOCR(loadedDocument); // Save the PDF document loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); -} +} \ No newline at end of file diff --git a/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/ara.traineddata b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/ara.traineddata new file mode 100644 index 00000000..42e5c4b3 Binary files /dev/null and b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/ara.traineddata differ diff --git a/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/deu.traineddata b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/deu.traineddata new file mode 100644 index 00000000..36f623a0 Binary files /dev/null and b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/deu.traineddata differ diff --git a/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/ell.traineddata b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/ell.traineddata new file mode 100644 index 00000000..6e60373e Binary files /dev/null and b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/ell.traineddata differ diff --git a/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/eng.traineddata b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/eng.traineddata new file mode 100644 index 00000000..f4744c20 Binary files /dev/null and b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/eng.traineddata differ diff --git a/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/fra.traineddata b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/fra.traineddata new file mode 100644 index 00000000..250c7749 Binary files /dev/null and b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/fra.traineddata differ diff --git a/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/grc.traineddata b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/grc.traineddata new file mode 100644 index 00000000..a306f3e7 Binary files /dev/null and b/OCR/.NET/Perform-OCR-on-PDF-with-multiple-languages/Perform-OCR-on-PDF-with-multiple-languages/Tessdata/grc.traineddata differ 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 6f51bbd3..d36101d8 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,29 +1,22 @@ using Syncfusion.OCRProcessor; using Syncfusion.Pdf.Graphics; -using System.Drawing; - -string tessdataPath = Path.GetFullPath(@"Tessdata"); //Initialize the OCR processor by providing the path of the tesseract binaries. using (OCRProcessor processor = new OCRProcessor()) { - //Get stream from the image file. + //Get stream from the image file. FileStream stream = new FileStream(Path.GetFullPath(@"Data/Input.jpg"), FileMode.Open); - + //Set OCR language to process. 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. - string ocrText = processor.PerformOCR(stream, tessdataPath); - - //Write the OCR'ed text in text file. - using (StreamWriter writer = new StreamWriter(Path.GetFullPath(@"Output/Output.txt"), true)) - { - writer.WriteLine(ocrText); - } + string ocrText = processor.PerformOCR(stream, processor.TessDataPath); + + System.IO.File.WriteAllText(Path.GetFullPath(@"Output/Output.txt"), ocrText); }