gerhardberger / electron-pdf-window

view PDF files in electron browser windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't loadURL from blob

Fiorello opened this issue · comments

commented

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?

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');

});`

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>

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.

Try this:

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

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

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

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 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.