Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
// 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);
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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);
}
Loading