我正在尝试让Qt5.8 .I中的pdf阅读器知道poppler是Qt的一个选择,但我想使用pdf.js .I来做这件事,我不知道如何在Qt5.8中嵌入pdf.js。我看过pdf.js的hello world文档,但它没有帮助。请帮帮我。提前谢谢。
发布于 2017-04-21 04:29:50
如果你想使用pdf.js,基本的想法是让一些小部件来显示超文本标记语言--看起来QWebEngineView (使用铬)可以完成这项工作,因为它只需要最少的代码就可以完成你的第一个实现。
在您的计算机上安装了pdf.js,并使用您的QT Creator准备了一个简约的gui应用程序(QT窗口小部件项目),您可以使用以下代码来获得基础知识:
#include "mainwindow.h"
#include <QApplication>
#include <QWebEngineView>
static QString pathToPDFjs = QString("file:///path-to/pdfjs-1.8.170-dist/web/viewer.html");
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow win;
QWebEngineView *view;
QString pdfFileURL;
//you could parse a widget to get the file name
pdfFileURL = QString("file:///path-to-your/file.pdf");
//init the view and attach it to the ui
view = new QWebEngineView();
win.setCentralWidget(view);
win.show();
//auto-load feature in pdf.js, pass file=filename as parameter
view->load(QUrl::fromUserInput(pathToPDFjs + QString("?file=") + pdfFileURL));
view->show();
return app.exec();
}从那时起,您可以向您的用户界面添加额外的功能。您甚至可以在您的pdf.js安装中添加修改(如果需要)。
如果你需要在你的pdf.js上调用JavaScript,你可以使用视图的页面(一个QWebEnginePage),它可以runJavaScript。

发布于 2017-04-04 20:19:39
我不知道为什么要使用pdf.js,但是您可能想看看QtLabs PDF module。它似乎相当新,并且与当前的Qt很好地集成在一起。(我猜它比JavaScript代码更高效)
如果你想尝试一下,下面是如何开始的:
git clone git://code.qt.io/qt-labs/qtpdf
cd qtpdf
git submodule update --init --recursive
qmake
make
cd examples/pdf/pdfviewer
qmake
make
./pdfviewer /path/to/my/file.pdfhttps://stackoverflow.com/questions/43206263
复制相似问题