pdf.text_diff
result = pdf.text_diff(src_a, src_b)
Input: src_a, src_b · Output: result
What it is
Page-by-page text diff of two documents, built entirely on pdf.extract_text/pdf.page_count.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = pdf.text_diff(src_a, src_b) | src_a —not documented yetsrc_b —not documented yet | pages_b Numeach document's page countpage NumNumonly_in_b —Boollines List or RecordList of Records with kind — "same", "added" or "removed" — and text, from a line-based LCS diff; empty when the page exists on only one side | Returns a Record: pages_a, pages_b (Num, each document's page count) and differing_pages — a List of Records, only for pages that differ (a page present on only one side counts as differing too), each with page (Num), only_in_a/only_in_b (Bool) and lines (List of Records with kind — "same", "added" or "removed" — and text, from a line-based LCS diff; empty when the page exists on only one side). |
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