yob/pdf-reader

Detecting underlined text

Opened this issue · 2 comments

Hi,
Thank you so much for creating this awesome gem.

I'm having troubles figuring out a way to detect underlined text. Underlined texts have a different meaning the documents that I'm trying to parse and so I need to be able to detect if a text is underlined.

I've been looking at the PageTextReceiver and the method internal_show_text but I'm seeing anything that will tell me if a character is underlined or not.

I'm gonna continue digging into the library but if anyone has any pointers to share, I would greatly appreciate!

Thank you so much for any help!

Best,
Lio

yob commented

I'm not super familiar with underlining.

I suspect there's two common approaches

  1. drawing a line using line/stroke primitives rather than a text command
  2. using annotations

(1) will be hard to detect.

You might have some success with annotations. Annotations are stored in each page outside the content stream. This comment might help you poke around: #179 (comment)

Thank you @yob for your comment.

Unfortunately, I had already tried to parse annotations but nothing is coming back 😞.
I'm not too sure how the first option will work.

My original thought was to look at fonts (which we can get access to), but underlines are actually styles, not fonts. I might need to educate myself with the PDF format and how streams/objects are stored/formatted.