Extremely basic plugin for rendering PDF files using Poppler in QML apps.
Supported features:
- Rendering PDF pages in any resolution (controlled by
Image
itemsourceSize
property) - Parsing document links
- Document search
Based on discontinued poppler-qml-plugin by Canonical (GPL v3).
- Qt 5.11+
- Poppler-Qt5 0.31+
- Qt Quick Controls 2 (only for an example app)
qmake
make
make install
See example app sources in example directory.
Set POPPLERPLUGIN_DEBUG
environment variable to 1
before starting application.
PDFView
is pure QML component, utilizing Poppler
native component from this plugin.
It serves as a good start when you just need to display PDF document.
If it doesn't suit your purposes very well, take a look at it source and implement the view more suiting your target functionality.
This component is an extended ListView (with custom delegate and some other logic inside), so you can simply add scroll bar or customize page spacing from your application code.
import org.docviewer.poppler 1.0
...
PDFView {
anchors.fill: parent
path: "path_to_file.pdf"
}
Local file path to open.
Zoom level. Defaults to 1.0
, at this component show document at 72 dpi.
Number of pages in opened document
Number of page currently shown in a center of viewport, starting with 0.
Color of found search term highlight. Defaults to Qt.rgba(1, 1, .2, .4)
.
Starts search for a passed substring. When found, scrolls view to show the string found. Repeating calls to this method passing the same string will result in moving to next occurance of the text.
Sent when there was a problem opening a document
Sent when recently started search haven't found any occurences of string requested.
Sent when search reached the end of a document and was started from the beginning of a document.
import org.docviewer.poppler 1.0
...
Poppler {
id: poppler
path: "path_to_file.pdf"
}
ListView {
anchors.fill: parent
model: poppler.pages
delegate: Image {
cache: false
fillMode: Image.Pad
source: modelData.image
sourceSize.width: modelData.size.width
sourceSize.height: modelData.size.height
width: sourceSize.width
height: sourceSize.height
}
}
Local file path to open.
List of document pages.
Each page contains several properties
image
- url of image to be used in Image QML element. Page image will be rendered by image provider based on ImagesourceSize
propertysize
- document page size in points (i.e. 1/72th of inch). Could be used to determine Image element size before asyncronous rendering is finishedlinks
- array of page linksrect
- active link rectangle as a proportion of page size (width being .5 means 50% of page width etc.)destination
- link destinationpage
- page indextop
- top coordinate of link destination (relative to page size, same as rect property)left
- left coordinate of link destination (relative to page size)
Returns list of text highlight rectangles for the page
. May return empty array.
Sent when there was a problem opening a document.