List of usage examples for org.apache.pdfbox.pdmodel.interactive.form PDField getWidgets
public abstract List<PDAnnotationWidget> getWidgets();
From source file:com.formkiq.core.service.generator.pdfbox.PdfEditorServiceImpl.java
License:Apache License
/** * Add Field to Page Map./*from w w w . ja v a2 s . c o m*/ * * @param objMap {@link Map} of {@link COSDictionary} objects by * Page Number. * @param field {@link PDField} * @param map {@link Map} * @throws IOException IOException */ private void addFieldToPageMap(final Map<COSDictionary, Integer> objMap, final PDField field, final Map<Integer, List<PDField>> map) throws IOException { List<PDAnnotationWidget> widgets = field.getWidgets(); if (field instanceof PDNonTerminalField) { PDNonTerminalField tf = (PDNonTerminalField) field; for (PDField f : tf.getChildren()) { addFieldToPageMap(objMap, f, map); } } else { if (!CollectionUtils.isEmpty(widgets)) { LOG.log(Level.FINE, "addFieldToPageMap='" + field.getFullyQualifiedName() + "',class=" + field.getClass().getName()); Integer page = getPageNumber(objMap, field); if (!map.containsKey(page)) { map.put(page, new ArrayList<>()); } map.get(page).add(field); } else { LOG.log(Level.FINE, "skip addFieldToPageMap='" + field.getFullyQualifiedName() + "',class=" + field.getClass().getName()); } } }
From source file:com.formkiq.core.service.generator.pdfbox.PdfEditorServiceImpl.java
License:Apache License
/** * Generate Matches between {@link PDField} and PDF Text. * * @param page {@link PDPage}//from ww w .j a v a 2s . co m * @param pdFields {@link List} of {@link PDField} * @param textOnPage {@link List} of {@link PdfTextField} * @param lineRects {@link List} of {@link PDRectangle} * @return {@link List} */ private List<PdfFieldMatch> generateMatches(final PDPage page, final List<PDField> pdFields, final List<PdfTextField> textOnPage, final List<PDRectangle> lineRects) { List<PdfFieldMatch> list = new ArrayList<>(); for (PDField pdField : pdFields) { PdfFieldMatch match = new PdfFieldMatch(); match.setField(pdField); match.setWidgets(new ArrayList<>()); match.setMatches(new ArrayList<>()); list.add(match); for (PDAnnotationWidget w : pdField.getWidgets()) { PdAnnotationWidgetMatch m = new PdAnnotationWidgetMatch(); m.setWidget(w); match.getWidgets().add(m); List<PDFieldSearchRectangle> searchAreas = getTextSearchArea(page, pdField, w, lineRects); List<PdfTextFieldMatch> matches = findTextForWidget(w, textOnPage, searchAreas); m.setMatches(matches); } updatePDCheckBoxMatches(pdField, match); } return list; }
From source file:com.formkiq.core.service.generator.pdfbox.PdfEditorServiceImpl.java
License:Apache License
/** * Adjust Matches for {@link PDCheckBox} fields. * * @param pdField {@link PDField}//from www .j a v a 2 s . c o m * @param match {@link PdfFieldMatch} */ private void updatePDCheckBoxMatches(final PDField pdField, final PdfFieldMatch match) { if (pdField instanceof PDCheckBox) { PDCheckBox c = (PDCheckBox) pdField; List<String> onValues = c.getOnValues().stream().map(s -> s.trim().toUpperCase()) .collect(Collectors.toList()); if (pdField.getWidgets().size() == onValues.size() && onValues.size() > 1) { List<PdfTextFieldMatch> bestmatch = new ArrayList<>(); for (int i = 0; i < match.getWidgets().size(); i++) { PdAnnotationWidgetMatch w = match.getWidgets().get(i); String onvalue = onValues.get(i).trim().toUpperCase(); // check to see if 1st match matches Checkbox Value if (!w.getMatches().isEmpty() && (w.getMatches().get(0).getTextField().getText().toUpperCase().startsWith(onvalue)) || w.getMatches().get(0).getTextField().getText().toUpperCase().endsWith(onvalue)) { bestmatch.add(w.getMatches().get(0)); // check to see if 2nd match matches Checkbox Value } else if (w.getMatches().size() > 1 && (w.getMatches().get(1).getTextField().getText().toUpperCase().startsWith(onvalue)) || w.getMatches().get(1).getTextField().getText().toUpperCase().endsWith(onvalue)) { bestmatch.add(w.getMatches().get(1)); } } if (bestmatch.size() == onValues.size()) { for (PdfTextFieldMatch bm : bestmatch) { bm.setMatch(0); } for (PdAnnotationWidgetMatch m : match.getWidgets()) { Collections.sort(m.getMatches(), this.matchComparator); } } } } }
From source file:com.formkiq.core.service.generator.pdfbox.PdfEditorServiceImpl.java
License:Apache License
/** * Get Page Number for {@link PDField}./*w w w .java 2 s. c om*/ * @param objMap {@link Map} of {@link COSDictionary} and Page Number * @param field {@link PDField} * @return {@link Integer} */ private Integer getPageNumber(final Map<COSDictionary, Integer> objMap, final PDField field) { return getPageNumber(objMap, field, field.getWidgets().get(0)); }
From source file:com.formkiq.core.service.generator.pdfbox.PDFieldComparator.java
License:Apache License
/** * Get Widget.//from ww w .j av a2 s .c om * @param field {@link PDField} * @return {@link PDAnnotationWidget} */ public PDRectangle getRectangle(final PDField field) { return field.getWidgets().get(0).getRectangle(); }
From source file:org.apache.tika.parser.pdf.AbstractPDF2XHTML.java
License:Apache License
private void processAcroField(PDField field, final int currentRecursiveDepth) throws SAXException, IOException, TikaException { if (currentRecursiveDepth >= MAX_ACROFORM_RECURSIONS) { return;//from w w w.j a v a 2 s .c om } PDFormFieldAdditionalActions pdFormFieldAdditionalActions = field.getActions(); if (pdFormFieldAdditionalActions != null) { handleDestinationOrAction(pdFormFieldAdditionalActions.getC(), ActionTrigger.FORM_FIELD_RECALCULATE); handleDestinationOrAction(pdFormFieldAdditionalActions.getF(), ActionTrigger.FORM_FIELD_FORMATTED); handleDestinationOrAction(pdFormFieldAdditionalActions.getK(), ActionTrigger.FORM_FIELD_KEYSTROKE); handleDestinationOrAction(pdFormFieldAdditionalActions.getV(), ActionTrigger.FORM_FIELD_VALUE_CHANGE); } if (field.getWidgets() != null) { for (PDAnnotationWidget widget : field.getWidgets()) { handleWidget(widget); } } addFieldString(field); if (field instanceof PDNonTerminalField) { int r = currentRecursiveDepth + 1; xhtml.startElement("ol"); for (PDField child : ((PDNonTerminalField) field).getChildren()) { processAcroField(child, r); } xhtml.endElement("ol"); } }