点击查看代码
// 图标
Resource resource = new ClassPathResource("file/内蒙章.png");
InputStream is = resource.getInputStream();
byte[] fileByte = toByteArray(is);
com.itextpdf.text.Image imageJldx = com.itextpdf.text.Image.getInstance(fileByte);
Image image = Image.getInstance("内蒙章.png"); // 替换为图片路径
image.setAlignment(Image.ALIGN_CENTER);
public static byte[] toByteArray(InputStream input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return output.toByteArray();
}