use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDFRenderer method hasBlendMode.
private boolean hasBlendMode(PDPage page) {
// check the current resources for blend modes
PDResources resources = page.getResources();
if (resources == null) {
return false;
}
for (COSName name : resources.getExtGStateNames()) {
PDExtendedGraphicsState extGState = resources.getExtGState(name);
if (extGState == null) {
// see PDFBOX-3950-23EGDHXSBBYQLKYOKGZUOVYVNE675PRD.pdf
continue;
}
BlendMode blendMode = extGState.getBlendMode();
if (blendMode != BlendMode.NORMAL) {
return true;
}
}
return false;
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDField method importFDF.
/**
* This will import a fdf field from a fdf document.
*
* @param fdfField The fdf field to import.
* @throws IOException If there is an error importing the data for this field.
*/
void importFDF(FDFField fdfField) throws IOException {
COSBase fieldValue = fdfField.getCOSValue();
if (fieldValue != null && this instanceof PDTerminalField) {
PDTerminalField currentField = (PDTerminalField) this;
if (fieldValue instanceof COSName) {
currentField.setValue(((COSName) fieldValue).getName());
} else if (fieldValue instanceof COSString) {
currentField.setValue(((COSString) fieldValue).getString());
} else if (fieldValue instanceof COSStream) {
currentField.setValue(((COSStream) fieldValue).toTextString());
} else if (fieldValue instanceof COSArray && this instanceof PDChoice) {
((PDChoice) this).setValue(COSArrayList.convertCOSStringCOSArrayToList((COSArray) fieldValue));
} else {
throw new IOException("Error:Unknown type for field import" + fieldValue);
}
} else if (fieldValue != null) {
dictionary.setItem(COSName.V, fieldValue);
}
Integer ff = fdfField.getFieldFlags();
if (ff != null) {
setFieldFlags(ff);
} else {
// these are suppose to be ignored if the Ff is set.
Integer setFf = fdfField.getSetFieldFlags();
int fieldFlags = getFieldFlags();
if (setFf != null) {
int setFfInt = setFf;
fieldFlags = fieldFlags | setFfInt;
setFieldFlags(fieldFlags);
}
Integer clrFf = fdfField.getClearFieldFlags();
if (clrFf != null) {
// we have to clear the bits of the document fields for every bit that is
// set in this field.
//
// Example:
// docFf = 1011
// clrFf = 1101
// clrFfValue = 0010;
// newValue = 1011 & 0010 which is 0010
int clrFfValue = clrFf;
clrFfValue ^= 0xFFFFFFFF;
fieldFlags = fieldFlags & clrFfValue;
setFieldFlags(fieldFlags);
}
}
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDVisibleSigBuilder method createImageForm.
@Override
public void createImageForm(PDResources imageFormResources, PDResources innerFormResource, PDStream imageFormStream, PDRectangle bbox, AffineTransform at, PDImageXObject img) throws IOException {
PDFormXObject imageForm = new PDFormXObject(imageFormStream);
imageForm.setBBox(bbox);
imageForm.setMatrix(at);
imageForm.setResources(imageFormResources);
imageForm.setFormType(1);
imageFormResources.getCOSObject().setDirect(true);
COSName imageFormName = COSName.getPDFName("n2");
innerFormResource.put(imageFormName, imageForm);
COSName imageName = imageFormResources.add(img, "img");
pdfStructure.setImageForm(imageForm);
pdfStructure.setImageFormName(imageFormName);
pdfStructure.setImageName(imageName);
Log.i("PdfBox-Android", "Created image form");
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDPageContentStream method drawXObject.
/**
* Draw an xobject(form or image) using the given {@link AffineTransform} to position
* the xobject.
*
* @param xobject The xobject to draw.
* @param transform the transformation matrix
* @throws IOException If there is an error writing to the stream.
* @throws IllegalStateException If the method was called within a text block.
* @deprecated Use {@link #drawImage(PDImageXObject, Matrix) drawImage(PDImageXObject, Matrix)}
* or {@link #drawForm(PDFormXObject) drawForm(PDFormXObject)} with
* {@link #transform(Matrix) transform(Matrix)} instead.
*/
@Deprecated
public void drawXObject(PDXObject xobject, AffineTransform transform) throws IOException {
if (inTextMode) {
throw new IllegalStateException("Error: drawXObject is not allowed within a text block.");
}
String xObjectPrefix;
if (xobject instanceof PDImageXObject) {
xObjectPrefix = "Im";
} else {
xObjectPrefix = "Form";
}
COSName objMapping = resources.add(xobject, xObjectPrefix);
saveGraphicsState();
transform(new Matrix(transform));
writeOperand(objMapping);
writeOperator(OperatorName.DRAW_OBJECT);
restoreGraphicsState();
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class COSDictionaryMap method convertBasicTypesToMap.
/**
* This will take a COS dictionary and convert it into COSDictionaryMap. All cos
* objects will be converted to their primitive form.
*
* @param map The COS mappings.
* @return A standard java map.
* @throws IOException If there is an error during the conversion.
*/
public static COSDictionaryMap<String, Object> convertBasicTypesToMap(COSDictionary map) throws IOException {
COSDictionaryMap<String, Object> retval = null;
if (map != null) {
Map<String, Object> actualMap = new HashMap<String, Object>();
for (COSName key : map.keySet()) {
COSBase cosObj = map.getDictionaryObject(key);
Object actualObject = null;
if (cosObj instanceof COSString) {
actualObject = ((COSString) cosObj).getString();
} else if (cosObj instanceof COSInteger) {
actualObject = ((COSInteger) cosObj).intValue();
} else if (cosObj instanceof COSName) {
actualObject = ((COSName) cosObj).getName();
} else if (cosObj instanceof COSFloat) {
actualObject = ((COSFloat) cosObj).floatValue();
} else if (cosObj instanceof COSBoolean) {
actualObject = ((COSBoolean) cosObj).getValue() ? Boolean.TRUE : Boolean.FALSE;
} else {
throw new IOException("Error:unknown type of object to convert:" + cosObj);
}
actualMap.put(key.getName(), actualObject);
}
retval = new COSDictionaryMap<String, Object>(actualMap, map);
}
return retval;
}
Aggregations