我在使用 poppler 库显示 pdf 的功能时遇到了一些问题。下面的代码是出现问题的函数。
const QString &file 是文件的路径 int page 是它必须打开的页面
当我将文件设置为真实路径(例如“/Users/User/Documents/xxx.pdf”)时,打开它是没有问题的。但是当我给出一个 qrc 文件的路径(“:/files/xxx.pdf”)时,它就不起作用了。例如,我想用它在应用程序中显示用户手册。
我也尝试过首先从中制作一个 QFile,打开它并执行 readAll,然后加载通过 do 接收到的 QByteArray Poppler::Document::loadFromData(the qbytearray)
,但是在 ReadOnly 模式下打开 QFile 时它已经出错了。
void class::setPdf(const QString &file, int page)
{
Poppler::Document *doc = Poppler::Document::load(file);
if (!doc) {
QMessageBox msgbox(QMessageBox::Critical, tr("Open Error"), tr("Please check preferences: cannot open:\n") + file,
QMessageBox::Ok, this);
msgbox.exec();
}
else{ /*Code for displaying the pdf, which works fine*/
}
}
我希望你能帮帮我,
问候,
马特