Search in sources :

Example 86 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDDefaultAppearanceString method processSetFont.

/**
 * Process the set font and font size operator.
 *
 * @param operands the font name and size
 * @throws IOException in case there are missing operators or the font is not within the resources
 */
private void processSetFont(List<COSBase> operands) throws IOException {
    if (operands.size() < 2) {
        throw new IOException("Missing operands for set font operator " + Arrays.toString(operands.toArray()));
    }
    COSBase base0 = operands.get(0);
    COSBase base1 = operands.get(1);
    if (!(base0 instanceof COSName)) {
        return;
    }
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    COSName fontName = (COSName) base0;
    PDFont font = defaultResources.getFont(fontName);
    float fontSize = ((COSNumber) base1).floatValue();
    // todo: handle cases where font == null with special mapping logic (see PDFBOX-2661)
    if (font == null) {
        throw new IOException("Could not find font: /" + fontName.getName());
    }
    setFontName(fontName);
    setFont(font);
    setFontSize(fontSize);
}
Also used : PDFont(com.tom_roush.pdfbox.pdmodel.font.PDFont) COSName(com.tom_roush.pdfbox.cos.COSName) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) IOException(java.io.IOException)

Example 87 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class FieldUtils method getPairableItems.

/**
 * Return either one of a list which can have two-element arrays entries.
 * <p>
 * Some entries in a dictionary can either be an array of elements
 * or an array of two-element arrays. This method will either return
 * the elements in the array or in case of two-element arrays, the element
 * designated by the pair index
 * </p>
 * <p>
 * An {@link IllegalArgumentException} will be thrown if the items contain
 * two-element arrays and the index is not 0 or 1.
 * </p>
 *
 * @param items the array of elements or two-element arrays
 * @param pairIdx the index into the two-element array
 * @return a List of single elements
 */
static List<String> getPairableItems(COSBase items, int pairIdx) {
    if (pairIdx < 0 || pairIdx > 1) {
        throw new IllegalArgumentException("Only 0 and 1 are allowed as an index into two-element arrays");
    }
    if (items instanceof COSString) {
        List<String> array = new ArrayList<String>();
        array.add(((COSString) items).getString());
        return array;
    } else if (items instanceof COSArray) {
        List<String> entryList = new ArrayList<String>();
        for (COSBase entry : (COSArray) items) {
            if (entry instanceof COSString) {
                entryList.add(((COSString) entry).getString());
            } else if (entry instanceof COSArray) {
                COSArray cosArray = (COSArray) entry;
                if (cosArray.size() >= pairIdx + 1 && cosArray.get(pairIdx) instanceof COSString) {
                    entryList.add(((COSString) cosArray.get(pairIdx)).getString());
                }
            }
        }
        return entryList;
    }
    return Collections.emptyList();
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) ArrayList(java.util.ArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase) List(java.util.List) ArrayList(java.util.ArrayList) COSString(com.tom_roush.pdfbox.cos.COSString) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 88 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDAcroForm method getXFA.

/**
 * Get the XFA resource, the XFA resource is only used for PDF 1.5+ forms.
 *
 * @return The xfa resource or null if it does not exist.
 */
public PDXFAResource getXFA() {
    PDXFAResource xfa = null;
    COSBase base = dictionary.getDictionaryObject(COSName.XFA);
    if (base != null) {
        xfa = new PDXFAResource(base);
    }
    return xfa;
}
Also used : COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 89 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDAcroForm method getDefaultResources.

/**
 * This will get the default resources for the AcroForm.
 *
 * @return The default resources or null if there is none.
 */
public PDResources getDefaultResources() {
    PDResources retval = null;
    COSBase base = dictionary.getDictionaryObject(COSName.DR);
    if (base instanceof COSDictionary) {
        retval = new PDResources((COSDictionary) base, document.getResourceCache());
    }
    return retval;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 90 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDTerminalField method getWidgets.

/**
 * Returns the widget annotations associated with this field.
 *
 * @return The list of widget annotations. Be aware that this list is <i>not</i> backed by the
 * actual widget collection of the field, so adding or deleting has no effect on the PDF
 * document until you call {@link #setWidgets(java.util.List) setWidgets()} with the modified
 * list.
 */
@Override
public List<PDAnnotationWidget> getWidgets() {
    List<PDAnnotationWidget> widgets = new ArrayList<PDAnnotationWidget>();
    COSArray kids = (COSArray) getCOSObject().getDictionaryObject(COSName.KIDS);
    if (kids == null) {
        // the field itself is a widget
        widgets.add(new PDAnnotationWidget(getCOSObject()));
    } else if (kids.size() > 0) {
        // there are multiple widgets
        for (int i = 0; i < kids.size(); i++) {
            COSBase kid = kids.getObject(i);
            if (kid instanceof COSDictionary) {
                widgets.add(new PDAnnotationWidget((COSDictionary) kid));
            }
        }
    }
    return widgets;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) ArrayList(java.util.ArrayList) PDAnnotationWidget(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Aggregations

COSBase (com.tom_roush.pdfbox.cos.COSBase)215 COSArray (com.tom_roush.pdfbox.cos.COSArray)108 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)68 COSName (com.tom_roush.pdfbox.cos.COSName)50 COSObject (com.tom_roush.pdfbox.cos.COSObject)42 IOException (java.io.IOException)34 COSString (com.tom_roush.pdfbox.cos.COSString)33 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)29 ArrayList (java.util.ArrayList)29 COSStream (com.tom_roush.pdfbox.cos.COSStream)20 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)14 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)11 HashMap (java.util.HashMap)11 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)10 Map (java.util.Map)10 List (java.util.List)9 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)8 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)7 COSObjectKey (com.tom_roush.pdfbox.cos.COSObjectKey)7 PDFStreamParser (com.tom_roush.pdfbox.pdfparser.PDFStreamParser)6