我正在将我从服务中获得的字节数组转换为pdf并将其显示在使用JS弹出的窗口中。
Map<String, Object> serviceMap = new HashMap<>();
// assigning map service value to serviceMap
// with key "bytes" that holds the byte array and key "disposition" that holds the filename
byte[] byteArray = (byte[]) serviceMap.get("bytes");
String contentDisposition = serviceMap.get("disposition").toString();
response.setContentType("application/pdf");
response.setContentLength(byteArray.length);
response.setProperty(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);
OutputStream os = null;
try {
os = response.getPortletOutputStream();
os.write(byteArray, 0, byteArray.length);
os.close();
} catch (Exception exception) {
//
}
JS:
window.open(url, "popupWindow");
如果我从服务获得的文件类型是pdf文件(从contentDisposition检查),这可以正常工作。但如果它是jpg,它将无法加载。
我的问题是,如何将任何文件类型(如jpg)转换为pdf,以便我可以在弹出窗口屏幕上正确显示?谢谢!