Редактирование: Poppler: Displaying PDF Files with Qt
Материал из Wiki.crossplatform.ru
Внимание: Вы не представились системе. Ваш IP-адрес будет записан в историю изменений этой страницы.
Правка может быть отменена. Пожалуйста, просмотрите сравнение версий, чтобы убедиться, что это именно те изменения, которые вас интересуют, и нажмите «Записать страницу», чтобы изменения вступили в силу.
Текущая версия | Ваш текст | ||
Строка 8: | Строка 8: | ||
</div> | </div> | ||
- | + | Fortunately, there are third party libraries available for some of the things that Qt doesn't provide. One of these is Poppler, a Portable Document Format (PDF) rendering library that forms the basis of a number of widely-used PDF viewing applications. Poppler is a fork of the Xpdf PDF viewer that is licensed under the GNU General Public License. Xpdf can also be obtained under other licensing terms. | |
- | Poppler | + | Poppler is designed in a way that allows it to be used with any toolkit or framework as long as a suitable rendering backend is available. Qt application developers are fortunate in that there is also a Qt frontend available—a set of Qt-style classes that use Qt classes to describe parts of PDF documents. |
[[Image:qq27-poppler.png|center]] | [[Image:qq27-poppler.png|center]] | ||
- | + | In this article, we'll take a brief look at some of the features provided by Poppler in the context of creating a simple PDF viewing application. | |
===Setting Things Up=== | ===Setting Things Up=== | ||
- | + | Developers using Linux should find that Poppler and the Qt 4 frontend are available as a package for most recent distributions. Developers on Windows, Mac OS X, and other Unix platforms can download source code from the [http://poppler.freedesktop.org poppler.freedesktop.org] Web site. | |
- | + | By default, Poppler is built with all kinds of frontends and backends. If you compile Poppler from source, you can exclude some of these to save compile time. When configuring the build, it may be easier to set the installation prefix to that used for the Qt installation—this prefix is the directory under which subdirectories containing executables, libraries and data files are stored. | |
- | + | It is important to know where the Poppler library and header files will be installed because our example will need them. | |
===Отрисовка документов=== | ===Отрисовка документов=== | ||
- | + | In our example, we provide a simple user interface to display PDF files, displaying a single page at a time and providing controls to let the user move between pages. Each page is displayed in a custom widget, <tt>DocumentWidget</tt>, held in the main window's central widget, a scroll area. | |
The user opens a new file via a file dialog, which we open in response to an action being triggered. The path to the file is passed to the <tt>DocumentWidget</tt> so that the document it contains can be fed to the Poppler library. | The user opens a new file via a file dialog, which we open in response to an action being triggered. The path to the file is passed to the <tt>DocumentWidget</tt> so that the document it contains can be fed to the Poppler library. | ||
Строка 55: | Строка 55: | ||
===Поиск текста=== | ===Поиск текста=== | ||
- | + | One of the many useful features that Poppler provides is the ability to locate specific text strings in PDF documents. Since PDF is designed to store printable rather than editable documents, it is not always easy to easily access and reconstruct the author's original text. However, Poppler does a good job of locating text in many documents, and we can expose this feature in our example. | |
- | API | + | The API for locating text provides conventional features such as case-insensitive and directional searching, but also returns information about the position of any located text on the page—since PDF is a display format, this is really the only useful information about the text we can obtain. This information can be used to indicate where any subsequent searches should begin. |
- | + | Basically, the code to perform a forward search in a given page looks like this: | |
<source lang="cpp-qt"> | <source lang="cpp-qt"> | ||
bool found = page->search(text, searchLocation, | bool found = page->search(text, searchLocation, |