[poppler] Get text formatting info
Albert Astals Cid
aacid at kde.org
Tue Jul 26 23:05:06 UTC 2022
El dimarts, 26 de juliol de 2022, a les 14:34:20 (CEST), Martin Delille va
escriure:
> Hi,
>
> I have this little piece of code that print the content of a PDF file and
> convert it to a sequence of image:
>
> bool showPDF(const QString &fileName) {
> bool result = false;
>
> if (auto document = Poppler::Document::load(fileName)) {
> if (document->isLocked()) {
> qCritical() << "Document is locked:" << fileName <<
> "\n";
> } else {
> qDebug() << "pages: " << document->numPages() <<
> "\n";
>
> for (int i = 0; i < document->numPages(); i++) {
> qDebug() << "page:" << i << "\n";
> auto page = document->page(i);
>
> for (auto &text : page->textList()) {
> qDebug() << "\ttext: " <<
> text->boundingBox().x()
> << " / " <<
> text->boundingBox().y()
> << " " << text->text()
> << "\n";
> }
>
> auto image = page->renderToImage(300, 300);
> image.save(QString("%0.%1.jpg")
> .arg(fileName,
>
> QString::number(i).rightJustified(3, '0')));
> break;
> }
>
> for (auto font : document->fonts()) {
> qDebug() << font.name();
>
> }
> }
> }
>
> return result;
> }
>
> How can I extract text formatting information like boldness and font size ?
> I can’t find the link between text and font items.
As you have discovered that information is not exposed in the Qt frontend.
You can use the cpp frontend
https://poppler.freedesktop.org/api/cpp/classpoppler_1_1text__box.html
or propose a patch for the Qt frontend to expose that information.
Cheers,
Albert
>
> Martin
More information about the poppler
mailing list