Search in sources :

Example 46 with COSString

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

the class PDChoiceTest method getOptionsFromMixed.

/*
     * Get the entries form a moxed values array. See PDFBOX-4185
     */
@Test
public void getOptionsFromMixed() {
    PDChoice choiceField = new PDComboBox(acroForm);
    COSArray choiceFieldOptions = new COSArray();
    // add string entry to options
    choiceFieldOptions.add(new COSString(" "));
    // add array entry to options
    COSArray entry = new COSArray();
    entry.add(new COSString("A"));
    choiceFieldOptions.add(entry);
    // add array entry to options
    entry = new COSArray();
    entry.add(new COSString("B"));
    choiceFieldOptions.add(entry);
    // add the options using the low level COS model as the PD model will
    // abstract the COSArray
    choiceField.getCOSObject().setItem(COSName.OPT, choiceFieldOptions);
    assertEquals(options, choiceField.getOptions());
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSString(com.tom_roush.pdfbox.cos.COSString) Test(org.junit.Test)

Example 47 with COSString

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

the class PDDefaultAppearanceStringTest method testFontResourceUnavailable.

@Test(expected = IOException.class)
public void testFontResourceUnavailable() throws IOException {
    COSString sampleString = new COSString("/Helvetica 12 Tf 0.019 0.305 0.627 rg");
    new PDDefaultAppearanceString(sampleString, resources);
}
Also used : COSString(com.tom_roush.pdfbox.cos.COSString) Test(org.junit.Test)

Example 48 with COSString

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

the class PDDefaultAppearanceStringTest method testWrongNumberOfColorArguments.

@Test(expected = IOException.class)
public void testWrongNumberOfColorArguments() throws IOException {
    COSString sampleString = new COSString("/Helvetica 12 Tf 0.305 0.627 rg");
    new PDDefaultAppearanceString(sampleString, resources);
}
Also used : COSString(com.tom_roush.pdfbox.cos.COSString) Test(org.junit.Test)

Example 49 with COSString

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

the class ControlCharacterTest method getStringsFromStream.

private List<String> getStringsFromStream(PDField field) throws IOException {
    PDAnnotationWidget widget = field.getWidgets().get(0);
    PDFStreamParser parser = new PDFStreamParser(widget.getNormalAppearanceStream());
    Object token = parser.parseNextToken();
    List<String> stringValues = new ArrayList<String>();
    while (token != null) {
        if (token instanceof COSString) {
            // TODO: improve the string output to better match
            // trimming as Acrobat adds spaces to strings
            // where we don't
            stringValues.add(((COSString) token).getString().trim());
        }
        token = parser.parseNextToken();
    }
    return stringValues;
}
Also used : PDFStreamParser(com.tom_roush.pdfbox.pdfparser.PDFStreamParser) ArrayList(java.util.ArrayList) PDAnnotationWidget(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget) COSString(com.tom_roush.pdfbox.cos.COSString) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 50 with COSString

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

the class PDChoiceTest method getOptionsFromStrings.

@Test
public void getOptionsFromStrings() {
    PDChoice choiceField = new PDComboBox(acroForm);
    COSArray choiceFieldOptions = new COSArray();
    choiceFieldOptions.add(new COSString(" "));
    choiceFieldOptions.add(new COSString("A"));
    choiceFieldOptions.add(new COSString("B"));
    // add the options using the low level COS model as the PD model will
    // abstract the COSArray
    choiceField.getCOSObject().setItem(COSName.OPT, choiceFieldOptions);
    assertEquals(options, choiceField.getOptions());
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSString(com.tom_roush.pdfbox.cos.COSString) Test(org.junit.Test)

Aggregations

COSString (com.tom_roush.pdfbox.cos.COSString)65 COSArray (com.tom_roush.pdfbox.cos.COSArray)33 COSBase (com.tom_roush.pdfbox.cos.COSBase)24 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)5 COSName (com.tom_roush.pdfbox.cos.COSName)5 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)4 Map (java.util.Map)4 COSBoolean (com.tom_roush.pdfbox.cos.COSBoolean)2 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)2 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)2 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)2 MessageDigest (java.security.MessageDigest)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)1