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);
}
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);
}
}
}
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");
}
}
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;
}
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);
}
Aggregations