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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With