I've a really simply html file with only a simple link

<a href="output.pdf">Get the file</a>

I want, for example on Windows, user can see the pdf in Adobe Reader as if downloaded and opened from browser.

But when I launch nw.exe C:\Node-WebKit-Project and click on the link, on the console I see this:

Resource interpreted as Document but transferred with MIME type application/pdf: "file:///C:/Node-WebKit-Project/output.pdf".

How to allow opening of pdf ?

有帮助吗?

解决方案

e.g create a link in your app. Set a on click event handler on this link. Set a data attribute with the URL of the pdf file. Then use gui.Shell.openExternal() method to open the pdf with the system default application.

html code:

...
<a id="pdfLink" data-href="file://file.pdf"></a>
...

javascript code:

...
$('#pdfLink').on('click', function () {
  gui.Shell.openExternal($(this).data('href'));
});
...

其他提示

A partial answer is to make sure that you have the following in your package.json file

"webkit": {
  "plugin": true
}

source: https://github.com/rogerwang/node-webkit/wiki/Third-party-browser-plugins

However, you then have to make sure that either the PDF viewer plugin is pre-installed on the system, or bundled with the app. I've not tested any of this.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top