List of usage examples for org.apache.pdfbox.cos COSDocument getObjectFromPool
public COSObject getObjectFromPool(COSObjectKey key)
From source file:com.aaasec.sigserv.csspsupport.pdfbox.modifications.CsCOSWriter.java
License:Apache License
private void prepareIncrement(PDDocument doc) { try {/* w ww . j a v a 2s . c om*/ if (doc != null) { COSDocument cosDoc = doc.getDocument(); Map<COSObjectKey, Long> xrefTable = cosDoc.getXrefTable(); Set<COSObjectKey> keySet = xrefTable.keySet(); long highestNumber = 0; for (COSObjectKey cosObjectKey : keySet) { COSBase object = cosDoc.getObjectFromPool(cosObjectKey).getObject(); if (object != null && cosObjectKey != null && !(object instanceof COSNumber)) { objectKeys.put(object, cosObjectKey); keyObject.put(cosObjectKey, object); } long num = cosObjectKey.getNumber(); if (num > highestNumber) { highestNumber = num; } } setNumber(highestNumber); // xrefTable.clear(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:net.padaf.preflight.utils.COSUtils.java
License:Apache License
/** * return true if the elt is a COSDictionary or a reference to a COSDictionary * /*from ww w . j a v a2 s . c om*/ * @param elt * @param doc * @return */ public static boolean isDictionary(COSBase elt, COSDocument doc) { if (elt instanceof COSObject) { try { COSObjectKey key = new COSObjectKey((COSObject) elt); COSObject obj = doc.getObjectFromPool(key); return (obj != null && obj.getObject() instanceof COSDictionary); } catch (IOException e) { return false; } } return (elt instanceof COSDictionary); }
From source file:net.padaf.preflight.utils.COSUtils.java
License:Apache License
/** * return true if the elt is a COSString or a reference to a COSString * // ww w . jav a 2s . c o m * @param elt * @param doc * @return */ public static boolean isString(COSBase elt, COSDocument doc) { if (elt instanceof COSObject) { try { COSObjectKey key = new COSObjectKey((COSObject) elt); COSObject obj = doc.getObjectFromPool(key); return (obj != null && (obj.getObject() instanceof COSString || obj.getObject() instanceof COSName)); } catch (IOException e) { return false; } } return (elt instanceof COSString || elt instanceof COSName); }
From source file:net.padaf.preflight.utils.COSUtils.java
License:Apache License
/** * return true if the elt is a COSStream or a reference to a COSStream * // www . j a v a2s.c o m * @param elt * @param doc * @return */ public static boolean isStream(COSBase elt, COSDocument doc) { if (elt instanceof COSObject) { try { COSObjectKey key = new COSObjectKey((COSObject) elt); COSObject obj = doc.getObjectFromPool(key); return (obj != null && obj.getObject() instanceof COSStream); } catch (IOException e) { return false; } } return (elt instanceof COSStream); }
From source file:net.padaf.preflight.utils.COSUtils.java
License:Apache License
/** * return true if the elt is a COSInteger or a reference to a COSInteger * /*ww w. ja v a2s .c o m*/ * @param elt * @param doc * @return */ public static boolean isInteger(COSBase elt, COSDocument doc) { if (elt instanceof COSObject) { try { COSObjectKey key = new COSObjectKey((COSObject) elt); COSObject obj = doc.getObjectFromPool(key); return (obj != null && obj.getObject() instanceof COSInteger); } catch (IOException e) { return false; } } return (elt instanceof COSInteger); }
From source file:net.padaf.preflight.utils.COSUtils.java
License:Apache License
/** * return true if the elt is a COSInteger or a reference to a COSInteger * /* w w w . j a va2 s .com*/ * @param elt * @param doc * @return */ public static boolean isFloat(COSBase elt, COSDocument doc) { if (elt instanceof COSObject) { try { COSObjectKey key = new COSObjectKey((COSObject) elt); COSObject obj = doc.getObjectFromPool(key); return (obj != null && obj.getObject() instanceof COSFloat); } catch (IOException e) { return false; } } return (elt instanceof COSFloat); }
From source file:net.padaf.preflight.utils.COSUtils.java
License:Apache License
/** * return true if the elt is a COSArray or a reference to a COSArray * //from ww w. j a va 2 s . c om * @param elt * @param doc * @return */ public static boolean isArray(COSBase elt, COSDocument doc) { if (elt instanceof COSObject) { try { COSObjectKey key = new COSObjectKey((COSObject) elt); COSObject obj = doc.getObjectFromPool(key); return (obj != null && obj.getObject() instanceof COSArray); } catch (IOException e) { return false; } } return (elt instanceof COSArray); }
From source file:net.padaf.preflight.utils.COSUtils.java
License:Apache License
/** * Return the COSBase object as COSArray if the COSBase object is an instance * of COSArray or a reference to a COSArray object. In other cases, this * method returns null;/*from w w w. j a va2 s .c om*/ * * @param cbase * @param cDoc * @return */ public static COSArray getAsArray(COSBase cbase, COSDocument cDoc) { if (cbase instanceof COSObject) { try { COSObjectKey key = new COSObjectKey((COSObject) cbase); COSObject obj = cDoc.getObjectFromPool(key); if (obj != null && obj.getObject() instanceof COSArray) { return (COSArray) obj.getObject(); } else { return null; } } catch (IOException e) { return null; } } else if (cbase instanceof COSArray) { return (COSArray) cbase; } else { return null; } }
From source file:net.padaf.preflight.utils.COSUtils.java
License:Apache License
/** * Return the COSBase object as COSString if the COSBase object is an instance * of COSString or a reference to a COSString object. In other cases, this * method returns null;/*from www . j av a 2 s . co m*/ * * @param cbase * @param cDoc * @return */ public static String getAsString(COSBase cbase, COSDocument cDoc) { if (cbase instanceof COSObject) { try { COSObjectKey key = new COSObjectKey((COSObject) cbase); COSObject obj = cDoc.getObjectFromPool(key); if (obj != null && obj.getObject() instanceof COSString) { return ((COSString) obj.getObject()).getString(); } else if (obj != null && obj.getObject() instanceof COSName) { return ((COSName) obj.getObject()).getName(); } else { return null; } } catch (IOException e) { return null; } } else if (cbase instanceof COSString) { return ((COSString) cbase).getString(); } else if (cbase instanceof COSName) { return ((COSName) cbase).getName(); } else { return null; } }
From source file:net.padaf.preflight.utils.COSUtils.java
License:Apache License
/** * Return the COSBase object as COSDictionary if the COSBase object is an * instance of COSDictionary or a reference to a COSDictionary object. In * other cases, this method returns null; * /*from ww w .j ava 2s . com*/ * @param cbase * @param cDoc * @return */ public static COSDictionary getAsDictionary(COSBase cbase, COSDocument cDoc) { if (cbase instanceof COSObject) { try { COSObjectKey key = new COSObjectKey((COSObject) cbase); COSObject obj = cDoc.getObjectFromPool(key); if (obj != null && obj.getObject() instanceof COSDictionary) { return (COSDictionary) obj.getObject(); } else { return null; } } catch (IOException e) { return null; } } else if (cbase instanceof COSDictionary) { return (COSDictionary) cbase; } else { return null; } }