use of com.tom_roush.pdfbox.cos.COSInteger in project PdfBox-Android by TomRoush.
the class BaseParser method parseCOSArray.
/**
* This will parse a PDF array object.
*
* @return The parsed PDF array.
*
* @throws IOException If there is an error parsing the stream.
*/
protected COSArray parseCOSArray() throws IOException {
long startPosition = seqSource.getPosition();
readExpectedChar('[');
COSArray po = new COSArray();
COSBase pbo;
skipSpaces();
int i;
while (((i = seqSource.peek()) > 0) && ((char) i != ']')) {
pbo = parseDirObject();
if (pbo instanceof COSObject) {
// We have to check if the expected values are there or not PDFBOX-385
if (po.size() > 0 && po.get(po.size() - 1) instanceof COSInteger) {
COSInteger genNumber = (COSInteger) po.remove(po.size() - 1);
if (po.size() > 0 && po.get(po.size() - 1) instanceof COSInteger) {
COSInteger number = (COSInteger) po.remove(po.size() - 1);
COSObjectKey key = new COSObjectKey(number.longValue(), genNumber.intValue());
pbo = getObjectFromPool(key);
} else {
// the object reference is somehow wrong
pbo = null;
}
} else {
pbo = null;
}
}
if (pbo != null) {
po.add(pbo);
} else {
// it could be a bad object in the array which is just skipped
Log.w("PdfBox-Android", "Corrupt object reference at offset " + seqSource.getPosition() + ", start offset: " + startPosition);
// This could also be an "endobj" or "endstream" which means we can assume that
// the array has ended.
String isThisTheEnd = readString();
seqSource.unread(isThisTheEnd.getBytes(ISO_8859_1));
if (ENDOBJ_STRING.equals(isThisTheEnd) || ENDSTREAM_STRING.equals(isThisTheEnd)) {
return po;
}
}
skipSpaces();
}
// read ']'
seqSource.read();
skipSpaces();
return po;
}
use of com.tom_roush.pdfbox.cos.COSInteger in project PdfBox-Android by TomRoush.
the class ContentStreamWriter method writeObject.
private void writeObject(Object o) throws IOException {
if (o instanceof COSString) {
COSWriter.writeString((COSString) o, output);
output.write(SPACE);
} else if (o instanceof COSFloat) {
((COSFloat) o).writePDF(output);
output.write(SPACE);
} else if (o instanceof COSInteger) {
((COSInteger) o).writePDF(output);
output.write(SPACE);
} else if (o instanceof COSBoolean) {
((COSBoolean) o).writePDF(output);
output.write(SPACE);
} else if (o instanceof COSName) {
((COSName) o).writePDF(output);
output.write(SPACE);
} else if (o instanceof COSArray) {
COSArray array = (COSArray) o;
output.write(COSWriter.ARRAY_OPEN);
for (int i = 0; i < array.size(); i++) {
writeObject(array.get(i));
output.write(SPACE);
}
output.write(COSWriter.ARRAY_CLOSE);
} else if (o instanceof COSDictionary) {
COSDictionary obj = (COSDictionary) o;
output.write(COSWriter.DICT_OPEN);
for (Map.Entry<COSName, COSBase> entry : obj.entrySet()) {
if (entry.getValue() != null) {
writeObject(entry.getKey());
output.write(SPACE);
writeObject(entry.getValue());
output.write(SPACE);
}
}
output.write(COSWriter.DICT_CLOSE);
output.write(SPACE);
} else if (o instanceof Operator) {
Operator op = (Operator) o;
if (op.getName().equals(OperatorName.BEGIN_INLINE_IMAGE)) {
output.write(OperatorName.BEGIN_INLINE_IMAGE.getBytes(Charsets.ISO_8859_1));
COSDictionary dic = op.getImageParameters();
for (COSName key : dic.keySet()) {
Object value = dic.getDictionaryObject(key);
key.writePDF(output);
output.write(SPACE);
writeObject(value);
output.write(EOL);
}
output.write(OperatorName.BEGIN_INLINE_IMAGE_DATA.getBytes(Charsets.ISO_8859_1));
output.write(EOL);
output.write(op.getImageData());
output.write(EOL);
output.write(OperatorName.END_INLINE_IMAGE.getBytes(Charsets.ISO_8859_1));
output.write(EOL);
} else {
output.write(op.getName().getBytes(Charsets.ISO_8859_1));
output.write(EOL);
}
} else {
throw new IOException("Error:Unknown type in content stream:" + o);
}
}
use of com.tom_roush.pdfbox.cos.COSInteger in project PdfBox-Android by TomRoush.
the class PDNumberTreeNode method getNumbers.
/**
* This will return a map of numbers. The key will be a java.lang.Integer, the value will
* depend on where this class is being used.
*
* @return A map of COS objects.
*
* @throws IOException If there is a problem creating the values.
*/
public Map<Integer, COSObjectable> getNumbers() throws IOException {
Map<Integer, COSObjectable> indices = null;
COSBase numBase = node.getDictionaryObject(COSName.NUMS);
if (numBase instanceof COSArray) {
COSArray numbersArray = (COSArray) numBase;
indices = new HashMap<Integer, COSObjectable>();
for (int i = 0; i < numbersArray.size(); i += 2) {
COSBase base = numbersArray.getObject(i);
if (!(base instanceof COSInteger)) {
Log.e("PdfBox-Android", "page labels ignored, index " + i + " should be a number, but is " + base);
return null;
}
COSInteger key = (COSInteger) base;
COSBase cosValue = numbersArray.getObject(i + 1);
indices.put(key.intValue(), cosValue == null ? null : convertCOSToPD(cosValue));
}
indices = Collections.unmodifiableMap(indices);
}
return indices;
}
use of com.tom_roush.pdfbox.cos.COSInteger in project PdfBox-Android by TomRoush.
the class FDFField method setSetWidgetFieldFlags.
/**
* This will get the widget field flags that are associated with this field. The SetF entry in the FDF field
* dictionary.
*
* @param ff The new value for the "set widget field flags".
*/
public void setSetWidgetFieldFlags(Integer ff) {
COSInteger value = null;
if (ff != null) {
value = COSInteger.get(ff);
}
field.setItem(COSName.SET_F, value);
}
use of com.tom_roush.pdfbox.cos.COSInteger in project PdfBox-Android by TomRoush.
the class FDFField method setClearWidgetFieldFlags.
/**
* This will get the field flags that are associated with this field. The ClrF entry in the FDF field dictionary.
*
* @param ff The new value for the "clear widget field flags".
*/
public void setClearWidgetFieldFlags(Integer ff) {
COSInteger value = null;
if (ff != null) {
value = COSInteger.get(ff);
}
field.setItem(COSName.CLR_F, value);
}
Aggregations