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

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

Introduction

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

Prototype

public void setPartialName(String name) 

Source Link

Document

This will set the partial name of the field.

Usage

From source file:com.fangxin365.core.utils.PDFMerger.java

License:Apache License

/**
 * Merge the contents of the source form into the destination form for the
 * destination file.//from  w  ww.  j av a2 s .  c  o  m
 * 
 * @param cloner
 *            the object cloner for the destination document
 * @param destAcroForm
 *            the destination form
 * @param srcAcroForm
 *            the source form
 * @throws IOException
 *             If an error occurs while adding the field.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private void mergeAcroForm(PDFCloneUtility cloner, PDAcroForm destAcroForm, PDAcroForm srcAcroForm)
        throws IOException {
    List destFields = destAcroForm.getFields();
    List srcFields = srcAcroForm.getFields();
    if (srcFields != null) {
        if (destFields == null) {
            destFields = new COSArrayList();
            destAcroForm.setFields(destFields);
        }
        Iterator srcFieldsIterator = srcFields.iterator();
        while (srcFieldsIterator.hasNext()) {
            PDField srcField = (PDField) srcFieldsIterator.next();
            PDField destField = PDFieldFactory.createField(destAcroForm,
                    (COSDictionary) cloner.cloneForNewDocument(srcField.getDictionary()));
            // if the form already has a field with this name then we need
            // to rename this field
            // to prevent merge conflicts.
            if (destAcroForm.getField(destField.getFullyQualifiedName()) != null) {
                destField.setPartialName("dummyFieldName" + (nextFieldNum++));
            }
            destFields.add(destField);
        }
    }
}