本文整理汇总了Java中org.apache.pdfbox.pdmodel.interactive.form.PDField.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java PDField.getValue方法的具体用法?Java PDField.getValue怎么用?Java PDField.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.interactive.form.PDField
的用法示例。
在下文中一共展示了PDField.getValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dumpFieldsInFile
import org.apache.pdfbox.pdmodel.interactive.form.PDField; //导入方法依赖的package包/类
private void dumpFieldsInFile(String file)
throws IOException, CryptographyException {
if (separator == null) throw new IllegalArgumentException("Separator cannot be null.");
try (PDDocument document = PDDocument.load(file)) {
if (document.isEncrypted()) {
document.decrypt("");
document.setAllSecurityToBeRemoved(true);
}
final PDDocumentCatalog documentCatalog = document.getDocumentCatalog();
final PDAcroForm acrobatForm = documentCatalog.getAcroForm();
if (acrobatForm == null) return;
List<String> values = new ArrayList<>();
for (String field : fields) {
final PDField acrobatFormField = acrobatForm.getField(field);
String value;
if (acrobatFormField == null) {
System.err.printf("Cannot find %s.%n", field);
value = null;
} else {
value = acrobatFormField.getValue();
}
values.add((value == null ? "" : StringEscapeUtils.escapeCsv(value)));
}
System.out.println(StringUtils.join(values, separator));
}
}
示例2: addFieldString
import org.apache.pdfbox.pdmodel.interactive.form.PDField; //导入方法依赖的package包/类
private void addFieldString(PDField field, XHTMLContentHandler handler)
throws SAXException {
// Pick partial name to present in content and altName for attribute
// Ignoring FullyQualifiedName for now
String partName = field.getPartialName();
String altName = field.getAlternateFieldName();
StringBuilder sb = new StringBuilder();
AttributesImpl attrs = new AttributesImpl();
if (partName != null) {
sb.append(partName).append(": ");
}
if (altName != null) {
attrs.addAttribute("", "altName", "altName", "CDATA", altName);
}
// return early if PDSignature field
if (field instanceof PDSignatureField) {
handleSignature(attrs, (PDSignatureField) field, handler);
return;
}
try {
// getValue can throw an IOException if there is no value
String value = field.getValue();
if (value != null && !value.equals("null")) {
sb.append(value);
}
} catch (Exception e) {
// swallow
}
if (attrs.getLength() > 0 || sb.length() > 0) {
handler.startElement("li", attrs);
handler.characters(sb.toString());
handler.endElement("li");
}
}