Giter VIP home page Giter VIP logo

qtpdfium's Introduction

QtPdfium

QtPdfium is a Qt module that renders PDF files using the pdfium project by google. It render PDF pages into QImage.

Installation

To use the library you must first install it in the same location as your Qt installation. Here is an example on Linux/Mac:

git clone --recursive https://github.com/paulovap/qtpdfium
cd qtpdfium
qmake
make
make install (might need sudo)

After that you are ready to use it. Remember to build for each platform you want. (Desktop, Android, iOS...)

Usage

The API consists in only two classes: QPdfium and QPdfiumPage.

To load a PDF file, simply do:

#include <QtPdfium/QPdfium>

QPdfium pdf("mypdf.pdf");
qDebug() << pdf.isValid(); //should return true

You can get the number of pages with QPdfium::pageCount()

You can access pages by index:

#include <QtPdfium/QPdfium>

QPdfium pdf("mypdf.pdf");
QPdfiumPage page =  pdf.page(0);
qDebug() << page.width(); // should show something!

To generate the image:

#include <QtPdfium/QPdfium>

QPdfium pdf("mypdf.pdf");
QPdfiumPage page =  pdf.page(0);
QImage image = page.image(3); //renders it 3 times bigger

And for extracting text:

#include <QtPdfium/QPdfium>

QPdfium pdf("mypdf.pdf");
QPdfiumPage page =  pdf.page(0);
QString pageText = page.text();

Note: On iOS you need to initialize QtPdfium manually since it is statically linked. Just create a global object like this:

#ifdef Q_OS_IOS
    //Since it's static library on IOS we need to initialize it by hand
    PdfiumGlobal global;
#endif

And that's it.

Future work

  • Load pdf with encryption (passwords)
  • Text manipulation (find, extract, cursor..)
  • Partial rendering
  • Render to other devices (gl surface, so on..)

Contributing

Feel free to help. :)

License

BSD

qtpdfium's People

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.