feat: implemented text extraction with bounding boxes
This commit is contained in:
@@ -96,6 +96,21 @@ PYBIND11_MODULE(pdfengine, m) {
|
||||
.def("extract_text", [](const pdfengine::PdfPage& self) {
|
||||
return get_or_throw(self.extractText());
|
||||
})
|
||||
.def("extract_text_with_bounds", [](const pdfengine::PdfPage& self) {
|
||||
auto res = get_or_throw(self.extractTextWithBounds());
|
||||
py::list py_list;
|
||||
for (const auto& glyph : res) {
|
||||
py::dict d;
|
||||
d["text"] = glyph.text;
|
||||
d["x"] = glyph.x;
|
||||
d["y"] = glyph.y;
|
||||
d["w"] = glyph.w;
|
||||
d["h"] = glyph.h;
|
||||
d["fontSize"] = glyph.fontSize;
|
||||
py_list.append(d);
|
||||
}
|
||||
return py_list;
|
||||
})
|
||||
.def("page_to_device", &pdfengine::PdfPage::pageToDevice,
|
||||
py::arg("page_point"), py::arg("device_width"), py::arg("device_height"), py::arg("rotate") = 0)
|
||||
.def("device_to_page", &pdfengine::PdfPage::deviceToPage,
|
||||
|
||||
Reference in New Issue
Block a user