read user input text from in pdf file
-
6 марта 2012 г. 15:05
Using the following code, I can read the text from a pdf file.
Question:
The code does not seem to read the text inside input form controls.
For example, if there is a textbox called txtName on the first page of the pdf file, the c# code does not pick it up whereas it only sees the actual text of the pdf.
Do you see why please?
Thanksstring strText = string.Empty;
string filename = @"D:\test.pdf";
PdfReader pdfReader = new PdfReader(filename");
for (int nPage = 1; nPage <= pdfReader.NumberOfPages; nPage++)
{
ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
PdfReader reader2 = new PdfReader(filename);
String s = PdfTextExtractor.GetTextFromPage(reader2, nPage, its);s = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(s)));
strText = strText + s;
reader2.Close();
}string strInput = strText;
Все ответы
-
6 марта 2012 г. 15:14
-
7 марта 2012 г. 8:13Thanks but it does not do what I have asked in my question.
-
7 марта 2012 г. 23:45
Hi mate,
You are PdfTextExtractor.GetTextFromPage(reader2, nPage, its); means read the text on file not field content. Check methods of component to read fields by name or identifier and get value of the fields against it.
There you go.
Thanks.
Mohammad Saidul Karim
- Помечено в качестве ответа Leo Liu - MSFTModerator 13 марта 2012 г. 6:31
-
8 марта 2012 г. 7:18МодераторHi arkiboys,
How is it going now with Mohammad's suggestion?
If your problem still exist, you need to close this thread by marking some useful replies as answers and then post in the some dedicated forums as below to get better support:
http://old.nabble.com/iTextSharp-f4188.html.
http://support.itextpdf.com/forum.
Thanks for your understanding and have a nice day,Leo Liu [MSFT]
MSDN Community Support | Feedback to us
-
14 марта 2012 г. 15:22
"Hi mate,
You are PdfTextExtractor.GetTextFromPage(reader2, nPage, its); means read the text on file not field content. Check methods of component to read fields by name or identifier and get value of the fields against it.
There you go.
Thanks.
Mohammad Saidul Karim
Check methods of component to read fields by name or identifier and get value of the fields against it."
This is exactly what I am trying to do but do not know how?
Any thoughts please?
Thanks -
21 марта 2012 г. 16:04
private void button2_Click(object sender, EventArgs e) { string strText = string.Empty; string filename = @"C:\pdfTestFile.pdf"; PdfReader pdfReader = new PdfReader(filename); for (int nPage = 1; nPage <= pdfReader.NumberOfPages; nPage++) { ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy(); PdfReader reader2 = new PdfReader(filename); String s = PdfTextExtractor.GetTextFromPage(reader2, nPage, its); s = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(s))); strText = strText + s; reader2.Close();
Hi,
My goal is to read the texts inside the controls in the
.pdf file...
I am using the iTextSharp reference...
The C# code below only reads the texts (Initially typed in the
file) but NOT the texts typed in the controls.
Do you know how
to solve this please?
Thanks

