itextpdf 生成PDF ,鼠标悬浮图片显示信息,点击事件
作者:互联网
应用场景
java使用itext生成PDF,需要在PDF图片或者签章添加点击事件或者鼠标悬浮显示指定信息
try {
Image img = Image.getInstance("C:\\Users\\Administrator\\Desktop\\muxuzi.jpg");
PushbuttonField btn = new PushbuttonField(writer, new Rectangle(100, 100, 200, 200), "Button1");
String showText = "姓 名: 勇气heart \n"
+"身份证号: 666666666666666666\n"
+"签署日期: 2018年05月25日\n"
+"签署密文 : adsf;lksdjfcljcvlakdsjf;lkasdsadjfosdjfasddofjdsfkj";
String tip = "6666";
btn.setText(showText);
btn.setBackgroundColor(BaseColor.GRAY);
btn.setImage(img);
btn.setFontSize(0);
btn.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);//只要图片
// btn.setLayout(PushbuttonField.LAYOUT_ICON_LEFT_LABEL_RIGHT);//图片在左,注释在右
btn.setLayout(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT);//可视但不打印
btn.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
btn.setBorderWidth(3);
btn.setBorderColor(BaseColor.GRAY);
PdfFormField ff = btn.getField();
String code ="app.alert('"+tip+"')";
PdfAction ac = PdfAction.javaScript(code, writer);
ff.setAction(ac);
writer.addAnnotation(ff);
} catch (Exception e) {
e.printStackTrace();
}
结果显示
标签:PushbuttonField,String,显示信息,setLayout,itextpdf,writer,PDF,btn 来源: https://blog.csdn.net/jianjun2114/article/details/80452486