PdfDictionary pageDict = myReader.getPageN(1); PdfArray annots = pageDict.getAsArray(PdfName.ANNOTS); ArrayList<String> dests = new ArrayList<String>(); if (annots != null) { for (int i = 0; i < annots.size(); ++i) { PdfDictionary annotDict = annots.getAsDict(i); PdfName subType = annotDict.getAsName(PdfName.SUBTYPE); if (subType != null && PdfName.LINK.equals(subType)) { PdfDictionary action = annotDict.getAsDict(PdfName.A); if (action != null && PdfName.URI.equals(action.getAsName(PdfName.S)) { dests.add(action.getAsString(PdfName.URI).toString()); } // else { its an internal link, meh } } } }
/** * Checks the type of the dictionary. * @param type the type you're looking for * @return true if the type of the dictionary corresponds with the type you're looking for */ public boolean checkType(PdfName type) { if (type == null) return false; if (dictionaryType == null) dictionaryType = getAsName(PdfName.TYPE); return type.equals(dictionaryType); }
/** * Checks the type of the dictionary. * @param type the type you're looking for * @return true if the type of the dictionary corresponds with the type you're looking for */ public boolean checkType(PdfName type) { if (type == null) return false; if (dictionaryType == null) dictionaryType = getAsName(PdfName.TYPE); return type.equals(dictionaryType); }
static boolean isTextField(PdfDictionary field) { PdfName type = field.getAsName(PdfName.FT); return PdfName.TX.equals(type); }
static boolean isTextField(PdfDictionary field) { PdfName type = field.getAsName(PdfName.FT); return PdfName.TX.equals(type); }
/** * Gets the field names that have blank signatures. * * @return the field names that have blank signatures */ public ArrayList<String> getBlankSignatureNames() { getSignatureNames(); ArrayList<String> sigs = new ArrayList<String>(); for (Map.Entry<String, Item> entry: fields.entrySet()) { Item item = entry.getValue(); PdfDictionary merged = item.getMerged(0); if (!PdfName.SIG.equals(merged.getAsName(PdfName.FT))) continue; if (sigNames.containsKey(entry.getKey())) continue; sigs.add(entry.getKey()); } return sigs; }
/** * Gets the field names that have blank signatures. * * @return the field names that have blank signatures */ public ArrayList<String> getBlankSignatureNames() { getSignatureNames(); ArrayList<String> sigs = new ArrayList<String>(); for (Map.Entry<String, Item> entry: fields.entrySet()) { Item item = entry.getValue(); PdfDictionary merged = item.getMerged(0); if (!PdfName.SIG.equals(merged.getAsName(PdfName.FT))) continue; if (sigNames.containsKey(entry.getKey())) continue; sigs.add(entry.getKey()); } return sigs; }
protected void checkEmbeddedFile(PdfDictionary embeddedFile) { PdfName subtype = embeddedFile.getAsName(PdfName.SUBTYPE); if (subtype == null || !MimeTypePdf.equals(subtype)) { throw new PdfAConformanceException(embeddedFile, MessageLocalization.getComposedMessage("embedded.file.shall.contain.pdf.mime.type")); } }
static Integer getFlags(PdfDictionary field) { PdfName type = field.getAsName(PdfName.FT); if (!PdfName.BTN.equals(type)) return null; PdfNumber flags = field.getAsNumber(PdfName.FF); if (flags == null) return null; return flags.intValue(); }
static Integer getFlags(PdfDictionary field) { PdfName type = field.getAsName(PdfName.FT); if (!PdfName.BTN.equals(type)) return null; PdfNumber flags = field.getAsNumber(PdfName.FF); if (flags == null) return null; return flags.intValue(); }
@Override protected void checkPdfObject(PdfWriter writer, int key, Object obj1) { super.checkPdfObject(writer, key, obj1); if (obj1 instanceof PdfDictionary) { PdfDictionary dictionary = (PdfDictionary) obj1; PdfName type = dictionary.getAsName(PdfName.TYPE); if (PdfName.EMBEDDEDFILE.equals(type)) { checkEmbeddedFile(dictionary); } } } }
private static void addFont(PRIndirectReference fontRef, IntHashtable hits, ArrayList<Object[]> fonts) { PdfObject obj = PdfReader.getPdfObject(fontRef); if (obj == null || !obj.isDictionary()) return; PdfDictionary font = (PdfDictionary)obj; PdfName subtype = font.getAsName(PdfName.SUBTYPE); if (!PdfName.TYPE1.equals(subtype) && !PdfName.TRUETYPE.equals(subtype) && !PdfName.TYPE0.equals(subtype)) return; PdfName name = font.getAsName(PdfName.BASEFONT); fonts.add(new Object[]{PdfName.decodeName(name.toString()), fontRef}); hits.put(fontRef.getNumber(), 1); }
private static void addFont(PRIndirectReference fontRef, IntHashtable hits, ArrayList<Object[]> fonts) { PdfObject obj = PdfReader.getPdfObject(fontRef); if (obj == null || !obj.isDictionary()) return; PdfDictionary font = (PdfDictionary)obj; PdfName subtype = font.getAsName(PdfName.SUBTYPE); if (!PdfName.TYPE1.equals(subtype) && !PdfName.TRUETYPE.equals(subtype) && !PdfName.TYPE0.equals(subtype)) return; PdfName name = font.getAsName(PdfName.BASEFONT); fonts.add(new Object[]{PdfName.decodeName(name.toString()), fontRef}); hits.put(fontRef.getNumber(), 1); }
static PdfDictionary getKDict(PdfDictionary obj) { PdfDictionary k = obj.getAsDict(PdfName.K); if (k != null) { if (PdfName.OBJR.equals(k.getAsName(PdfName.TYPE))) { return k; } } else { PdfArray k1 = obj.getAsArray(PdfName.K); if (k1 == null) return null; for (int i = 0; i < k1.size(); i++) { k = k1.getAsDict(i); if (k != null) { if (PdfName.OBJR.equals(k.getAsName(PdfName.TYPE))) { return k; } } } } return null; }
/** * Computes the number of unfiltered bytes that each row of the image will contain. * If the number of bytes results in a partial terminating byte, this number is rounded up * per the PDF specification * @param imageDictionary the dictionary of the inline image * @return the number of bytes per row of the image */ private static int computeBytesPerRow(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic){ PdfNumber wObj = imageDictionary.getAsNumber(PdfName.WIDTH); PdfNumber bpcObj = imageDictionary.getAsNumber(PdfName.BITSPERCOMPONENT); int cpp = getComponentsPerPixel(imageDictionary.getAsName(PdfName.COLORSPACE), colorSpaceDic); int w = wObj.intValue(); int bpc = bpcObj != null ? bpcObj.intValue() : 1; int bytesPerRow = (w * bpc * cpp + 7) / 8; return bytesPerRow; }
/** * Computes the number of unfiltered bytes that each row of the image will contain. * If the number of bytes results in a partial terminating byte, this number is rounded up * per the PDF specification * @param imageDictionary the dictionary of the inline image * @return the number of bytes per row of the image */ private static int computeBytesPerRow(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic){ PdfNumber wObj = imageDictionary.getAsNumber(PdfName.WIDTH); PdfNumber bpcObj = imageDictionary.getAsNumber(PdfName.BITSPERCOMPONENT); int cpp = getComponentsPerPixel(imageDictionary.getAsName(PdfName.COLORSPACE), colorSpaceDic); int w = wObj.intValue(); int bpc = bpcObj != null ? bpcObj.intValue() : 1; int bytesPerRow = (w * bpc * cpp + 7) / 8; return bytesPerRow; }
protected void readFields() { catalog = trailer.getAsDict(PdfName.ROOT); PdfDictionary fdf = catalog.getAsDict(PdfName.FDF); if (fdf == null) return; PdfString fs = fdf.getAsString(PdfName.F); if (fs != null) fileSpec = fs.toUnicodeString(); PdfArray fld = fdf.getAsArray(PdfName.FIELDS); if (fld == null) return; encoding = fdf.getAsName(PdfName.ENCODING); PdfDictionary merged = new PdfDictionary(); merged.put(PdfName.KIDS, fld); kidNode(merged, ""); }
protected void readFields() { catalog = trailer.getAsDict(PdfName.ROOT); PdfDictionary fdf = catalog.getAsDict(PdfName.FDF); if (fdf == null) return; PdfString fs = fdf.getAsString(PdfName.F); if (fs != null) fileSpec = fs.toUnicodeString(); PdfArray fld = fdf.getAsArray(PdfName.FIELDS); if (fld == null) return; encoding = fdf.getAsName(PdfName.ENCODING); PdfDictionary merged = new PdfDictionary(); merged.put(PdfName.KIDS, fld); kidNode(merged, ""); }
/** * @see com.itextpdf.text.pdf.interfaces.PdfVersion#addDeveloperExtension(com.itextpdf.text.pdf.PdfDeveloperExtension) * @since 2.1.6 */ public void addDeveloperExtension(PdfDeveloperExtension de) { if (extensions == null) { extensions = new PdfDictionary(); } else { PdfDictionary extension = extensions.getAsDict(de.getPrefix()); if (extension != null) { int diff = de.getBaseversion().compareTo(extension.getAsName(PdfName.BASEVERSION)); if (diff < 0) return; diff = de.getExtensionLevel() - extension.getAsNumber(PdfName.EXTENSIONLEVEL).intValue(); if (diff <= 0) return; } } extensions.put(de.getPrefix(), de.getDeveloperExtensions()); }
protected void readColorProfile() { PdfObject outputIntents = reader.getCatalog().getAsArray(PdfName.OUTPUTINTENTS); if (outputIntents != null && ((PdfArray) outputIntents).size() > 0) { PdfStream iccProfileStream = null; for (int i = 0; i < ((PdfArray) outputIntents).size(); i++) { PdfDictionary outputIntentDictionary = ((PdfArray) outputIntents).getAsDict(i); if (outputIntentDictionary != null) { PdfName gts = outputIntentDictionary.getAsName(PdfName.S); if (iccProfileStream == null || PdfName.GTS_PDFA1.equals(gts)) { iccProfileStream = outputIntentDictionary.getAsStream(PdfName.DESTOUTPUTPROFILE); if (iccProfileStream != null && PdfName.GTS_PDFA1.equals(gts)) break; } } } if (iccProfileStream instanceof PRStream) { try { colorProfile = ICC_Profile.getInstance(PdfReader.getStreamBytes((PRStream)iccProfileStream)); } catch(IOException exc) { throw new ExceptionConverter(exc); } } } }