[poppler] Get text formatting info
Martin Delille
martin at lylo.tv
Tue Jul 26 12:34:20 UTC 2022
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.
Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/poppler/attachments/20220726/365dc114/attachment.htm>
More information about the poppler
mailing list