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..b42eb3c1 100644 --- a/cpp/tests/poppler-dump.cpp +++ b/cpp/tests/poppler-dump.cpp @@ -315,7 +315,7 @@ 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; + std::cout << p->text(poppler::rectf(), show_text_layout) << std::endl; } else { std::cout << std::setw(out_width) << "Broken Page. Could not be parsed" << std::endl; }