/** * This will get the file name. * * @return The file name. */ @Override public String getFile() { return file.getString(); }
@Override public String toString() { return "COSString{" + getString() + "}"; } }
/** * Verifies that a date item is a COSString and has the format "D:YYYYMMDDHHmmSSOHH'mm'", where * D:YYYY is mandatory and the next fields optional, but only if all of their preceding fields * are also present. This needs to be done because the other date utilities are too lenient. * * @param item the date item that is to be checked. * @return true if the date format is assumed to be valid, false if not. */ private boolean isValidPDFDateFormat(COSBase item) { if (item instanceof COSString) { String date = ((COSString) item).getString(); if (date.matches("D:\\d{4}(\\d{2}(\\d{2}(\\d{2}(\\d{2}(\\d{2}([\\+\\-Z](\\d{2}'\\d{2}')?)?)?)?)?)?)?")) { return true; } } return false; }
/** * This will get the string of one of the available options. A required element. * * @return An available option. */ public String getOption() { return ((COSString) option.getObject(0)).getString(); }
/** * This will get the string of default appearance string. A required element. * * @return A default appearance string. */ public String getDefaultAppearanceString() { return ((COSString) option.getObject(1)).getString(); }
private String getTextString(COSString cosString) { String text = cosString.getString(); for (char c : text.toCharArray()) { if (Character.isISOControl(c)) { text = "<" + cosString.toHexString() + ">"; break; } } return "" + text; }
/** * A string representing the preferred font family. * * @return The font family. */ public String getFontFamily() { String retval = null; COSString name = (COSString)dic.getDictionaryObject( COSName.FONT_FAMILY ); if( name != null ) { retval = name.getString(); } return retval; }
/** * This will get the character set for the font. * * @return The character set value. */ public String getCharSet() { String retval = null; COSString name = (COSString)dic.getDictionaryObject( COSName.CHAR_SET ); if( name != null ) { retval = name.getString(); } return retval; }
/** * Get the default appearance. * * This is an inheritable attribute. * * The default appearance contains a set of default graphics and text operators * to define the field’s text size and color. * * @return the DA element of the dictionary object */ public String getDefaultAppearance() { COSString defaultAppearance = (COSString) getInheritableAttribute(COSName.DA); return defaultAppearance.getString(); }
/** * * @return parsed string or null if something went wrong. */ String myParseCOSString() { try { COSString cosString = parseCOSString(); if (cosString != null) { return cosString.getString(); } } catch (IOException e) { } return null; } }
/** * This is a convenience method that will get the dictionary object that is expected to be a * string. Null is returned if the entry does not exist in the dictionary. * * @param key The key to the item in the dictionary. * @return The name converted to a string. */ public String getString(COSName key) { String retval = null; COSBase value = getDictionaryObject(key); if (value instanceof COSString) { retval = ((COSString) value).getString(); } return retval; }
/** * Returns the Calendar for a given COS string containing a date, * or {@code null} if it cannot be parsed. * * The returned value will have 0 for DST_OFFSET. * * @param text A COS string containing a date. * @return The Calendar that the text string represents, or {@code null} if it cannot be parsed. */ public static Calendar toCalendar(COSString text) { if (text == null) { return null; } return toCalendar(text.getString()); }
/** * If the value in the /A entry is a string, this will get the value of the /NM entry in the * annotation dictionary. * * @return the /NM value of an annotation dictionary or null if the /A entry value is missing or * not a string. */ public String getAnnotationName() { COSBase base = dict.getDictionaryObject(COSName.A); if (base instanceof COSString) { return ((COSString) base).getString(); } return null; }
/** * This will get the name of the destination. * * @return The name of the destination. */ public String getNamedDestination() { String retval = null; if( namedDestination instanceof COSString ) { retval = ((COSString)namedDestination).getString(); } else if( namedDestination instanceof COSName ) { retval = ((COSName)namedDestination).getName(); } return retval; }
/** * Get the default style string. * * The default style string defines the default style for * rich text fields. * * @return the DS element of the dictionary object */ public String getDefaultStyleString() { COSString defaultStyleString = (COSString) getCOSObject().getDictionaryObject(COSName.DS); return defaultStyleString.getString(); }
/** * Returns the selected values, or an empty List, for the given key. */ private List<String> getValueFor(COSName name) { COSBase value = getCOSObject().getDictionaryObject(name); if (value instanceof COSString) { List<String> array = new ArrayList<>(); array.add(((COSString) value).getString()); return array; } else if (value instanceof COSArray) { return COSArrayList.convertCOSStringCOSArrayToList((COSArray)value); } return Collections.emptyList(); }
/** * @return The Javascript Code. */ public String getAction() { COSBase base = action.getDictionaryObject( COSName.JS ); if (base instanceof COSString) { return ((COSString)base).getString(); } else if (base instanceof COSStream) { return ((COSStream)base).toTextString(); } else { return null; } } }
/** * This will get the javascript that is executed after the import. * * @return Some javascript code. */ public String getAfter() { COSBase base = dictionary.getDictionaryObject(COSName.AFTER); if (base instanceof COSString) { return ((COSString) base).getString(); } else if (base instanceof COSStream) { return ((COSStream) base).toTextString(); } else { return null; } }
/** * Used when processing custom metadata entries, as PDFBox won't do * the conversion for us in the way it does for the standard ones */ private void addMetadata(Metadata metadata, String name, COSBase value) { if (value instanceof COSArray) { for (Object v : ((COSArray) value).toList()) { addMetadata(metadata, name, ((COSBase) v)); } } else if (value instanceof COSString) { addMetadata(metadata, name, ((COSString) value).getString()); } // Avoid calling COSDictionary#toString, since it can lead to infinite // recursion. See TIKA-1038 and PDFBOX-1835. else if (value != null && !(value instanceof COSDictionary)) { addMetadata(metadata, name, value.toString()); } }