aslushnikov / latex-online

Online latex compiler. You give it a link, it gives you PDF
http://latexonline.cc
MIT License
491 stars 89 forks source link

Blocked by CORS when trying to fetch #56

Closed NachoCasta closed 3 years ago

NachoCasta commented 5 years ago

Hi, im having a similar issue as #30

What I would like to do is to fetch the pdf via "fetch" and then download it on the users browser, instead of making them open another tab with the link to the API, so that users would be able to download it without having to leave the page.

This was my first approach of doing it

fetch("https://latexonline.cc/compile?url=https://raw.githubusercontent.com/aslushnikov/latex-online/master/sample/sample.tex")
.then(response => response.blob())
.then(blob => {
            var url = window.URL.createObjectURL(blob);
            var a = document.createElement('a');
            a.href = url;
            a.download = "filename.pdf";
            document.body.appendChild(a);
            a.click();    
            a}
);

I even tried this while on latexonlice.cc in the console, but it didnt work either. It just downloads an empty pdf file, so maybe i'm not doing it right.

Is there any way of doing this?

Thanks!

aslushnikov commented 3 years ago

It does work now if you attempt from latexonline.cc. However, I'm hesitant to enable CORS since iframe should be good-enough for all expected usecases.