vs+qt5.0 使用poppler-qt5 操作库获取pdf所有文本输出到txt操作

先获取poppler库,编译出lib与dll,配置好依赖环境,获取某页所有文本:

QList<QString> PDFkitEngine::GetText(int nPageNum)

{

QList<QString> lstText;

Poppler::Page* pPage = NULL;

pPage = GetPage(nPageNum);

if (pPage == nullptr)

{

return lstText;

}

QList<Poppler::TextBox* > lstTexts = pPage->textList();

if (lstTexts.count() == 0)

{

return lstText;

}

for (int i = 0;i < lstTexts.count();i++)

{

lstText.append(lstTexts.at(i)->text());

}

return lstText;

}

输出到txt文本:

void PDFkitEngine::outputText(const QString& strfileName, QList<QString>& vecText)

{

QFile file(strfileName);

if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))

{

return;

}

QTextStream textStream(&file);

for (auto& _info : vecText)

{

textStream << _info << endl;

}

file.close();

}

测试效果是可以将pdf文本全部读出来,并且成功的输出到文本文件,但是有点瑕疵是,pdf读出来的一行数据内容可能会分成2行或者多行,但是文本获取没有问题

相关推荐
xcyxiner15 小时前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner1 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner2 天前
DicomViewer (添加模型类)3
qt
xcyxiner2 天前
DicomViewer (目录调整) 2
qt
xcyxiner2 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能4 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
weixin_397574094 天前
PDF复杂表格的1:1还原引擎:跨页表格自动拼接技术实战
大数据·人工智能·pdf
Metaphor6924 天前
使用 Python 将 PDF 转换为 HTML
python·pdf·html
2601_961845154 天前
粉笔行测5000题电子版|pdf|解析
pdf·新媒体运营·github·个人开发·内容运营·规格说明书·极限编程
森G4 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt