Qt Pdf Viewer Library Installation Instructions
Usage
To use the qt-pdf-viewer-library in your app, follow these steps:
- include the library in your
.pro:
QML_IMPORT_PATH += $$PWD/libs/qt-pdf-viewer-library/
QML_DESIGNER_IMPORT_PATH += $$PWD/libs/qt-pdf-viewer-library/
include($$PWD/libs/qt-pdf-viewer-library/qtpdfviewer.pri)
- initialize the library in your
main.cppjust beforeQGuiApplicationinstantiation, and connect theaboutToQuitsignal, emitted on app close, with theQtPdfViewerInitializersingletondeleteInstancemethod to allow the correct deletion of the initializer instance:
int main(int argc, char *argv[])
{
...
// Initialize QtPdfViewer library
// To make the pdf module to function correctly across all platforms,
// it is necessary to call QtPdfViewerInitializer::initialize() before creating
// the QGuiApplication instance.
LTDev::QtPdfViewerInitializer::initialize();
QGuiApplication app(argc, argv);
// Delete QtPdfViewer instance on app close
QObject::connect(&app, &QGuiApplication::aboutToQuit, LTDev::QtPdfViewerInitializer::getInstance(), LTDev::QtPdfViewerInitializer::deleteInstance);
...
}
- then, in qml import the library
import it.ltdev.qt.qml.components 1.0, and use the providedPdfViewclass.
import it.ltdev.qt.qml.components 1.0 as LTDev
ApplicationWindow {
...
LTDev.PdfView {
id: pdfView
anchors.fill: parent
onViewerLoaded: {
// Load pdf only when viewer is ready
pdfView.load("path/to/my/document.pdf")
}
}
}
-
(Android only) since
Android 9or higher, in order to view remote document from an HTTP url, is necessary to addandroid:usesCleartextTraffic="true"in theapplicationtag of themanifest.xml. Since that version cleartext support is disabled by default.
<application android:usesCleartextTraffic="true" ...>
-
(Android only) on
Androidpermissionandroid.permission.READ_EXTERNAL_STORAGEmust be added in themanifest.xml, and sinceAndroid 9, it must be also asked at runtime (see sample app).
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>