Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF to QPainter calls or SVG? #18

Open
twardoch opened this issue Feb 10, 2017 · 2 comments
Open

PDF to QPainter calls or SVG? #18

twardoch opened this issue Feb 10, 2017 · 2 comments

Comments

@twardoch
Copy link

There is a high-quality BSD-licensed PDFium parsing and rendering library, maintained by Google and originated at Foxkit:
[1]: https://pdfium.googlesource.com/pdfium/

Qt has recently published a "labs module" to render a PDF into a QImage using the PDFium library:
[2]: http://blog.qt.io/blog/2017/01/30/new-qtpdf-qtlabs-module/
[3]: https://github.com/qt-labs/qtpdf

There is also another Qt-based similar project, QtPDFium:
[4]: https://github.com/paulovap/qtpdfium

There is also the Google Skia library, a performant 2D graphics library, also opensource:
[5]: https://skia.org
[6]: https://github.com/google/skia
[7]: https://skia.org/user/api/skcanvas

Now, PDFium has a Skia backend, which means that it can render a PDF onto an SkCanvas canvas:
[8]: https://pdfium.googlesource.com/pdfium/+/master/core/fxge/skia/
[9]: https://github.com/amplab/ray-core/blob/master/src/examples/ui/pdf_viewer/pdf_viewer.cc

And on the other hand, Skia has an SkSVGCanvas backend, which can render an SkCanvas into SVG:
[10]: https://github.com/google/skia/tree/master/include/svg
[11]: https://github.com/google/skia/tree/master/src/svg
[12]: https://github.com/google/skia/blob/master/include/svg/SkSVGCanvas.h
[13]: https://github.com/google/skia/blob/master/src/svg/SkSVGCanvas.cpp

And this seems to be a project that translates QPainter API calls to Skia API calls:
[14]: https://github.com/telishev/sneakPic/blob/master/src/renderer/qt2skia.h
[15]: https://github.com/telishev/sneakPic/blob/master/src/renderer/qt2skia.cpp
[16]: https://github.com/telishev/sneakPic
[17]: https://github.com/telishev/sneakPic/blob/master/src/renderer/renderer_item_svg.cpp

The qt2skia.cpp looks very trivial.

There seem to be several options:

  1. Bundle Skia with the Qt app and use [the Skia backend of PDFium][8] to render the PDF via PDFium onto a Skia canvas, and then use [SkSVGCanvas][10] to generate an SVG from the Skia canvas, which then can be consumed by the Qt app. This would have the advantage of actually being free from any Qt dependencies, i.e. one could make a "sk-pdf2svg" commandline app that converts PDF to SVG via PDFium+Skia.

  2. Bundle Skia with the Qt app, use [PDFium+Skia][8] to render the PDF via PDFium onto a Skia canvas, and then adapt [qt2skia][17] to do the reverse (translate Skia canvas API calls to QPainter API calls).

  3. Skip Skia altogether, and develop a QPainter backend for PDFium modeled after [the Skia backend of PDFium][8].

If anyone is up to doing any of the above and publishes the results under a liberal opensource license, I’ll be most happy.

@paulovap
Copy link
Owner

Hi @twardoch, an interesting compilation! I would prefer to keep Qt as the only dependency so it would be better to user QPainter or QtSvg package. Feel free to contribute!

@iondevsrl
Copy link

Hi,

Is there a chance to get QtPdfium to render a PDF document to a QPainter, instead of a QImage?
Any work on this has been started?

Thanks in advance for your answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants