首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Qt5.8中使用pdf.js

在Qt5.8中使用pdf.js
EN

Stack Overflow用户
提问于 2017-04-04 19:43:13
回答 2查看 2.2K关注 0票数 1

我正在尝试让Qt5.8 .I中的pdf阅读器知道popplerQt的一个选择,但我想使用pdf.js .I来做这件事,我不知道如何在Qt5.8中嵌入pdf.js。我看过pdf.jshello world文档,但它没有帮助。请帮帮我。提前谢谢。

EN

回答 2

Stack Overflow用户

发布于 2017-04-21 04:29:50

如果你想使用pdf.js,基本的想法是让一些小部件来显示超文本标记语言--看起来QWebEngineView (使用铬)可以完成这项工作,因为它只需要最少的代码就可以完成你的第一个实现。

在您的计算机上安装了pdf.js,并使用您的QT Creator准备了一个简约的gui应用程序(QT窗口小部件项目),您可以使用以下代码来获得基础知识:

代码语言:javascript
复制
#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

票数 3
EN

Stack Overflow用户

发布于 2017-04-04 20:19:39

我不知道为什么要使用pdf.js,但是您可能想看看QtLabs PDF module。它似乎相当新,并且与当前的Qt很好地集成在一起。(我猜它比JavaScript代码更高效)

如果你想尝试一下,下面是如何开始的:

代码语言: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.pdf
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43206263

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档