Example usage for org.apache.pdfbox.pdmodel.interactive.form PDField getValueAsString

List of usage examples for org.apache.pdfbox.pdmodel.interactive.form PDField getValueAsString

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.interactive.form PDField getValueAsString.

Prototype

public abstract String getValueAsString();

Source Link

Document

Returns a string representation of the "V" entry, or an empty string.

Usage

From source file:com.mycompany.mavenproject1.ragaiproject.PDFManipulation.java

public String[] getFieldNames(PDDocument pdfDocument, JList list) {
    int i = 0;/*  w  w w.j a va 2 s .  com*/

    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));
    }//from  w w  w .  ja va  2 s  . c o  m

    //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: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(": ");
    }/*from w ww  . j a  v a 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);
        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");
    }
}