I'd like to know if there's some PDF library in Microsoft .NET being able of extracting text by giving coordinates.
For example (in pseudo-code):
PdfReader reader = new PdfReader();
reader.Load("file.pdf");
// Top, bottom, left, right in pixels or any other unit
string wholeText = reader.GetText(100, 150, 20, 50);
I've tried to do so using PDFBox for .NET (that one working on top of IKVM) with no luck, and it seems to be very outdated and undocumented.
Perhaps anyone has a good sample of doing so with PDFBox, iTextSharp or any other open-sourced library, and he/she can give me a hint.
Thank you in advance.
This code will work in itext 7
iText's
RegionTextRenderFilter
is precisely what you're looking for.So you want something like this (forgive my Java, but it should be trivial to translate):
It's not open source, but hopefully this helps you (and potentially anyone else using ABCPDF!)
I did this earlier today by looping over the available fields in the PDF. This means that the PDF you are using needs to be created properly and you need to know the field name that you want to get the text for (you could work this out by adding a breakpoint and looping through the available fields).
In the example, "Text1" is the name of the field that is being updated. Note I am also providing an example for saving out updated field(s).
Hopefully that at least gives you an idea of how to approach this problem.
This should work:
Well, thank you for your effort anyone.
I got it using Apache's PDFBox on top of IKVM compilation, and this is the final code:
And it works like a charm.
Thank you anyway and I hope my own answer will help others. If you need further details, just comment out here and I'll update this answer.
You may wanna look at this sample. It uses itextsharp