develtar / qt-pdf-viewer-library

The qt-pdf-viewer-library is a qml wrapper of pdf.js library which allows you to render PDF files in a WebView. This library also works on Android devices, and it uses WebSocketServer, WebSocketTransport and WebChannel to exchange data between qml and the browser environment.
Apache License 2.0
41 stars 9 forks source link

Step-By-Step #5

Open FRAYOURSELF opened 1 year ago

FRAYOURSELF commented 1 year ago

How to set it up step-by-step. I am new to qt so stuck at various portions. Help me please. qt_ss

develtar commented 1 year ago

Hi @FRAYOURSELF,

the library comes with a sample app which is used to showcase the features of the library. To try the sample app, open the 'pdf-viewer.pro' file with Qt creator.

To start from scratch, you need to create a qt quick project first:

Screenshot_20230405_202220

Then follow those steps (as stated in the section of the README):

QML_IMPORT_PATH += $$PWD/libs/qt-pdf-viewer-library/
QML_DESIGNER_IMPORT_PATH += $$PWD/libs/qt-pdf-viewer-library/
include($$PWD/libs/qt-pdf-viewer-library/qtpdfviewer.pri)
#include "it/ltdev/qt/cpp/components/qtpdfviewerinitializer.h"

int main(int argc, char *argv[])
{
  ...

  // Initialize QtPdfViewer library
  // To make the pdf module to function correctly across all platforms,
  // it is necessary to call QtPdfViewerInitializer::initialize()
  // before in Qt>= 5.15.0, or after in Qt<5.15.0, creating
  // the QGuiApplication instance
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
  LTDev::QtPdfViewerInitializer::initialize();
  QGuiApplication app(argc, argv);
#else
  QGuiApplication app(argc, argv);
  LTDev::QtPdfViewerInitializer::initialize();
#endif

  // Delete QtPdfViewer instance on app close
  QObject::connect(&app, &QGuiApplication::aboutToQuit, LTDev::QtPdfViewerInitializer::getInstance(), LTDev::QtPdfViewerInitializer::deleteInstance);

 QQmlApplicationEngine engine;

 // Needed to import the custom module
 engine.addImportPath("qrc:/");
 engine.addImportPath(":/");
  ...
}
import it.ltdev.qt.qml.components 1.0 as LTDev

ApplicationWindow {
      ...

      LTDev.PdfView {
          id: pdfView

          anchors.fill: parent

          onViewerLoaded: {
              // Load pdf only when viewer is ready
              pdfView.load("path/to/my/document.pdf")
          }

          onPdfLoaded: {
              // Pdf has been correctly loaded
          }

          onError: {
             // Some error occurred
             console.error("Error: ", message)
          }
      }
}

Anyway, for more info, give a look to the sources of the sample app :D

FRAYOURSELF commented 1 year ago

On trying to build the project why I am getting this err

FRAYOURSELF commented 1 year ago

For the qt quick application where is the .pro file?? image