Closed ic005k closed 1 year ago
If you're interested, download the Knot and try it out. Open the pdf file under "Reader." In the meantime, any suggestions and corrections are welcome. Thank you.
At the moment i cannot try it, but below some suggestions:
I see that in your main.cpp
you called QtWebView::initialize();
: this is not necessary, because it is already initialized by the QtPdfViewerInitializer
(see qtpdfviewerinitializer.cpp
). Multiple WebView's initializations could cause issues.
void QtPdfViewerInitializer::initialize()
{
// To make the Qt WebView module function correctly across all platforms,
// it is necessary to call QtWebView::initialize() before in Qt>= 5.15.0, or after in Qt<5.15.0, creating
// the QGuiApplication instance
QtWebView::initialize();
// Expose classes to qml
qmlRegisterType<LTDev::WebSocketTransport>("it.ltdev.qt.cpp.components", 1, 0, "WebSocketTransport");
qmlRegisterSingletonType<QtPdfViewerInitializer>("it.ltdev.qt.cpp.components", 1, 0, "QtPdfViewerInitializer", &QtPdfViewerInitializer::getQmlInstance);
}
in the sample app, particularly on Android devices, i needed to play with visibility
and opacity
to correctly show the pdf: the WebView
(and the PdfView
) is always shown (--> the blank page) even if a file is not loaded. So, to visualize popup errors, like the ones used in the sample, i needed to play with those properties. Maybe your view is in a state where the pdf should be shown but the view is not visible or opacity is 0.
i see that in your pdf.qml
(in onViewerLoaded
) you are setting the visibility after the pdf load, and not before:
this,
...
onViewerLoaded: {
isViewEnd = true
pdfView.load(pdfPath)
pdfView.visible = true // <-- call this before pdfView.load()
console.debug("onViewerLoaded...... " + isViewEnd)
}
should become:
...
onViewerLoaded: {
isViewEnd = true
pdfView.visible = true
pdfView.load(pdfPath)
console.debug("onViewerLoaded...... " + isViewEnd)
}
Note that setting the visibility of the WebView, will cause the reload of the WebView. The load of pdf is asynchronous, so multiple calls to the load method could cause issues.
- I see that in your you called : this is not necessary, because it is already initialized by the (see ). Multiple WebView's initializations could cause issues.
main.cpp``QtWebView::initialize();``QtPdfViewerInitializer``qtpdfviewerinitializer.cpp
That's the question. Thank you very much.
Remove QtWebView::initialize();
, everything is fine.
In addition, pdf.js seems to have a new version, I don't know if you have any plans to upgrade them, I am looking forward to it, thank you.
In my opinion, this is QML's best pdf solution for Android right now.
Remove
QtWebView::initialize();
, everything is fine
Perfect! Then i consider the issue closed :D
In addition, pdf.js seems to have a new version, I don't know if you have any plans to upgrade them, I am looking forward to it, thank you.
Nope, i haven't any plan to upgrade it to the new version: lots of work would be needed to support older qt versions and android devices. Furthermore, some changes on pdf.js
source files were needed to correctly emit signals and capture errors.
In my opinion, this is QML's best pdf solution for Android right now
Thank you! I really appreciate it! :D
Hello, in one of my project (https://github.com/ic005k/Knot) integrates the library, but found a problem, is to open the second or more files, there will be a blank, during normal open it again. At the moment, I get around this problem by opening an empty file before opening one, but I don't think this is a scientific solution. What do you think about that? thank you.
pdfView.load("") pdfView.load(pdfPath)
https://github.com/ic005k/Knot/blob/e19e5ceed53f8bc9e3a3d1f19588e1cb159640ea/pdf_module/PdfPage.qml#L35