pdf.extract_text
result = pdf.extract_text(src, [pages], [page=], [normalize=false], [lines=false])
Input: src, pages, page, normalize, lines · Output: result
What it is
Text reconstructed from a PDF's content streams. src (string path, or Vec of bytes) is the document; pages (optional, positional or page=) is a page number or a Vec/List of them, defaulting to every page.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = pdf.extract_text(src, [pages], [page=], [normalize=false], [lines=false]) | src string or Vecsrc (string path, or Vec of bytes) is the document.pages number, Vec, or List, optionalpages (optional, positional or page=) is a page number or a Vec/List of them, defaulting to every page.page number, Vec, or List, optionalpages (optional, positional or page=) is a page number or a Vec/List of them, defaulting to every page.normalize optional (default false)Read the warning below before relying on this. With normalize=true (added in v0.4.7) ligatures are expanded (fi fl ff ffi ffl and the presentation forms U+FB00 to U+FB06), no-break spaces become spaces, runs of whitespace collapse to one space, empty lines are dropped, and a word split by a line-end hyphen is re-joined (Fi- then nally gives Finally, the two lines becoming one) -- only when the hyphen follows a letter and the next line starts lowercase, so well- / Known is left alone.lines optional (default false)Read the warning below before relying on this. With normalize=true (added in v0.4.7) ligatures are expanded (fi fl ff ffi ffl and the presentation forms U+FB00 to U+FB06), no-break spaces become spaces, runs of whitespace collapse to one space, empty lines are dropped, and a word split by a line-end hyphen is re-joined (Fi- then nally gives Finally, the two lines becoming one) -- only when the hyphen follows a letter and the next line starts lowercase, so well- / Known is left alone. | normalize=true —added in v0.4.7lines=true —added in v0.4.7 | Returns a Str. Read the warning below before relying on this. With normalize=true (added in v0.4.7) ligatures are expanded (fi fl ff ffi ffl and the presentation forms U+FB00 to U+FB06), no-break spaces become spaces, runs of whitespace collapse to one space, empty lines are dropped, and a word split by a line-end hyphen is re-joined (Fi- then nally gives Finally, the two lines becoming one) -- only when the hyphen follows a letter and the next line starts lowercase, so well- / Known is left alone. With lines=true (added in v0.4.7) the result is a List of Str, one per text line, instead of one Str: lines are rebuilt from where each text-showing operator starts (text matrix and cm are followed), grouped by baseline and ordered top to bottom, left to right within a line. There are no glyph widths, so a piece of text is placed by its start only; /Rotate is ignored; a multi-column page comes out interleaved row by row; and a page whose text is inside a Form XObject, or whose fonts have no usable encoding, is an error saying lines could not be recovered, never a faked answer. Both options default to false, which leaves the result byte-identical to earlier versions; both accept only true or false. |
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
try
t = pdf.extract_text("paper.pdf", page = 1)
print(t)
catch err
print("no text layer this engine can read: {err}")
end
not run by the build — this one needs something the repository cannot supply · from file-io