我有一个web服务,它在“BYTE ARRAY”中给我回复,现在我想使用该字节数组将其转换为pdf文件并下载..
目前我正在使用java代码 -
String genericResponseS="";
OrderRequest orderRequest=null;
String orderId=request.getParameter("orderId");
FileOutputStream fileOuputStream=null;
try {
//$('#productName').val()
orderRequest=new OrderRequest();
orderRequest.setOrderId(Long.valueOf(orderId));
orderRequest.setUserId(userBean.getUserID());
//priceBookRequest.setCurrencyId(Long.parseLong(currencyId));
byte[] arrayB=MobileServiceOrder.generateOrderPDF(orderRequest, request) ;
/*response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename=" + "abc.pdf");
fileOuputStream = new FileOutputStream("D:\\ORDER2.pdf");
fileOuputStream.write(arrayB);*/
response.getOutputStream().write(arrayB);
and JAVASCRIPT CODE --
function generatePDF(orderId){
debugger;
$.ajax({
url:"newOrder.do?parameter=generateOrderPDF&orderId="+orderId,
data: $('#orderParamForm').serialize(),
type: 'POST',
documenttype: "application\pdf",
async:false,
success: function (data) {
// window.open(data);
saveByteArray(data);
}
});
}
function saveByteArray(byte) {
debugger;
var blob = new Blob([byte], { type: 'application/pdf' });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
var fileName = "abc" + ".pdf";
link.download = fileName;
link.click();
};
//帮助将得到满足