Qu

pdf.find_text

Builtin index · File I/O

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.

CodeInputOutputDescription
result = pdf.find_text(src, query, [case_sensitive=])
src —not documented yet
query —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 1
offset 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 positions
length 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