landings
landings

Reputation: 770

NW.js + PDF.js: How to provide an URL to pdf.js?

I'm quite new to Javascript.

I want to make a very simple native PDF viewer using nw.js and pdf.js. It reads a package file and extract a buffer that contains a valid PDF file. Then I convert the buffer into a stream like this:

var stream = require('stream');
var bufferStream = new stream.PassThrough();
bufferStream.end(pdfbuffer); // pdfbuffer is the PDF file's buffer

But I don't know how to make a valid URL for this PDF file so that I can fill it in pdf.js' default viewer code here:

// viewer.js from PDF.JS
var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf';

Or am I thinking of the wrong direction?

Upvotes: 1

Views: 377

Answers (1)

Edrian
Edrian

Reputation: 608

I think you should create a Writable stream first. Then write that stream to a PDF file which you will create too. I'm not sure if you can use a PDF file as a writable stream directly. Sorry if this doesn't really answer the question but take this as a nudge in the right direction.

Upvotes: 1

Related Questions