diff --git a/cpp/poppler-page.cpp b/cpp/poppler-page.cpp index a3f85069..56537905 100644 --- a/cpp/poppler-page.cpp +++ b/cpp/poppler-page.cpp @@ -26,7 +26,9 @@ #include "TextOutputDev.h" +#include #include +#include using namespace poppler; @@ -270,7 +272,12 @@ ustring page::text(const rectf &r, text_layout_enum layout_mode) const TextOutputDev td(0, gFalse, 0, use_raw_order, gFalse); d->doc->doc->displayPage(&td, d->index + 1, 72, 72, 0, false, true, false); if (r.is_empty()) { - const PDFRectangle *rect = d->page->getCropBox(); + PDFRectangle *rect = d->page->getCropBox(); + const int rotate = d->page->getRotate(); + if (rotate == 90 || rotate == 270) { + std::swap(rect->x1, rect->y1); + std::swap(rect->x2, rect->y2); + } s.reset(td.getText(rect->x1, rect->y1, rect->x2, rect->y2)); } else { s.reset(td.getText(r.left(), r.top(), r.right(), r.bottom())); diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp index 398a5004..914c7c6f 100644 --- a/cpp/tests/poppler-dump.cpp +++ b/cpp/tests/poppler-dump.cpp @@ -315,7 +315,17 @@ static void print_page(poppler::page *p) static void print_page_text(poppler::page *p) { if (p) { - std::cout << p->text(p->page_rect(), show_text_layout) << std::endl; + poppler::rectf r = p->page_rect(); + poppler::page::orientation_enum o = p->orientation(); + if (o == poppler::page::landscape || o == poppler::page::seascape) { + float temp = r.left(); + r.set_left(r.top()); + r.set_top(temp); + temp = r.right(); + r.set_right(r.bottom()); + r.set_bottom(temp); + } + std::cout << p->text(r, show_text_layout) << std::endl; } else { std::cout << std::setw(out_width) << "Broken Page. Could not be parsed" << std::endl; }