List of usage examples for org.apache.pdfbox.pdmodel.interactive.form PDField getPartialName
public String getPartialName()
From source file:com.mycompany.mavenproject1.ragaiproject.PDFManipulation.java
public String[] getFieldNames(PDDocument pdfDocument, JList list) { int i = 0;//www. j ava 2s.c o m String[] names = new String[10000]; PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog(); PDAcroForm acroForm = docCatalog.getAcroForm(); java.util.List<PDField> fields = acroForm.getFields(); for (PDField field : fields) { names[i] = field.getPartialName(); this.arrayOfFieldNames[i] = names[i]; list.setListData(names); this.fieldLabelPairs.add(new Pair(field.getPartialName(), field.getValueAsString())); System.out.println(this.fieldLabelPairs.size()); i++; } return names; }
From source file:com.mycompany.mavenproject1.ragaiproject.PDFManipulation.java
public void convert(List<PDDocument> pdfList, List<String> selectedFields, String fileName) { Workbook wb = new HSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); HSSFSheet s1 = (HSSFSheet) wb.createSheet("Sheet 1"); Row header = s1.createRow((short) 0); //initialize column headers for (int i = 0; i < selectedFields.size(); i++) { Cell headerCell = header.createCell(i); headerCell.setCellValue(selectedFields.get(i)); }// w w w .j a v a 2 s . c om //for(int i = 0; i < selectedFields.size();i++){ //fills out row //Cell dataCell = data.createCell(i); for (int y = 0; y < pdfList.size(); y++) { PDDocumentCatalog docCatalog = pdfList.get(y).getDocumentCatalog(); PDAcroForm acroForm = docCatalog.getAcroForm(); java.util.List<PDField> fields = acroForm.getFields(); Row data = s1.createRow((short) y + 1); for (int i = 0; i < selectedFields.size(); i++) { Cell dataCell = data.createCell(i); for (PDField field : fields) { System.out.println("Field Value: " + field.getValueAsString()); if (field.getPartialName().equals(selectedFields.get(i))) { dataCell.setCellValue(field.getValueAsString()); } } } /* for(int j = 0; j < this.fieldLabelPairs.size();j++){ if(this.fieldLabelPairs.get(j).getLabel().equals(selectedFields.get(i))){ dataCell.setCellValue(this.fieldLabelPairs.get(j).getValue()); } }*/ } //} /*for (int i = 0; i < selectedFields.size(); i++){ Row data = s1.createRow(i+1); for(int j = 0; j< this.fieldLabelPairs.length; j++){ Cell dataCell = data.createCell(i); if(this.fieldLabelPairs[j].getLabel().equals(selectedFields.get(i))){ dataCell.setCellValue(this.fieldLabelPairs[j].getValue()); } } }*/ FileOutputStream fileOut = null; try { fileOut = new FileOutputStream(fileName + ".xls"); try { wb.write(fileOut); fileOut.close(); } catch (IOException ex) { Logger.getLogger(ExcelExport.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(ExcelExport.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:mj.ocraptor.extraction.tika.parser.pdf.PDF2XHTML.java
License:Apache License
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(": "); }/* ww w. j a v a 2 s . c o m*/ 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"); } }
From source file:org.apache.tika.parser.pdf.AbstractPDF2XHTML.java
License:Apache License
private void addFieldString(PDField field) 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(": "); }/*w w w .jav a2s . c o m*/ if (altName != null) { attrs.addAttribute("", "altName", "altName", "CDATA", altName); } //return early if PDSignature field if (field instanceof PDSignatureField) { handleSignature(attrs, (PDSignatureField) field); return; } String value = field.getValueAsString(); if (value != null && !value.equals("null")) { sb.append(value); } if (attrs.getLength() > 0 || sb.length() > 0) { xhtml.startElement("li", attrs); xhtml.characters(sb.toString()); xhtml.endElement("li"); } }
From source file:org.apache.tika.parser.pdf.EnhancedPDF2XHTML.java
License:Apache License
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(": "); }/*from w w w .j a v a 2s .com*/ 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().toString(); if (value != null && !value.equals("null")) { sb.append(value); } } catch (IOException e) { //swallow } catch (NullPointerException e) { //TODO: remove once PDFBOX-2161 is fixed } if (attrs.getLength() > 0 || sb.length() > 0) { handler.startElement("li", attrs); handler.characters(sb.toString()); handler.endElement("li"); } }
From source file:org.apache.tika.parser.pdf.PDF2XHTML.java
License:Apache License
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(": "); }//from www. j a va 2 s . c om 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 (IOException e) { //swallow } if (attrs.getLength() > 0 || sb.length() > 0) { handler.startElement("li", attrs); handler.characters(sb.toString()); handler.endElement("li"); } }