1
votes

I'm trying to add support for PDFs in my Mac node-webkit app. I tried using "PDF.js" but it requires the use of a web server so this won't help me.

I've already solved this issue for the PC version of the node-webkit app by installing "Adobe Acrobat Reader" and adding the "nppdf32.dll" file inside the plugins folder of the root directory of the PC application.

Now I'm trying to solve this issue for the Mac version. How can I open PDF files inside my Mac node-webkit application?

1
Something like this should work, no? <a id="pdfLink" href="file://file.pdf"></a> - 4m1r
I've actually gotten PDF.js to work in the past, since node-webkit has a web server built into it. That's the node part :) It is at least one viable solution. - gotohales
@4m1r - I tried that with no success, I get the error message "Could not load plugin" - Fez
@gotohales - How to you get the web-server started in node-webkit? I tried getting the server started following the steps at sysmagazine.com/posts/181670 but I'm getting the error "Cannot findmodule 'express'". Thanks. - Fez
@Leo You shouldn't need express. In fact, the node-webkit documentation explicitly mentions it isn't necessary. github.com/rogerwang/node-webkit/wiki/… I'll add an answer with more information on how I got it working. - gotohales

1 Answers

0
votes

If you still want to try PDF.js, this is how I have gotten it working.

After downloading all the files, the main ones that do all the work are viewer.html and viewer.js. You can point to viewer.html from anywhere in your node-webkit app by doing something like:

$(".some-pdf").on("click", function(){
   window.location.href = "path-to-pdfjs/viewer.html";
});

To determine which file it opens, there's a variable in view.js.

var DEFAULT_URL = 'pdfs/something.pdf';

Since you're using node-webkit, it won't have any issues accessing the file system.

I made it a little more dynamic, where the link can point to any specific pdf, by doing the following. In any file, the link adds a hash with the file name:

$(".some-pdf").on("click", function(){
   window.location.href = "path-to-pdfjs/viewer.html#specific.pdf";
});

Then in viewer.js:

var DEFAULT_URL = 'pdfs/' + window.location.hash.replace("#", "");

Then it is a bit reusable through your app, if there are multiple pdf files involved.