Summary
- 传递文件给 jasper 然后生成pdf文件。
- 注意接收图片的 field 类型,需要和传递过去的参数类型一致。
DemoA
URL url = new URL(microService + "/getQR?url=" + URLEncoder.encode(targetURL, 'UTF-8')+"&width=400&height=400")
InputStream inputStream = url.openStream()
param.put("QRCode", inputStream)
DemoB
URL url = new URL("https://www.duchaoqun.cn/a.jpg")
InputStream inputStream = url.openStream()
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int n = 0;
while (-1 != (n = inputStream.read(buffer))) {
baos.write(buffer, 0, n);
}
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();
InputStream in11 = new ByteArrayInputStream(imageInByte);
BufferedImage bImageFromConvert = ImageIO.read(in11);
param.put("QRCode", bImageFromConvert)