I am working on a Windows 8 Javascript application that generates a PDF using PDFKit.
Normally you'd make a blobstream using pipe and then make an URL of it that you send to the browser. This only works if the website is run from a server, which is not the case since it's a local app. However I do have access to the file system and I'd like to save the generated PDF to a file.
To do this I was inspired by this question: How to pipe a stream using pdfkit with node js
I tried both above's solutions using Browserify, replacing the printer code with code that saves to a file:
Windows.Storage.ApplicationData.current.localFolder.createFileAsync("test.pdf",
Windows.Storage.CreationCollisionOption.replaceExisting).then(function (file) {
//write as text
Windows.Storage.FileIO.writeTextAsync(file, data).then(function () {});
//or write as buffer
var buffUTF8 = Windows.Security.Cryptography.CryptographicBuffer.convertStringToBinary(data, 0);
Windows.Storage.FileIO.writeBufferAsync(file, buffUTF8).then(function () {});
});
As you can see I both tried using writing as text or writing as a buffer, both gave me exactly the same files.
The PDF file is created but when I open it it shows a blank page. If I open the pdf in a text editor and compare it to a valid PDF I can tell that the stream part of the file has different kind of characters.
Also the Visual Studio output window is spamming me with Javascript run-time error messages about the URI having invalid encoding.
So it's obviously an encoding issue and I'm not sure what to do next. Any tips on how to save a PDFkit document to a file?
This is working for me in firefox