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
40 stars 9 forks source link

About qt-pdf-viewer-library #1

Open flegall2014 opened 1 year ago

flegall2014 commented 1 year ago

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:

Thanks for your help.

Best regards.

develtar commented 1 year ago

Now, if you are loading data from:

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")    
    }
}
flegall2014 commented 1 year ago

Using MSVC2019 compiler (needed by WebView component)

flegall2014 commented 1 year ago

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:

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

flegall2014 commented 1 year ago

Meaning that this:

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

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

flegall2014 commented 1 year ago

Any idea?

ic005k commented 1 year ago

@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

develtar commented 1 year ago

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.

ic005k commented 1 year ago

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.

ic005k commented 1 year ago
#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.

FRAYOURSELF commented 1 year ago

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

FRAYOURSELF commented 1 year ago

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??