Giter Club home page Giter Club logo

poppler-qml-plugin's Introduction

Poppler QML plugin

Extremely basic plugin for rendering PDF files using Poppler in QML apps.

Supported features:

  • Rendering PDF pages in any resolution (controlled by Image item sourceSize property)
  • Parsing document links
  • Document search

Based on discontinued poppler-qml-plugin by Canonical (GPL v3).

Example application screenshot

Requirements

  • Qt 5.11+
  • Poppler-Qt5 0.31+
  • Qt Quick Controls 2 (only for an example app)

Build and install

qmake
make
make install

Example

See example app sources in example directory.

Debugging

Set POPPLERPLUGIN_DEBUG environment variable to 1 before starting application.


Using PDFView QML component

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"
}

Properties

string path

Local file path to open.

bool loaded

real zoom

Zoom level. Defaults to 1.0, at this component show document at 72 dpi.

int count

Number of pages in opened document

int currentPage

Number of page currently shown in a center of viewport, starting with 0.

color searchHighlightColor

Color of found search term highlight. Defaults to Qt.rgba(1, 1, .2, .4).

Methods

search(string text)

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.

Signals

error(string errorMessage)

Sent when there was a problem opening a document

searchNotFound

Sent when recently started search haven't found any occurences of string requested.

searchRestartedFromTheBeggining

Sent when search reached the end of a document and was started from the beginning of a document.


Using Poppler object

Opening PDF 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
  }
}

Properties

string path

Local file path to open.

bool loaded

array pages

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 Image sourceSize property
  • size - document page size in points (i.e. 1/72th of inch). Could be used to determine Image element size before asyncronous rendering is finished
  • links - array of page links
    • rect - active link rectangle as a proportion of page size (width being .5 means 50% of page width etc.)
    • destination - link destination
      • page - page index
      • top - top coordinate of link destination (relative to page size, same as rect property)
      • left - left coordinate of link destination (relative to page size)

Methods

array[rect] search(int page, string text)

Returns list of text highlight rectangles for the page. May return empty array.

Signals

error(string errorMessage)

Sent when there was a problem opening a document.

poppler-qml-plugin's People

Contributors

cyberbobs avatar mtuner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

poppler-qml-plugin's Issues

Plugin installation

Hi,

My setup:

  • Ubuntu 19.04
  • Poppler-0.82.0 installed
  • QtCreator with Qt 5.13.1
  • libpoppler-qt5-dev and libpoppler-qt5-1 installed

Copied Poppler-QML-plugin directory in /home/andrea/Qt/ then inside:
qmake
make
make install
And it showed no error.

If I try to open the inclued example in QtCreator it gives me:
qrc:/main.qml:9 module "org.docviewer.poppler" is not installed

What I'm doing wrong?

Thanks for your support

Unable to pan left/right when zoomed in

When you zoom in on a PDF and it seems to zoom in on the center of the page and not allow you to pan to the left or the right to see the content. Is there a way to enable this behavior? Thanks!

Segmentation faults galore with poppler 0.82

Hi,
I am using this plugin in one of my projects. I'd have to say it works quite well. However, it crashes a lot. I've tried it on both x86_64 Linux PC and Raspberry Pi 4 (64-bit) OS, Custom Poky/Yocto distro.

Reproducing the crashes:

It seems to me like "loaded" flag does not function correctly. It is almost always true. Shouldn't there be a flag for "document completely loaded"? If the document is not visible and waiting for the load because you zoomed and you select a new file, you get a Segmentation fault. (possibly related to poppler)
Also, after you select .pdf file it also gives Segmentation fault randomly. This does not happen on PC if you wait 5 second between .pdf file selections. If you do it quickly, it even crashes on PC.
"Error (0): Call to Object where the object was type 13, not the expected type 7"

I am using poppler 0.82 with Qt 5.13.0.
Do you have any suggestions or validated versions to avoid such problems? Thank you.

Single Page Display Mode

Is it possible to display one page at a time with fit to screen width or Screen Height
Right now it is in continuous scrolling mode with multiple pages ( pages are one below the other )

Thanks

Using the plug in

Hi,

i open the Poppler-QML-plugin in Qt creator and build it with no errors.
How do i use the plug in?
If i include it like this #include <poppler-qt5.h> i get an error: "no such file or directory"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.