QPdfDocument/QPdfView: How to display an animated PDF? - c++

I implemented a PDF Viewing widget in C++ using Qt, loosely based on https://doc.qt.io/qt-5/qtpdf-pdfviewer-example.html, using the pdfwidgets module. (For this question, we can assume that I copied the code in that link 1:1).
This works well so far.
But now the thing is, the PDF I want to display happens to be an animated PDF. Opened in a regular viewer like Acrobat, it will show a short sequence. That sequence is located on a single page, the frames are not different slides.
In the documentation of the QPdfDocument and the QPdfPageNavigation classes, I can't find any functionality that deals with animated pages. It would suffice if I had any way to set the current animation phase.
Is this possible at all? If so, how?

It's not implemented at the moment. On Windows, you could use an ActiveQt widget to embed Acrobat Reader inside your application, if present. Otherwise you'd need to find a PDF rendering library - most likely a commercial one - that has such support.

Related

Making a fancy looking window with messages stack

I try to make fancy looking messages viewer, where messages divided by formatting, other background of smth. similar. They need to looks like this - http://pastebin.com/GU1Lq087. What I found in wxWidgets to solve this problem, and why I can't use it:
wxHtmlWindow
Supports minimal HTML (a few tags). But big problem with this - html representation doesnt fill parent window. So element with width=100% will have 100% width only on standard window size. And even p tag doesnt have word wrapping (long long paragraph goes in one line with vertical scroolbar).
wxWebWiew
I need to have the ability to set generated HTML to it, but IE must to load some page first and I can rely only on IE background. It has some time to load page, even if I set HTML-string.
wxRichText
Most suitable for me. But I can't draw line like HTML's hr, or change background for the entire message block (to distinguish it from common background)
I need to show messages like this. But i didn't know how and which tool is better.
One way of achieving this would be using wxWebView with WebKit backend but I am afraid that Windows can only use IE's engine. However, there is project which allows you to use Gecko engine. I use WebKit for rendering chat in my application and it works really good (although I am using Qt). (http://www.kirix.com/labs/wxwebconnect.html)
You can always do it regular way - just create separate widget (I think it is called "frame" in wxWidgets) for single message. This way you get almost infinite possibilities. E.g. you can make "AbstractMessage" with virtual methods and then things like "AdministratorMessage", "MOTD" etc. will be a breeze.
wxRichText Most suitable for me. But I can't draw line like HTML's hr
Really? Have you looked at the docs?
( http://docs.wxwidgets.org/trunk/overview_richtextctrl.html )
Here's a couple simple ideas:
a. Write a line of blanks, underlined.
http://docs.wxwidgets.org/trunk/classwx_rich_text_ctrl.html#a333b2e675617ed2299cf91e7c0dbd0d8
b. Create an image of a horizontal line, display it using WriteImage
http://docs.wxwidgets.org/trunk/classwx_rich_text_ctrl.html#a1315611c0741d03e852ee26eba3a9d94
The funny thing is that what you want can be done using any of the 3 controls you mention. With wxHtmlWindow you just need to set its size correctly, with wxWebView I don't understand what your problem with it is at all and with wxRichTextCtrl you could just use separate controls for the areas with different backgrounds (you could almost certainly use a single control with different styles but using several controls seems simpler).

programmatically feed a kml-file and retrieve/generate a .png-file

How can I, programmatically, draw a KML-file (routing information on a map) onto a map and then save the result to a .png-file?
What I try to accomplish: a program of mine (written in C++) produces a route. Now I would like this program to emit a .png-file instead with the route draw on it.
I've looked into the google maps api as well as others (e.g. cartagen) but google maps is java-script oriented and cartagen produces html5 output.
Probably you can use Qt Framework to achive this.
It has great XML support so it should be easy to read KML.
It has support for drawing simple shapes.
It has support for PNGs too.
There is also library called libkml - it can probably help you with manipulating with KML files.
I highly doubt if there is any "Ready to Use" solution.

Java library to create and dynamically modify business diagrams

I am looking for a good java library to manipulate box, arrows and labels in order to dynamically create and fill diagrams like the following and render them to a png :
Another example
I can create a static template to be filled later, but I will need to dynamically create labels for every box and edges in the diagrams.
For now I have tried using batik to manipulate an svg template but creating multiline labels for the edges is proving quite complicated. The SVG way with batik seems to force me to create 1 text object for each label line with absolute positioning for each which is a real pain.
I would like to be able to define the label specifying only the text and the link they relate to, eventually some hints as to how it should be placed and let the library place them.
Any suggestions ?
If this is in a commercial scenario, the Java graph drawing library yFiles can be a good match for your requirements:
You can use a convenient API to create and style your diagram and automatically layout the diagram with lots and lots options to constrain the resulting layout to suit your needs.
Multi-line and (simple) HTML labels are supported out-of-the-box.
Also you can export to PNG (as well as other pixel based image formats) and vector graphics formats like SVG, PDF, EPS.
This can be done both in a regular Java (Swing) application as well as in a headless environment (e.g. to create images on a server and to send them to a web-based thin client dynamically).
To get a feel what can be done using that library, I suggest you take a look at the freely available graph editor application "yEd" that is based on yFiles and lets you try out the above steps in an interactive manner.
(Disclosure: I work for yWorks, but on Stackoverflow I do not represent my employer.)

How to open and display a PDF file using Qt/C++?

I am trying to open and read a PDF file using Qt, but there is no specific way to do that.
I know the subject is a bit old, but...
I found a really simple way to render PDFs in Qt via QtWebKit using pdf.js (http://mozilla.github.com/pdf.js/).
Here is my realization of the idea for Qt5 and the WebEngine: https://github.com/Archie3d/qpdf
Qt itself does not include PDF reading/rendering functionality as far as I know. You might want to have a look at libpoppler which has Qt bindings.
I found this very interesting article on qt-project.org - "Handling PDF - Qt Project".
This page discusses various available options for working with PDF documents in a Qt application. The page does not exactly show how to "open and display an existing PDF document" but it can help you deduce something useful out of all that is explained there.
Here, the page says:
For rendering pages or elements from existing PDF documents to image
files or in-memory pixmaps (useful e.g. for thumbnail generation or
implementing custom viewers), third-party libraries can be used (for
example: poppler-qt4 (freedesktop.org) and muPDF (mupdf.com)).
Alternatively, the task can be delegated to existing command-line
tools (like poppler-utils (freedesktop.org) and muPDF (mupdf.com)).
You can use PdfViewer which is a lightweight PDF viewer that only uses Qt. It contains a PdfView widget which can be easily embedded in your application.
Simple answer : it is not supported in the Qt API.
Other answer : you can code it, I suggest you have a look at this Qt application which uses Ghostscript
The best way I have found to open a pdf is using QProcess in Qt.
You may want to use okular for pdf proccessing.
I know this is an old post, but I stumbled on it during my initial search so I figured I would post some documentation from the solutions I used.
As of Qt 5.10
Check out the QPdfDocument Class. This class can open a PDF and you can use the render function to render a page to an image. I use the QQuickPaintedItem to then "draw" this image but I am sure there are more ways to handle the QImage output.
Prior to Qt 5.10
I used libpoppler to do a VERY similar process.
#include <poppler/qt5/poppler-qt5.h>
Use the Poppler::Document Class to load and handle the entire PDF document and look at the Poppler::Page::renderToImage function to output the page as a QImage.
Qt does not support reading PDF files out of the box and among many approaches you can use Adobe's PDF Reader ActiveX object along with a QAxObject.
You may want to check out this link which describes how to read PDF files in Qt/C++ using ActiveX and has a downloadable example project.

HTML renderer drop-in, C++ code

I want to drop in an HTML renderer that will basically be used for render-to-texture operations.
If I can render the HTML to an HDC, that would be perfect.
I found HTMLayout, which isn't bad. But it isn't open source. But I'm wondering if there's a way to somehow tap into IE or Mozilla/Gecko code, how realisitic/difficult this will be, and possibly some pointers on how to do it.
It will be for a regular straight C++ directx application
Edit
Wow! Mozilla has an embedding kit!
Take a look at WebKit.
Qt can do it, render to a QPainter. See for example http://doc.trolltech.com/4.6/qwebpage.html But not sure if it's easily used if you are not already using Qt.