Rendering PDF Content with XpdfWidget

By Chris Cortopassi

A consulting project I worked on recently needed to display an interactive PDF document in the style of Adobe Reader on a touchscreen device running embedded Linux using Qt and QML. I have been working with Qt for nearly ten years and had not come across this requirement before, so of course I turned to the Internet to see what was available and I came across this page, which lists all options available for dealing with PDF files from Qt.

Amazingly, Qt natively supports writing PDF files using a few lines of code via QPrinter. However, it does not support reading or rendering PDF files out of the box. The Qt Project page lists third party solutions, but only one, XpdfWidget/Qt by Glyph & Cog, is not licensed under the GNU General Public License (GPL). It is offered under a commercial license, which is what I needed for my project.

After looking at the XpdfWidget/Qt description and documentation, it looked like it would work. Although my project used QML, XpdfWidget is a QWidget subclass, so I could overlay it on top of some QML.

I went ahead and contacted Glyph & Cog to obtain an evaluation copy of XpdfWidget/Qt (which ships as source code), and I was able to quickly build the static library and run the demo application that comes with it as shown below:

The client purchased a license and I proceeded to put together some QML to lay underneath the XpdfWidget:

Then, I developed a prototype to lay XpdfWidget on top of QML under Microsoft Windows and finally brought the code over to the embedded Linux target, seen below:

Conclusions

If your application deals with PDF files in any capacity, please contact Glyph & Cog. They were extremely helpful throughout the entire development process.

References

  1. Handling PDF Qt project Wiki page, accessed 12 Dec 2014, qt-project.org/wiki/Handling_PDF
  2. Glyph & Cog website, accessed 12 Dec 2104, glyphandcog.com

Have a question or want to add to the conversation?

You must be logged in to continue.

Log in Register