简体   繁体   English

如何在java iText PDF中的多个页面上创建复选框?

[英]How to create checkboxes on multiple pages in java iText PDF?

I currently have a method that looks like this for making checkboxes on my pdf: 我目前有一个方法看起来像这样在我的PDF上制作复选框:

private static void createCheckbox(PdfWriter writer, float lowerLeftX, float lowerLeftY, float upperRightX, float upperRightY, String fieldName, boolean startChecked) throws IOException, DocumentException {
    RadioCheckField bt = new RadioCheckField(writer, new Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY), fieldName, "Yes");
    bt.setCheckType(RadioCheckField.TYPE_CHECK);
    bt.setBorderWidth(BaseField.BORDER_WIDTH_THIN);
    bt.setBorderColor(Color.BLACK);
    bt.setBackgroundColor(Color.WHITE);
    bt.setChecked(startChecked);
    bt.setOptions(RadioCheckField.READ_ONLY);
    PdfFormField ck = bt.getCheckField();
    writer.addAnnotation(ck);
}

This lets me send in lower left X and Y coords and upper right X and Y coords in order to make a box. 这让我可以发送左下X和Y坐标以及右上角的X和Y坐标来制作一个盒子。 This seems to work fine on the first page of a document where I create checkboxes. 这似乎在我创建复选框的文档的第一页上正常工作。 If I try making them on later pages, they just don't appear. 如果我尝试在以后的页面上制作它们,它们就不会出现。

Example: I make a PDF form some text on page one, make a new page, add more info plus checkboxes, make a new page, add more info and checkboxes. 示例:我在第一页上创建一个PDF表单,创建一个新页面,添加更多信息和复选框,创建一个新页面,添加更多信息和复选框。 That last page will not actually display checkboxes even if I use the same code for both pages with checkboxes. 即使我对带有复选框的两个页面使用相同的代码,最后一页也不会显示复选框。

Try putting a different name on each page. 尝试在每个页面上添加不同的名称。 Field names are document-wide. 字段名称是文档范围的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM