📜 ⬆️ ⬇️

The tragic story of dating with poppler

... Or as we wrote a pilot application for OS Sailfish using poppler.

The year began with an amusing task - our team needed to assemble a pilot of the application “Mobile manager’s workplace” on the Sailfish OS in a short time. In fact, this is a mobile client, EDS, i.e. It is designed to work with documents. And of course, a pdf-reader is needed to work with documents. But it turned out that making it work smoothly is not so easy. But we can say we did it (for the prototype, of course). How? Read under the cut.

image

From the good, I can say that the pdf-reader built into the operating system is simply wonderful, no need to separately assemble. And "Aurora" (it seems like this is the future "Russian" name for the hard-to-pronounce "Sailfish Mobile OS Rus") can boast of this, for which she thanks a lot. But still writing a quick solution was not so easy.

Poppler is a pdf rendering library built into Sailfish, which is why it was chosen for our dark purposes. But only for writing a prototype, because the GPL license will not allow in the future to release on it a commercial product. And, having touched it a little, I come to the conclusion that there must be more convenient solutions, but more on that later.

I would like to tell you about the two main problems that I faced, trying to squeeze at least something from the poppler in a short time. I propose to watch a video demonstrating the work of the application, which turned out before reading my nagging.


Problem number one


See the beautiful carousel? This is a way to display documents by folders - intuitive and easy for the user, allows you to quickly view documents, details on it, before going directly to reading the document and approval. It is necessary so that important ministers, signing their very important documents, can look at their eyes to delight PathView.

PathView is a great tool, you can make a bunch of all kinds of beauty. But our problem is delegate.

To draw the first page of the document (document preview on the main screen) online using poppler is an idea so-so, because the folders are not cached and the transition between them starts to hang incredibly, the poppler draws slowly. More precisely renders, draws, of course, QPainter.

The problem is solved simply, but not at all elegantly: we render the preview when the application starts, save the image to the device, and finally draw through the QImage in the delegate. And, frankly, how to rewrite it in a more elegant form, I have not yet invented.

Problem number two


If you try to draw a large document all at once (the page that displays the content of the document), it is not enough that it does this for a very long time, it also blurs the picture. I thought, I messed up with the dimensions, that the document is rendered into a small-sized image, and then stretches it by a specified amount, but no, I checked everything 100 times. I tried to make a bigger picture - everything is the same. Yes, and smears not as a loss of quality, but rather, as if we had a hand in fresh ink.

This, of course, is solved in one fell swoop; you need to draw not the entire document, but only the current page and the neighboring pages, but you have not had time to do it yet.

Total


Poppler is slow and strange, but thanks for being there. Now we want to implement the pdf graphic and text annotations as part of the pilot, so I’m going to rewrite the whole thing to another library , this is something incredibly powerful at first glance, I hope that the declared functionality actually corresponds.

If anyone has tried or knows the solution is more appropriate, I will be most grateful for the advice.

Source: https://habr.com/ru/post/440864/