qpdfjs icon indicating copy to clipboard operation
qpdfjs copied to clipboard

What about the use of Resources files ?

Open obiwankennedy opened this issue 7 years ago • 6 comments

I'm seeing those lines in your code:

auto url = QUrl::fromLocalFile(app_path+"/minified/web/viewer.html");
QDir dir(app_path+"/minified/web/");

Have you tried to use embedded resources from Qt. Instead of file beside your application it will be inside. Easier to make it movable. Do you think is it possible (or you did not try for some reason) ?

obiwankennedy avatar Jan 25 '18 13:01 obiwankennedy

I didn't try. It is a question support of qresource vfs inside of WebKit. If no then WebKit just can open such files. You can just give a try to know this.

yshurik avatar Jan 25 '18 18:01 yshurik

Ok, I tried I am able to load pdf from resource files but not from file system.

The causes is about webengineview. When you set qrc:/viewer.html, the web engine keeps the qrc:/ as the root of the protocol. So when i set the pdf path. It adds qrc:/ in front of it. The only solution is to provide a way to set pdf data instead of pdf path.

Is there a way to amend your communicator to allows setting pdf data ? It is mostly javascript. I know that pdf.js can display pdf from data.

obiwankennedy avatar Jan 30 '18 15:01 obiwankennedy

I guess so. You can make adjustments to communicator to send bytes of pdf document to js

yshurik avatar Jan 30 '18 16:01 yshurik

Another way - you may try to prepend with "file://"

yshurik avatar Jan 30 '18 17:01 yshurik

Yeah, I've tried already but it does not support different url scheme at the same time.

I modify the communicator to manage data. But on javascript side I can't find the right thing to do to load the data as data and not string/path.

obiwankennedy avatar Jan 30 '18 23:01 obiwankennedy

Hi. The solution for this is adding "qrc:" to HOSTED_VIEWER_ORIGINS in the app.js file before minifying. This makes pdf.js think it's hosted, so it can open files from any location

coyoteazul avatar Apr 29 '20 02:04 coyoteazul