使用 Poppler-Qt4 加载并显示 PDF 文档
- #include <poppler-qt4.h>
- //A PDF document can then be loaded as follows:
- QString filename;
- Poppler::Document* document = Poppler::Document::load(filename);
- if (!document || document->isLocked()) {
- // ... error message ....
- delete document;
- return;
- }
- // Paranoid safety check
- if (document == 0) {
- // ... error message ...
- return;
- }
- // Access page of the PDF file
- Poppler::Page* pdfPage = document->page(pageNumber); // Document starts at page 0
- if (pdfPage == 0) {
- // ... error message ...
- return;
- }
- // Pages can be rendered to QImages with the following commands:
- // Generate a QImage of the rendered page
- QImage image = pdfPage->renderToImage(xres, yres, x, y, width, height);
- if (image.isNull()) {
- // ... error message ...
- return;
- }
- // ... use image ...
- // after the usage, the page must be deleted
- delete pdfPage;
- // Finally, don't forget to destroy the document:
- delete document;
复制代码
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论