我想将 PDF 查看器添加到我目前正在使用的嵌入式设备中,该设备在 Xilinx Zynq SoC 上运行 Linux/Qt5。通常,该设备非常快,可以处理一些体面的工作负载,例如使用 QCustomPlot 每 100 毫秒绘制一个 8192 点图。
我遇到了 Poppler/libpoppler,并认为手头的任务是完美的,即显示 PDF。我编写了一些演示代码,从这段代码中调用 poppler 的 renderToImage() 方法需要将近 1 分钟,以便我可以将 PDF 转换为图像以显示在 UI 上。
有没有人使用过 Poppler-Qt5 并找到类似的结果或加快速度的方法?如果没有,我应该看看其他与 Qt 很好集成的库吗?
这是我的演示代码片段:
// Load pdf
Poppler::Document* document = Poppler::Document::load("/tmp/test.pdf");
document->setRenderHint(Poppler::Document::Antialiasing);
document->setRenderHint(Poppler::Document::TextAntialiasing);
if (!document || document->isLocked() || document == 0 )
{
cout << "ERROR" << endl;
}
Poppler::Page* pdfPage = document->page(0);
if (pdfPage == 0)
{
cout << "ERROR" << endl;
}
// Generate a QImage of the rendered page
QImage image = pdfPage->renderToImage(72.0,72.0,0,0,pdfPage->pageSize().width(),pdfPage->pageSize().height());
if (image.isNull())
{
cout << "ERROR" << endl;
}
ui->label->setPixmap(QPixmap::fromImage(image));
ui->label->show();
// after the usage, the page must be deleted
delete pdfPage;
delete document;