I have found a solution you can post messages to webview through the experimental APIs also you can receive messages here is a code sample
main.qml
import QtQuick 2.2
import QtQuick.Window 2.1
import QtWebKit 3.0
import QtWebKit.experimental 1.0
Window {
visible: true
width: 360
height: 360
WebView{
id: webview
anchors.fill: parent
url: "file:///D:/workspace/pdf.js/web/viewer.html"
experimental.preferences.navigatorQtObjectEnabled: true
}
MouseArea {
anchors.fill: parent
onClicked: {
var data = pdfLoader.loadPDF( "D:/Secrets_of_Success.pdf" );
webview.experimental.postMessage( data );
console.log( "data= " + data );
}
}
}
import QtQuick 2.2
import QtQuick.Window 2.1
import QtWebKit 3.0
import QtWebKit.experimental 1.0
Window {
visible: true
width: 360
height: 360
WebView{
id: webview
anchors.fill: parent
url: "file:///D:/workspace/pdf.js/web/viewer.html"
experimental.preferences.navigatorQtObjectEnabled: true
}
MouseArea {
anchors.fill: parent
onClicked: {
var data = pdfLoader.loadPDF( "D:/Secrets_of_Success.pdf" );
webview.experimental.postMessage( data );
console.log( "data= " + data );
}
}
}
To copy to clipboard, switch view to plain text mode
and here is the js file
navigator.qt.onmessage = function(ev) {
//eval(ev.data);
var data = ev.data;
var buf = new ArrayBuffer(data.length * 2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen = data.length; i<strLen; i++) {
bufView[i] = data.charCodeAt(i);
}
PDFJS.getDocument(buf);
}
navigator.qt.onmessage = function(ev) {
//eval(ev.data);
var data = ev.data;
var buf = new ArrayBuffer(data.length * 2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen = data.length; i<strLen; i++) {
bufView[i] = data.charCodeAt(i);
}
PDFJS.getDocument(buf);
}
To copy to clipboard, switch view to plain text mode
but still i have a problem sending the file to pdf.js library
I am reading the file and send the QBytearray directly to the js file (UInt8Array) but it is not able to load the pdf file
Do have any ideas how to could i read the file and send it to the pdf library?
Bookmarks