Example usage for org.apache.pdfbox.pdmodel.common COSArrayList COSArrayList

List of usage examples for org.apache.pdfbox.pdmodel.common COSArrayList COSArrayList

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.common COSArrayList COSArrayList.

Prototype

public COSArrayList() 

Source Link

Document

Default constructor.

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  ww  w . j av a2  s.  co  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);
        }
    }
}