itext更换模板中图片的方法
生成pdf文件时,一般情况都是些表格或文字的,但也有pdf的需要包含图片的情况,
特别是固定格式的模板,其中包含图片时需要如何处理呢?
方法如下:
?
?? 首先我们模板文件中要有image域,才行,这个就不说了。
?
? 以下是代码:
???
pushbuttonField.setImage(image);//将对象放入pushbuttonField PdfFormField editFormField = pushbuttonField.getField(); //生成fromfield form.replacePushbuttonField(tmpname, editFormField);//放入pdf }
??这里只贴出了部分代码,代码中没有考虑radio,list等情况。
?
?? 这样你生成的pdf中将包含图像。
?? 代码在itext2.7中测试通过。