I am working on reading a PDF electronically
filled by user using SyncFusion. I have not been able to get much in the library. ExtractText()
gives me the PDF text but that is not of much use to me because I need to read
the data that user has electronically filled in the PDF as well. I also
tried with form.Fields but that helps only if user has electronically edited
PDF having created the Form Fields initially using Adobe Acrobat Reader. But I
want to consider the scenario where user has just entered plain text in PDF as
data and I want to read entire PDF including PDF text and user input data.
Is there any method exposed in the library for
this task?
//Load the existing PDF document
PdfLoadedDocument ldoc = new PdfLoadedDocument("../../input.pdf");
//Load the existing form
PdfLoadedForm lForm = ldoc.Form;
//Get the form fields value
foreach (PdfLoadedField lField in lForm.Fields)
{
if (lField is PdfLoadedTextBoxField)
{
PdfLoadedTextBoxField lTextBox = lField as PdfLoadedTextBoxField;
//Get the text box value
string text = lTextBox.Text;
}
} |
//Load the existing PDF document
PdfLoadedDocument ldoc = new PdfLoadedDocument("../../input.pdf");
//Load the existing form
PdfLoadedForm lForm = ldoc.Form;
//Flatten the form fields
lForm.Flatten = true;
MemoryStream ms = new MemoryStream();
//Save the PDF document
ldoc.Save(ms);
//Close the PDF document
ldoc.Close(true);
//Load the document
PdfLoadedDocument doc = new PdfLoadedDocument(ms);
string text = string.Empty;
foreach (PdfLoadedPage lpage in doc.Pages)
{
//Extract the text
text += lpage.ExtractText(true);
}
File.AppendAllText("text.txt", text);
|