pdf.find_text
result = pdf.find_text(src, query, [case_sensitive=])
Input: src, query, case_sensitive · Output: result
What it is
Searches every page's pdf.extract_text output for query (built on that function, not a separate reconstruction — the same warning below applies: a page extract_text cannot read is a page this cannot search either, and errors the same way). case_sensitive defaults to true; passing false case-folds character-by-character rather than via a byte comparison.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = pdf.find_text(src, query, [case_sensitive=]) | src —not documented yetquery —Searches every page's pdf.extract_text output for query (built on that function, not a separate reconstruction — the same warning below applies: a page extract_text cannot read is a page this cannot search either, and errors the same way).case_sensitive optionalcase_sensitive defaults to true. | page Numfrom 1offset Num or stringa character offset into that page's extract_text string — not a byte offset, and not an on-page coordinate; this module reads PDF structure, not rendered glyph positionslength Numthe match's length in characters | Returns a List of Records, one per match, each with page (Num, from 1), offset (Num, a character offset into that page's extract_text string — not a byte offset, and not an on-page coordinate; this module reads PDF structure, not rendered glyph positions) and length (Num, the match's length in characters). |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
import pdf
# Only `subject` changes; title/author/producer/... are untouched.
tagged = pdf.set_metadata("paper.pdf", subject = "Impedance spectroscopy")
pdf.write_merge("tagged.pdf", [tagged]) # or write it out any other way
hits = pdf.find_text("paper.pdf", "impedance", case_sensitive = false)
for h in hits
print("page {h.page}, offset {h.offset}")
end
d = pdf.text_diff("draft_v1.pdf", "draft_v2.pdf")
print("{length(d.differing_pages)} of {d.pages_b} pages changed")
s = pdf.structural_diff("draft_v1.pdf", "draft_v2.pdf")
if s.pages_a != s.pages_b
print("page count changed: {s.pages_a} -> {s.pages_b}")
end
not run by the build — this one needs something the repository cannot supply · from file-io