Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

PDF Utils

Felgo includes useful PDF features to work with PDF files.

Display a PDF as Image

PDFPage Image Provider

Felgo includes the pdfpage image provider to show a PDF page from a given PDF file path as image.

To show the first page of a PDF, use the following source for an AppImage:

 AppImage {
   source: "image://pdfpage/" + pdfPath
 }

To show a specific page of a PDF, use the following source for an AppImage:

 AppImage {
   source: "image://pdfpage/" + pdfPath + ":" + pageNumber
 }

Supported Platforms

The pdfpage image provider is supported on Android, iOS and macOS platforms and uses the native platform APIs.

For iOS and macOS, you need to link the PDFKit framework. Open your project's .pro file and add the following lines:

 macx|ios {
   LIBS += -framework PDFKit
 }

PDFViewer Example

The following example demonstrates how to use the image provider for a PDF viewer that downloads a PDF from the web:

 import QtQuick 2.0
 import Felgo 3.0

 App {
   id: app

   property int pageIndex: 0

   onPageIndexChanged: {
     if (pdfDownload.available) {
       pdfImage.source = "image://pdfpage/" + pdfDownload.storagePath + ":" + pageIndex

     }
   }

   DownloadableResource {
     id: pdfDownload

     extractAsPackage: false
     source: "https://felgo.com/resources/Felgo_Handout_for_Qt_Developers.pdf"

     Component.onCompleted: {
       if (pdfDownload.status === DownloadableResource.UnAvailable) {
         pdfDownload.download()
       }
     }
   }

   NavigationStack {
     id: stack

     Page {
       leftBarItem: IconButtonBarItem {
         icon: IconType.arrowleft
         onClicked: app.pageIndex--
       }

       rightBarItem: IconButtonBarItem {
         icon: IconType.arrowright
         onClicked: app.pageIndex++
       }

       title: "Page: %1".arg(pageIndex + 1)

       AppImage {
         id: pdfImage
         fillMode: Image.PreserveAspectFit
         anchors.fill: parent

         source: pdfDownload.available ? "image://pdfpage/" + pdfDownload.storagePath : ""

         smooth: true
         sourceSize.width: width
         asynchronous: true

         onStatusChanged: {
           if (status === Image.Null) {
             pageIndex = 0
           }
         }
       }

     }
   }
 }
Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded