如何从servlet到pdf.js获取字节数组数据 [英] How to get byte-array data from servlet to pdf.js

查看:61
本文介绍了如何从servlet到pdf.js获取字节数组数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么得到这个:

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

从我的servlet doGet或doPost到pdf.js函数:

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) {});

推荐答案

基于 example ,我会说而不是

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

我认为您应该使用:

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

返回PDF文件的servlet与客户端应该与服务器上的PDF文件没有什么不同,并且该示例使用PDFJS.getDocument('helloworld.pdf').then(...,因此此函数显然采用URL.

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.

这篇关于如何从servlet到pdf.js获取字节数组数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆