Please can any one help me. I am really stuck I don't know how to highlight particular line of pdf. It would be better if any one can provide me sample code or pseudo code
Thanks

- 19
- 2
-
Do you want to modify the PDF file and add highlighting on a particular line, or do you need just to show the PDF on screen with the line highlighted? – Gintautas Miliauskas Nov 29 '10 at 17:09
-
possible duplicate of [HIghlighting the text in PDF document iPhone xcode](http://stackoverflow.com/questions/1755584/highlighting-the-text-in-pdf-document-iphone-xcode) – Brad Larson Nov 29 '10 at 22:51
3 Answers
I'm working on the same thing at the moment and it's not trivial indeed.
From what I can figure out you need to load the text and arrange it in lines first. If you are using Poppler, the Poppler.Page.textList()
will provide you with a list of TextBoxes and a TextBox.hasSpaceAfter()
will tell you the end of line when returning False
.
I am using the Qt4 frontend, so the each TextBox has a QRect from which I can figure out where to highlight a word. Highlighting a line is more or less lirstWordOfLine.geometry().united(lastWordOfLine.geometry())
which will provide the geometry of the line to highlight.
Now what I can't figure out is how to save the coordinates of the highlights in the document.

- 6,973
- 9
- 57
- 89
This is not trivial.
To do this, I'd render the PDF contents into one layer, and somehow get the position of the said line/object using the CoreGraphics PDF parser (or some other way). After that, you highlight the said object using your own drawing code.

- 19,679
- 11
- 56
- 86
Just highlighting a particular line is quite difficult.
If you need search and highlight, please try FastPDFKit. I played with it for a while and it's quite good as a pdf reader.

- 1,791
- 3
- 17
- 23