I'm trying to implement a PDF file download functionality with JavaScript.
As a response to a POST
request I get a PDF file, in Chrome DevTools console it looks like (the oResult
data container, fragment):
"%PDF-1.4?%?????4 0 obj?<>stream?x??
Now I'm trying to initialize the download process:
let blob = new Blob([oResult], {type: "application/pdf"});
let link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = "tstPDF";
link.click();
As a result, upon a click on a button I get tstPDF.pdf, it contains the correct number of pages, but the PDF itself is empty, no content is displayed, although it is 6 KB.
When I test the Java server-side module, which generates the PDF, everything is working fine, it sends InputStream
through ServletOutputStream
. Thus I assume that the issue is somewhere on a client side, perhaps something with MIME
, BLOB
, encoding
, or similar.
Do you have any idea why the generated PDF doesn't display any data?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…