Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open .pdf using node-webkit

I'd like to know how to open in my operating system a .pdf with Node-Webkit and PDFKIT.

The Node-Webkit app create the .pdf at the root of the project, I just would like to open and print it...

var pdf = require('pdfkit');
var fs = require('fs');

( function($){

    $(document).ready( function(){

        $('#form-quote').on('submit', function(e){

            e.preventDefault();

            var doc = new pdf();

            doc.pipe(fs.createWriteStream('quote.pdf'));
            doc.fontSize(20).text("test", 50, 400);

            doc.end();

            // Open the .pdf here using the operating system of the user

        });

    });

})(jQuery);
like image 809
tonymx227 Avatar asked Jul 12 '26 05:07

tonymx227


1 Answers

Use the Shell component as follows:

// Load native UI library.
var gui = require('nw.gui');

// Open URL with default browser.
gui.Shell.openExternal('https://github.com/rogerwang/node-webkit');

// Open a text file with default viewer.
gui.Shell.openItem('quote.pdf');

// Open a file in file explorer.
gui.Shell.showItemInFolder('quote.pdf');

Check the corresponding Node-Webkit reference for more information.

like image 184
fjaguero Avatar answered Jul 14 '26 00:07

fjaguero