/** * Returns a <CODE>PdfObject</CODE> as a <CODE>PdfName</CODE>, * resolving indirect references. * * The object associated with the <CODE>PdfName</CODE> given is retrieved * and resolved to a direct object. * If it is a <CODE>PdfName</CODE>, it is cast down and returned as such. * Otherwise <CODE>null</CODE> is returned. * * @param key A <CODE>PdfName</CODE> * @return the associated <CODE>PdfName</CODE> object, * or <CODE>null</CODE> */ public PdfName getAsName(final PdfName key) { PdfName name = null; PdfObject orig = getDirectObject(key); if (orig != null && orig.isName()) name = (PdfName) orig; return name; }
/** * Returns a <CODE>PdfObject</CODE> as a <CODE>PdfName</CODE>, * resolving indirect references. * * The object corresponding to the specified index is retrieved and * resolved to a direct object. * If it is a <CODE>PdfName</CODE>, it is cast down and returned as such. * Otherwise <CODE>null</CODE> is returned. * * @param idx The index of the <CODE>PdfObject</CODE> to be returned * @return the corresponding <CODE>PdfName</CODE> object, * or <CODE>null</CODE> */ public PdfName getAsName(final int idx) { PdfName name = null; PdfObject orig = getDirectObject(idx); if (orig != null && orig.isName()) name = (PdfName) orig; return name; }
/** * Returns a <CODE>PdfObject</CODE> as a <CODE>PdfName</CODE>, * resolving indirect references. * * The object corresponding to the specified index is retrieved and * resolved to a direct object. * If it is a <CODE>PdfName</CODE>, it is cast down and returned as such. * Otherwise <CODE>null</CODE> is returned. * * @param idx The index of the <CODE>PdfObject</CODE> to be returned * @return the corresponding <CODE>PdfName</CODE> object, * or <CODE>null</CODE> */ public PdfName getAsName(final int idx) { PdfName name = null; PdfObject orig = getDirectObject(idx); if (orig != null && orig.isName()) name = (PdfName) orig; return name; }
/** * Returns a <CODE>PdfObject</CODE> as a <CODE>PdfName</CODE>, * resolving indirect references. * * The object associated with the <CODE>PdfName</CODE> given is retrieved * and resolved to a direct object. * If it is a <CODE>PdfName</CODE>, it is cast down and returned as such. * Otherwise <CODE>null</CODE> is returned. * * @param key A <CODE>PdfName</CODE> * @return the associated <CODE>PdfName</CODE> object, * or <CODE>null</CODE> */ public PdfName getAsName(final PdfName key) { PdfName name = null; PdfObject orig = getDirectObject(key); if (orig != null && orig.isName()) name = (PdfName) orig; return name; }
private static void mapGotoBookmark(HashMap<String, Object> map, PdfObject dest, IntHashtable pages) { if (dest.isString()) map.put("Named", dest.toString()); else if (dest.isName()) map.put("Named", PdfName.decodeName(dest.toString())); else if (dest.isArray()) map.put("Page", makeBookmarkParam((PdfArray)dest, pages)); //changed by ujihara 2004-06-13 map.put("Action", "GoTo"); }
private static void mapGotoBookmark(HashMap<String, Object> map, PdfObject dest, IntHashtable pages) { if (dest.isString()) map.put("Named", dest.toString()); else if (dest.isName()) map.put("Named", PdfName.decodeName(dest.toString())); else if (dest.isArray()) map.put("Page", makeBookmarkParam((PdfArray)dest, pages)); //changed by ujihara 2004-06-13 map.put("Action", "GoTo"); }
static boolean existsName(final PdfDictionary dic, final PdfName key, final PdfName value) { PdfObject type = getPdfObjectRelease(dic.get(key)); if (type == null || !type.isName()) return false; PdfName name = (PdfName)type; return name.equals(value); }
static boolean existsName(final PdfDictionary dic, final PdfName key, final PdfName value) { PdfObject type = getPdfObjectRelease(dic.get(key)); if (type == null || !type.isName()) return false; PdfName name = (PdfName)type; return name.equals(value); }
static String getFontName(final PdfDictionary dic) { if (dic == null) return null; PdfObject type = getPdfObjectRelease(dic.get(PdfName.BASEFONT)); if (type == null || !type.isName()) return null; return PdfName.decodeName(type.toString()); }
static String getFontName(final PdfDictionary dic) { if (dic == null) return null; PdfObject type = getPdfObjectRelease(dic.get(PdfName.BASEFONT)); if (type == null || !type.isName()) return null; return PdfName.decodeName(type.toString()); }
private void findActivesFromDict(PdfDictionary dict, ArrayList<PdfIndirectReference> actives, HashSet<RefKey> activeKeys, HashSet<PdfName> activeClassMaps) { if (containsInactivePg(dict, activeKeys)) return; for (PdfName key: dict.getKeys()) { PdfObject obj = dict.get(key); if (key.equals(PdfName.P)) continue; else if (key.equals(PdfName.C)) { //classmap if (obj.isArray()) { for (PdfObject cm: (PdfArray)obj) { if (cm.isName()) activeClassMaps.add((PdfName)cm); } } else if (obj.isName()) activeClassMaps.add((PdfName)obj); continue; } switch (obj.type()) { case 0://PdfIndirectReference findActivesFromReference((PdfIndirectReference)obj, actives, activeKeys); break; case PdfObject.ARRAY: findActivesFromArray((PdfArray)obj, actives, activeKeys, activeClassMaps); break; case PdfObject.DICTIONARY: case PdfObject.STREAM: findActivesFromDict((PdfDictionary)obj, actives, activeKeys, activeClassMaps); break; } } }
private void findActivesFromDict(PdfDictionary dict, ArrayList<PdfIndirectReference> actives, HashSet<RefKey> activeKeys, HashSet<PdfName> activeClassMaps) { if (containsInactivePg(dict, activeKeys)) return; for (PdfName key: dict.getKeys()) { PdfObject obj = dict.get(key); if (key.equals(PdfName.P)) continue; else if (key.equals(PdfName.C)) { //classmap if (obj.isArray()) { for (PdfObject cm: (PdfArray)obj) { if (cm.isName()) activeClassMaps.add((PdfName)cm); } } else if (obj.isName()) activeClassMaps.add((PdfName)obj); continue; } switch (obj.type()) { case 0://PdfIndirectReference findActivesFromReference((PdfIndirectReference)obj, actives, activeKeys); break; case PdfObject.ARRAY: findActivesFromArray((PdfArray)obj, actives, activeKeys, activeClassMaps); break; case PdfObject.DICTIONARY: case PdfObject.STREAM: findActivesFromDict((PdfDictionary)obj, actives, activeKeys, activeClassMaps); break; } } }
if (v == null) return null; if (v.isName()) return PdfName.decodeName(((PdfName)v).toString()); else if (v.isString()) {
if (key.compareTo(PdfName.BASEFONT) == 0 || key.compareTo(PdfName.FONTNAME) == 0) { PdfObject cmpObj = cmpDict.getDirectObject(key); if (cmpObj.isName() && cmpObj.toString().indexOf('+') > 0) { PdfObject outObj = outDict.getDirectObject(key); if (!outObj.isName() || outObj.toString().indexOf('+') == -1) { if (compareResult != null && currentPath != null) compareResult.addError(currentPath, String.format("PdfDictionary %s entry: Expected: %s. Found: %s", key.toString(), cmpObj.toString(), outObj.toString()));
if (object == null || !object.isName()) { return;
/** * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray. */ public void simplifyColorspace() { if (additional == null) return; PdfArray value = additional.getAsArray(PdfName.COLORSPACE); if (value == null) return; PdfObject cs = simplifyColorspace(value); PdfObject newValue; if (cs.isName()) newValue = cs; else { newValue = value; PdfName first = value.getAsName(0); if (PdfName.INDEXED.equals(first)) { if (value.size() >= 2) { PdfArray second = value.getAsArray(1); if (second != null) { value.set(1, simplifyColorspace(second)); } } } } additional.put(PdfName.COLORSPACE, newValue); }
/** * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray. */ public void simplifyColorspace() { if (additional == null) return; PdfArray value = additional.getAsArray(PdfName.COLORSPACE); if (value == null) return; PdfObject cs = simplifyColorspace(value); PdfObject newValue; if (cs.isName()) newValue = cs; else { newValue = value; PdfName first = value.getAsName(0); if (PdfName.INDEXED.equals(first)) { if (value.size() >= 2) { PdfArray second = value.getAsArray(1); if (second != null) { value.set(1, simplifyColorspace(second)); } } } } additional.put(PdfName.COLORSPACE, newValue); }
if (object == null || !object.isName()) { return;
@Override protected void checkFileSpec(PdfWriter writer, int key, Object obj1) { if (obj1 instanceof PdfFileSpecification) { PdfDictionary fileSpec = (PdfFileSpecification)obj1; if(!fileSpec.contains(PdfName.UF) || !fileSpec.contains(PdfName.F) || !fileSpec.contains(PdfName.DESC)) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("file.specification.dictionary.shall.contain.f.uf.and.desc.entries")); } PdfObject obj = fileSpec.get(PdfName.AFRELATIONSHIP); if (obj == null || !obj.isName() || !allowedAFRelationships.contains(obj)) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("file.specification.dictionary.shall.contain.correct.afrelationship.key")); } if (fileSpec.contains(PdfName.EF)) { PdfDictionary dict = getDirectDictionary(fileSpec.get(PdfName.EF)); if (dict == null || !dict.contains(PdfName.F)) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("ef.key.of.file.specification.dictionary.shall.contain.dictionary.with.valid.f.key")); } PdfDictionary embeddedFile = getDirectDictionary(dict.get(PdfName.F)); if (embeddedFile == null) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("ef.key.of.file.specification.dictionary.shall.contain.dictionary.with.valid.f.key")); } checkEmbeddedFile(embeddedFile); } } }