/** * Get the annotations normal appearance. * * <p> * This will get the annotations normal appearance. If this is not existent * an empty appearance entry will be created. * * @return the appearance entry representing the normal appearance. */ private PDAppearanceEntry getNormalAppearance() { PDAppearanceDictionary appearanceDictionary = getAppearance(); PDAppearanceEntry normalAppearanceEntry = appearanceDictionary.getNormalAppearance(); if (normalAppearanceEntry.isSubDictionary()) { //TODO replace with "document.getDocument().createCOSStream()" normalAppearanceEntry = new PDAppearanceEntry(new COSStream()); appearanceDictionary.setNormalAppearance(normalAppearanceEntry); } return normalAppearanceEntry; }
/** * Returns the appearance stream for this annotation, if any. The annotation state is taken into account, if * present. */ public PDAppearanceStream getNormalAppearanceStream() { PDAppearanceDictionary appearanceDict = getAppearance(); if (appearanceDict == null) { return null; } PDAppearanceEntry normalAppearance = appearanceDict.getNormalAppearance(); if (normalAppearance == null) { return null; } if (normalAppearance.isSubDictionary()) { COSName state = getAppearanceState(); return normalAppearance.getSubDictionary().get(state); } else { return normalAppearance.getAppearanceStream(); } }
/** * Returns the entry as an appearance stream. * * @throws IllegalStateException if this entry is not an appearance stream */ public PDAppearanceStream getAppearanceStream() { if (!isStream()) { throw new IllegalStateException("This entry is not an appearance stream"); } return new PDAppearanceStream((COSStream) entry); }
private void addContentStreamsFromAppearanceEntry(COSBase appearanceEntry, List<PDContentStream> appearances) { if (appearanceEntry != null) { PDAppearanceEntry newAppearance = new PDAppearanceEntry(appearanceEntry); if (newAppearance.isStream()) { addAppearance(appearances, newAppearance.getAppearanceStream()); } else { Map<COSName, PDAppearanceStream> subDictionary = newAppearance.getSubDictionary(); for (PDAppearanceStream stream : subDictionary.values()) { addAppearance(appearances, stream); } } } }
private Set<String> getAppearanceEntryDependencies(PDAppearanceEntry entry, COSBase entryLink) { Set<String> res = new HashSet<>(); if (entry.isStream()) { res.add(getAppearanceStreamDependencies(entry.getAppearanceStream(), entryLink)); } else { for (Map.Entry<COSName, PDAppearanceStream> mapEntry : entry.getSubDictionary().entrySet()) { res.add(getAppearanceStreamDependencies(mapEntry.getValue(), ((COSDictionary) entry.getCOSObject()).getItem(mapEntry.getKey()))); } } return res; }
private static void addAllAppearances(PDAppearanceEntry appearance, List<PDAppearanceStream> list) { if (appearance == null) { return; } if (appearance.isStream()) { PDAppearanceStream appearanceStream = appearance.getAppearanceStream(); if (appearanceStream != null) { list.add(appearanceStream); } } else { for (PDAppearanceStream appearanceStream : appearance.getSubDictionary().values()) { if (appearanceStream != null) { list.add(appearanceStream); } } } }
if (appearance != null && appearance.isStream()) appearanceStream = appearance.getAppearanceStream();
/** * This will return a list of appearances. In the case where there is only one appearance the map will contain one * entry whose key is the string "default". * * @return A list of key(java.lang.String) value(PDAppearanceStream) pairs */ public PDAppearanceEntry getNormalAppearance() { COSBase entry = dictionary.getDictionaryObject(COSName.N); if (entry instanceof COSDictionary) { return new PDAppearanceEntry((COSDictionary) entry); } return null; }
private String getOnValueForWidget(PDAnnotationWidget widget) { PDAppearanceDictionary apDictionary = widget.getAppearance(); if (apDictionary != null) { PDAppearanceEntry normalAppearance = apDictionary.getNormalAppearance(); if (normalAppearance != null) { Set<COSName> entries = normalAppearance.getSubDictionary().keySet(); for (COSName entry : entries) { if (COSName.Off.compareTo(entry) != 0) { return entry.getName(); } } } } return ""; }
private void updateByValue(String value) { getCOSObject().setName(COSName.V, value); // update the appearance state (AS) for (PDAnnotationWidget widget : getWidgets()) { if (widget.getAppearance() == null) { continue; } PDAppearanceEntry appearanceEntry = widget.getAppearance().getNormalAppearance(); if (((COSDictionary) appearanceEntry.getCOSObject()).containsKey(value)) { widget.setAppearanceState(value); } else { widget.setAppearanceState(COSName.Off.getName()); } } }
private PDAppearanceContentStream getAppearanceEntryAsContentStream( PDAppearanceEntry appearanceEntry, boolean compress) throws IOException { PDAppearanceStream appearanceStream = appearanceEntry.getAppearanceStream(); setTransformationMatrix(appearanceStream); // ensure there are resources PDResources resources = appearanceStream.getResources(); if (resources == null) { resources = new PDResources(); appearanceStream.setResources(resources); } return new PDAppearanceContentStream(appearanceStream, compress); }
/** * Returns the entry as an appearance subdictionary. * * @throws IllegalStateException if this entry is not an appearance subdictionary */ public Map<COSName, PDAppearanceStream> getSubDictionary() { if (!isSubDictionary()) { throw new IllegalStateException("This entry is not an appearance subdictionary"); } COSDictionary dict = entry; Map<COSName, PDAppearanceStream> map = new HashMap<>(); for (COSName name : dict.keySet()) { COSBase value = dict.getDictionaryObject(name); // the file from PDFBOX-1599 contains /null as its entry, so we skip non-stream entries if (value instanceof COSStream) { map.put(name, new PDAppearanceStream((COSStream) value)); } } return new COSDictionaryMap<>(map, dict); } }
if (appearance != null && appearance.isStream()) appearanceStream = appearance.getAppearanceStream();
/** * This will return a list of appearances. In the case where there is only one appearance the map will contain one * entry whose key is the string "default". If there is no rollover appearance then the normal appearance will be * returned. Which means that this method will never return null. * * @return A list of key(java.lang.String) value(PDAppearanceStream) pairs */ public PDAppearanceEntry getDownAppearance() { COSBase entry = dictionary.getDictionaryObject(COSName.D); if (entry instanceof COSDictionary) { return new PDAppearanceEntry((COSDictionary) entry); } else { return getNormalAppearance(); } }
if (normalAppearance != null) Set<COSName> entries = normalAppearance.getSubDictionary().keySet(); for (COSName entry : entries)
PDAppearanceEntry normalAppearance = ap.getNormalAppearance(); COSDictionary normalAppearanceDict = (COSDictionary) normalAppearance.getCOSObject(); normalAppearanceDict.setItem(COSName.Off, createRadioButtonAppearanceStream(document, widget, false)); normalAppearanceDict.setItem(COSName.YES, createRadioButtonAppearanceStream(document, widget, true));
private PDAppearanceContentStream getAppearanceEntryAsContentStream(PDAppearanceEntry appearanceEntry) throws IOException { PDAppearanceStream appearanceStream = appearanceEntry.getAppearanceStream(); setTransformationMatrix(appearanceStream); return new PDAppearanceContentStream(appearanceStream); }
private static String getN_type(PDAnnotation annot) { PDAppearanceDictionary appearanceDictionary = annot.getAppearance(); if (appearanceDictionary != null) { PDAppearanceEntry normalAppearance = appearanceDictionary.getNormalAppearance(); if (normalAppearance == null) { return null; } else if (normalAppearance.isSubDictionary()) { return DICT; } else { return STREAM; } } return null; }
/** * Returns the appearance stream for this annotation, if any. The annotation state is taken into account, if * present. */ public PDAppearanceStream getNormalAppearanceStream() { PDAppearanceDictionary appearanceDict = getAppearance(); if (appearanceDict == null) { return null; } PDAppearanceEntry normalAppearance = appearanceDict.getNormalAppearance(); if (normalAppearance == null) { return null; } if (normalAppearance.isSubDictionary()) { COSName state = getAppearanceState(); return normalAppearance.getSubDictionary().get(state); } else { return normalAppearance.getAppearanceStream(); } }
/** * Get the annotations down appearance. * * <p> * This will get the annotations down appearance. If this is not existent an * empty appearance entry will be created. * * @return the appearance entry representing the down appearance. */ PDAppearanceEntry getDownAppearance() { PDAppearanceDictionary appearanceDictionary = getAppearance(); PDAppearanceEntry downAppearanceEntry = appearanceDictionary.getDownAppearance(); if (downAppearanceEntry.isSubDictionary()) { //TODO replace with "document.getDocument().createCOSStream()" downAppearanceEntry = new PDAppearanceEntry(new COSStream()); appearanceDictionary.setDownAppearance(downAppearanceEntry); } return downAppearanceEntry; }