electron-pdf-window icon indicating copy to clipboard operation
electron-pdf-window copied to clipboard

Can't loadURL from blob

Open Fiorello opened this issue 7 years ago • 8 comments

Hi, i'm trying to load a pdf file from a blob without success. With a real url it's work, with blob url it render a blank page without error. My code: `const filePath = path.join(dirPath, files[0]);

  Utils.decryptStream(filePath, password, (error, content) => {

    const blob = new Blob([content], {type: 'application/pdf'});

    const objectURL = URL.createObjectURL(blob);

    const currentWindow = remote.getCurrentWindow();

    // console.log(objectURL);
    PDFWindow.addSupport(currentWindow);

    currentWindow.loadURL(objectURL);

  });

});`

Can anyone help me please?

Fiorello avatar Mar 30 '17 17:03 Fiorello

+1

ronsc avatar Jun 13 '17 11:06 ronsc

What i did to get it working for me was to convert the blob to a base64 dataurl and then write the dataurl to a pdf file using node filesystem api and then reading the url to the saved pdf

`fs.writeFile('the name of the pdf you want to save',new Buffer(data, "base64"), (err) => {

 if (err) throw err;
 console.log('The file has been saved!');
 win.loadURL('path to the saved file');

});`

codedeus avatar Nov 20 '17 12:11 codedeus

I'm having the same issue.

Note that the same code on the latest Chrome works fine.

Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Worker': Error: Protocol "blob:" not supported. Expected "https:" could not be cloned.
    at O.postMessage (file:///home/burton/projects/polar-bookshelf/pdfviewer/web/pdf.viewer.js:1:15528)
    at l (file:///home/burton/projects/polar-bookshelf/pdfviewer/web/pdf.viewer.js:1:12217)
    at file:///home/burton/projects/polar-bookshelf/pdfviewer/web/pdf.viewer.js:1:13060
    at <anonymous>
pdf.viewer.js:1 Uncaught (in promise) Error: An error occurred while loading the PDF.
    at pdf.viewer.js:1
    at <anonymous>

burtonator avatar Jun 08 '18 19:06 burtonator

Still an issue a year later...

Electronjs doesn't support blobs yet in their native pdf viewer either. Pretty much the main way businesses open PDFs isn't support by either of these repos.

joshuaballas avatar Jul 17 '18 13:07 joshuaballas

Try this:

https://github.com/burtonator/polar-bookshelf

Polar loads the PDF via HTTP into Electron to bypass this problem

burtonator avatar Jul 18 '18 00:07 burtonator

@burtonator I gave this a look and it looks promising, but I can't find any documentation on how to set it up.

joshuaballas avatar Jul 18 '18 13:07 joshuaballas

I'm doing another release this morning. It's basically just download and install. The README.md in the home directory explains how to install - near the bottom.

Create an issue in that repo if you are confused about anything.

burtonator avatar Jul 18 '18 13:07 burtonator

@burtonator I ended up making an Issue on there. If this is something I have to install in order to use, that is not something our company can use. This needs to be something implemented directly into my project.

EDIT: Turned out to be an app and not an API. Not an alternative in this instance.

joshuaballas avatar Jul 19 '18 12:07 joshuaballas