本文整理汇总了Java中org.apache.pdfbox.pdmodel.interactive.form.PDField.getWidgets方法的典型用法代码示例。如果您正苦于以下问题:Java PDField.getWidgets方法的具体用法?Java PDField.getWidgets怎么用?Java PDField.getWidgets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.interactive.form.PDField
的用法示例。
在下文中一共展示了PDField.getWidgets方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAFieldTwice
import org.apache.pdfbox.pdmodel.interactive.form.PDField; //导入方法依赖的package包/类
/**
* <a href="https://stackoverflow.com/questions/22074449/how-to-know-if-a-field-is-on-a-particular-page">
* how to know if a field is on a particular page?
* </a>
* <p>
* This sample document does not contain the optional page entry in its annotations.
* Thus, the fast method fails in contrast to the safe one.
* </p>
*/
@Test
public void testAFieldTwice() throws IOException
{
System.out.println("aFieldTwice.pdf\n=================");
try ( InputStream resource = getClass().getResourceAsStream("aFieldTwice.pdf") )
{
PDDocument document = PDDocument.load(resource);
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
if (acroForm != null)
{
for (PDField field : acroForm.getFieldTree())
{
System.out.println(field.getFullyQualifiedName());
for (PDAnnotationWidget widget : field.getWidgets())
{
System.out.print(widget.getAnnotationName() != null ? widget.getAnnotationName() : "(NN)");
System.out.printf(" - fast: %s", determineFast(document, widget));
System.out.printf(" - safe: %s\n", determineSafe(document, widget));
}
}
}
}
System.out.println();
}
示例2: testTestDuplicateField2
import org.apache.pdfbox.pdmodel.interactive.form.PDField; //导入方法依赖的package包/类
/**
* <a href="https://stackoverflow.com/questions/22074449/how-to-know-if-a-field-is-on-a-particular-page">
* how to know if a field is on a particular page?
* </a>
* <p>
* This sample document contains the optional page entry in its annotations.
* Thus, the fast method returns the same result as the safe one.
* </p>
*/
@Test
public void testTestDuplicateField2() throws IOException
{
System.out.println("test_duplicate_field2.pdf\n=================");
try ( InputStream resource = getClass().getResourceAsStream("test_duplicate_field2.pdf") )
{
PDDocument document = PDDocument.load(resource);
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
if (acroForm != null)
{
for (PDField field : acroForm.getFieldTree())
{
System.out.println(field.getFullyQualifiedName());
for (PDAnnotationWidget widget : field.getWidgets())
{
System.out.print(widget.getAnnotationName() != null ? widget.getAnnotationName() : "(NN)");
System.out.printf(" - fast: %s", determineFast(document, widget));
System.out.printf(" - safe: %s\n", determineSafe(document, widget));
}
}
}
}
System.out.println();
}
示例3: testReadFormOptions
import org.apache.pdfbox.pdmodel.interactive.form.PDField; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/36964496/pdfbox-2-0-overcoming-dictionary-key-encoding">
* PDFBox 2.0: Overcoming dictionary key encoding
* </a>
* <br/>
* <a href="http://www.stockholm.se/PageFiles/85478/KYF%20211%20Best%C3%A4llning%202014.pdf">
* KYF 211 Beställning 2014.pdf
* </a>
*
* <p>
* Indeed, the special characters in the names are replaced by the Unicode replacement
* character. PDFBox, when parsing a PDF name, immediately interprets its bytes as UTF-8
* encoded which fails in the document at hand.
* </p>
*/
@Test
public void testReadFormOptions() throws IOException
{
try ( InputStream originalStream = getClass().getResourceAsStream("KYF 211 Best\u00e4llning 2014.pdf") )
{
PDDocument pdfDocument = PDDocument.load(originalStream);
PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
PDField field = acroForm.getField("Krematorier");
List<PDAnnotationWidget> widgets = field.getWidgets();
System.out.println("Field Name: " + field.getPartialName() + " (" + widgets.size() + ")");
for (PDAnnotationWidget annot : widgets) {
PDAppearanceDictionary ap = annot.getAppearance();
Set<COSName> keys = ((COSDictionary)(ap.getCOSObject().getDictionaryObject("N"))).keySet();
ArrayList<String> keyList = new ArrayList<>(keys.size());
for (COSName cosKey : keys) {keyList.add(cosKey.getName());}
System.out.println(String.join("|", keyList));
}
}
}
示例4: testListFieldsInFieldNameTest
import org.apache.pdfbox.pdmodel.interactive.form.PDField; //导入方法依赖的package包/类
/**
* <a href="https://stackoverflow.com/questions/44817793/the-method-getkids-is-undefined-for-the-type-pdfield">
* The method getKids() is undefined for the type PDField
* </a>
* <br/>
* <a href="https://issues.apache.org/jira/secure/attachment/12651245/field%20name%20test.pdf">
* field name test.pdf
* </a>
* <p>
* The problems referred to don't exist anymore.
* </p>
*/
@Test
public void testListFieldsInFieldNameTest() throws InvalidPasswordException, IOException
{
PDDocument doc = PDDocument.load(getClass().getResourceAsStream("field name test.pdf"));
PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
List<PDField> fields = form.getFields();
for (int i=0; i<fields.size(); i++) {
PDField f = fields.get(i);
if (f instanceof PDTerminalField)
{
System.out.printf("%s, %s widgets\n", f.getFullyQualifiedName(), f.getWidgets().size());
for (PDAnnotationWidget widget : f.getWidgets())
System.out.printf(" %s\n", widget.getAnnotationName());
}
else if (f instanceof PDNonTerminalField)
{
List<PDField> kids = ((PDNonTerminalField)f).getChildren();
for (int j=0; j<kids.size(); j++) {
if (kids.get(j) instanceof PDField) {
PDField kidField = (PDField) kids.get(j);
System.out.println(kidField.getFullyQualifiedName());
}
}
}
}
}