简体   繁体   中英

How to get byte-array data from servlet to pdf.js

How can I get this:

File file = new File(doneDir + "\\" + batchName + "\\" + fileName);
byte[] by = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(by);
fis.close();

response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment; filename=TheDocument." + "pdf");
response.getOutputStream().write(by);
response.getOutputStream().flush();
response.getOutputStream().close();

From my servlet either doGet or doPost to the pdf.js function:

var data = (byte array returned from servlet)
PDFJS.getDocument(data).then(function(pdf) {});

Based on the example , I would say that instead of

var data = (byte array returned from servlet)
PDFJS.getDocument(data).then(function(pdf) {});

I think you should use:

PDFJS.getDocument(servlet_url).then(function(pdf) {
   // you can now use *pdf* here
});

A servlet that returns a PDF file should be no different to the client than a PDF file on the server, and the example uses PDFJS.getDocument('helloworld.pdf').then(... so this function obviously takes a URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM