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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About qt-pdf-viewer-library

flegall2014 opened this issue · comments

Hello,

I tried your application using Qt 5.15.2/MSVC2019. UI launches, but sample.pdf nevers shows up.... Only getting the main toolbar and a large gray area below. Doesn't seem to work as expected. Qt standard error is not showing error...

Questions:

  • How do I make it work?
  • How to load another file than sample.pdf?

Thanks for your help.

Best regards.

  • Have you tried with MinGW compiler?

  • To load another file, use the load method in the onViewerLoaded: path must be set only when the viewer is ready, otherwise pdf is not shown (The javascript environment needs a while to prepare the viewer).

Now, if you are loading data from:

  • qrc: use the url qrc://path/to/my/document.pdf
  • filesystem: use the url file:///path/to/my/document.pdf on linux, or path/to/my/document.pdf on windows

In case the urls are not resolved yet, you can try using Qt.resolvedUrl("path/to/my/document.pdf").

LTDev.PdfView {

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

Using MSVC2019 compiler (needed by WebView component)

Bitwise, when I launch the app, onViewerLoaded is never reached. Here my Qt console output:

19:40:52: Starting C:\projects\qt-pdf-viewer-library-master\build-pdf-viewer-Desktop_Qt_6_2_4_MSVC2019_64bit-Debug\debug\pdf-viewer.exe...
QML debugging is enabled. Only use this in a safe environment.
Qt WebEngine seems to be initialized from a plugin. Please set Qt::AA_ShareOpenGLContexts using QCoreApplication::setAttribute and QSGRendererInterface::OpenGLRhi using QQuickWindow::setGraphicsApi before constructing QGuiApplication.
"C:/Users/legal/AppData/Roaming/pdf-viewer/libs/pdfjs/viewer.html"
qml: Permission manager: BasePermissionsManager_QMLTYPE_22(0x1af0500b0d0)
qt.webenginecontext:

GLImplementation: desktop
Surface Type: OpenGL
Surface Profile: CompatibilityProfile
Surface Version: 4.6
Using Default SG Backend: yes
Using Software Dynamic GL: no
Using Angle: no

Init Parameters:

  • application-name pdf-viewer
  • browser-subprocess-path C:\Qt\6.2.4\msvc2019_64\bin\QtWebEngineProcessd.exe
  • create-default-gl-context
  • disable-es3-gl-context
  • disable-features DnsOverHttpsUpgrade,ConsolidatedMovementXY,InstalledApp,BackgroundFetch,WebOTP,WebPayments,WebUSB,PictureInPicture
  • disable-speech-api
  • enable-features NetworkServiceInProcess,TracingServiceInProcess
  • enable-threaded-compositing
  • in-process-gpu
  • use-gl desktop

qml: file://C:/Users/legal/AppData/Roaming/pdf-viewer/libs/pdfjs/viewer.html

Meaning that this:

// Signal that html viewer page has been loaded
backend.viewerLoaded()

never happens in pdf.viewer.bridge.js...

Any idea?

@flegall2014 Questions about the open files, you can refer to me to write a project: https://github.com/ic005k/Knot

The specific code is here:

https://github.com/ic005k/Knot/blob/e19e5ceed53f8bc9e3a3d1f19588e1cb159640ea/pdf_module/PdfPage.qml#L30

Qt WebEngine seems to be initialized from a plugin. Please set Qt::AA_ShareOpenGLContexts using QCoreApplication::setAttribute and QSGRendererInterface::OpenGLRhi using QQuickWindow::setGraphicsApi before constructing QGuiApplication.

Have you set the recommended attributes in the main.cpp, before QGuiApplication initialization?

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif


#ifdef Q_OS_WIN
    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);     // <---- this
    QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi);  // <---- this
#endif

...

}

Those additions could resolve the issue (at the moment i cannot try them).

Note that i developed and tested the library in a linux machine (see the testing chapter in the readme), so it is probable that windows needs other additions/adjustments.

when I launch the app, onViewerLoaded is never reached.

It does exist under Windows (Win11), I just tested it and it works for me on Mac.

The cause is unknown.

#ifdef Q_OS_WIN
    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);     // <---- this
    QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi);  // <---- this
#endif

It didn't seem to work.

But I used Qt5.15.2

"QQuickWindow: : setGraphicsApi (QSGRendererInterface: : OpenGLRhi);" I don't know if it has anything to do with it. Qt6.4 needs to be used for testing. I don't have this development environment at present.

Hello, I am having the same error in windows, did you got way to fix it?

Hello,

I tried your application using Qt 5.15.2/MSVC2019. UI launches, but sample.pdf nevers shows up.... Only getting the main toolbar and a large gray area below. Doesn't seem to work as expected. Qt standard error is not showing error...

Questions:

  • How do I make it work?

This thing, how to make it work??