Class: Pdfrb::Content::HiddenTextDetector
- Inherits:
-
Object
- Object
- Pdfrb::Content::HiddenTextDetector
- Defined in:
- lib/pdfrb/content/hidden_text_detector.rb
Overview
Detects hidden / transparent text in content streams. Hidden text is text rendered with Tr=3 (invisible) or with alpha=0 (fully transparent). PDF/A and PDF/UA require such text to be tagged as /Artifact or wrapped in a structure element.
Inspired by mn2pdf's PDFHiddenTextStripper. Walks content streams via the Content::Parser, tracking graphics state changes.
Defined Under Namespace
Classes: Collector, HiddenItem
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
-
#detect ⇒ Object
Walk all content streams.
-
#hidden_only ⇒ Object
Returns only the hidden text items (rendering_mode_3 or alpha=0).
-
#initialize(document) ⇒ HiddenTextDetector
constructor
A new instance of HiddenTextDetector.
Constructor Details
#initialize(document) ⇒ HiddenTextDetector
Returns a new instance of HiddenTextDetector.
23 24 25 |
# File 'lib/pdfrb/content/hidden_text_detector.rb', line 23 def initialize(document) @document = document end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
21 22 23 |
# File 'lib/pdfrb/content/hidden_text_detector.rb', line 21 def document @document end |
Instance Method Details
#detect ⇒ Object
Walk all content streams. Returns HiddenItem objects for each text-showing operation. Items with a nil reason are visible.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pdfrb/content/hidden_text_detector.rb', line 29 def detect items = [] @document.each_indirect_object do |obj| next unless content_stream?(obj) page = find_page(obj) detect_in_stream(obj, page) { |item| items << item } end items end |
#hidden_only ⇒ Object
Returns only the hidden text items (rendering_mode_3 or alpha=0).
41 42 43 |
# File 'lib/pdfrb/content/hidden_text_detector.rb', line 41 def hidden_only detect.select(&:hidden?) end |