Search in sources :

Example 61 with COSString

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

the class PDSignature method setContents.

/**
 * Sets the contents.
 *
 * @param bytes contents to be used
 */
public void setContents(byte[] bytes) {
    COSString string = new COSString(bytes);
    string.setForceHexForm(true);
    dictionary.setItem(COSName.CONTENTS, string);
}
Also used : COSString(com.tom_roush.pdfbox.cos.COSString)

Example 62 with COSString

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

the class PDFStreamEngine method showTextStrings.

/**
 * Called when a string of text with spacing adjustments is to be shown.
 *
 * @param array array of encoded text strings and adjustments
 * @throws IOException if there was an error showing the text
 */
public void showTextStrings(COSArray array) throws IOException {
    PDTextState textState = getGraphicsState().getTextState();
    float fontSize = textState.getFontSize();
    float horizontalScaling = textState.getHorizontalScaling() / 100f;
    PDFont font = textState.getFont();
    boolean isVertical = false;
    if (font != null) {
        isVertical = font.isVertical();
    }
    for (COSBase obj : array) {
        if (obj instanceof COSNumber) {
            float tj = ((COSNumber) obj).floatValue();
            // calculate the combined displacements
            float tx;
            float ty;
            if (isVertical) {
                tx = 0;
                ty = -tj / 1000 * fontSize;
            } else {
                tx = -tj / 1000 * fontSize * horizontalScaling;
                ty = 0;
            }
            applyTextAdjustment(tx, ty);
        } else if (obj instanceof COSString) {
            byte[] string = ((COSString) obj).getBytes();
            showText(string);
        } else {
            throw new IOException("Unknown type in array for TJ operation:" + obj);
        }
    }
}
Also used : PDFont(com.tom_roush.pdfbox.pdmodel.font.PDFont) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDTextState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDTextState) IOException(java.io.IOException) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 63 with COSString

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

the class FDFDictionary method writeXML.

/**
 * This will write this element as an XML document.
 *
 * @param output The stream to write the xml to.
 *
 * @throws IOException If there is an error writing the XML.
 */
public void writeXML(Writer output) throws IOException {
    PDFileSpecification fs = this.getFile();
    if (fs != null) {
        output.write("<f href=\"" + fs.getFile() + "\" />\n");
    }
    COSArray ids = this.getID();
    if (ids != null) {
        COSString original = (COSString) ids.getObject(0);
        COSString modified = (COSString) ids.getObject(1);
        output.write("<ids original=\"" + original.toHexString() + "\" ");
        output.write("modified=\"" + modified.toHexString() + "\" />\n");
    }
    List<FDFField> fields = getFields();
    if (fields != null && fields.size() > 0) {
        output.write("<fields>\n");
        for (FDFField field : fields) {
            field.writeXML(output);
        }
        output.write("</fields>\n");
    }
}
Also used : PDFileSpecification(com.tom_roush.pdfbox.pdmodel.common.filespecification.PDFileSpecification) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 64 with COSString

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

the class FDFField method getOptions.

/**
 * This will return a list of options for a choice field. The value in the list will be 1 of 2 types.
 * java.lang.String or FDFOptionElement.
 *
 * @return A list of all options.
 */
public List<Object> getOptions() {
    List<Object> retval = null;
    COSArray array = (COSArray) field.getDictionaryObject(COSName.OPT);
    if (array != null) {
        List<Object> objects = new ArrayList<Object>();
        for (int i = 0; i < array.size(); i++) {
            COSBase next = array.getObject(i);
            if (next instanceof COSString) {
                objects.add(((COSString) next).getString());
            } else {
                COSArray value = (COSArray) next;
                objects.add(new FDFOptionElement(value));
            }
        }
        retval = new COSArrayList<Object>(objects, array);
    }
    return retval;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 65 with COSString

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

the class FDFField method setValue.

/**
 * You should pass in a string, or a java.util.List of strings to set the value.
 *
 * @param value The value that should populate when imported.
 *
 * @throws IOException If there is an error setting the value.
 */
public void setValue(Object value) throws IOException {
    COSBase cos = null;
    if (value instanceof List) {
        cos = COSArrayList.convertStringListToCOSStringCOSArray((List<String>) value);
    } else if (value instanceof String) {
        cos = new COSString((String) value);
    } else if (value instanceof COSObjectable) {
        cos = ((COSObjectable) value).getCOSObject();
    } else if (value != null) {
        throw new IOException("Error:Unknown type for field import" + value);
    }
    field.setItem(COSName.V, cos);
}
Also used : COSObjectable(com.tom_roush.pdfbox.pdmodel.common.COSObjectable) COSBase(com.tom_roush.pdfbox.cos.COSBase) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSString(com.tom_roush.pdfbox.cos.COSString) IOException(java.io.IOException) COSString(com.tom_roush.pdfbox.cos.COSString)

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