/** * Determine if an MCID is available * @return true if the MCID is available, false otherwise */ public boolean hasMcid(){ return dictionary.contains(PdfName.MCID); }
/** * Determine if an MCID is available * @return true if the MCID is available, false otherwise */ public boolean hasMcid(){ return dictionary.contains(PdfName.MCID); }
/** * Checks if this PDF has usage rights enabled. * * @return <code>true</code> if usage rights are present; <code>false</code> otherwise */ public boolean hasUsageRights() { PdfDictionary perms = catalog.getAsDict(PdfName.PERMS); if (perms == null) return false; return perms.contains(PdfName.UR) || perms.contains(PdfName.UR3); }
/** * Checks if this PDF has usage rights enabled. * * @return <code>true</code> if usage rights are present; <code>false</code> otherwise */ public boolean hasUsageRights() { PdfDictionary perms = catalog.getAsDict(PdfName.PERMS); if (perms == null) return false; return perms.contains(PdfName.UR) || perms.contains(PdfName.UR3); }
/** * Gets the first entarance of attribute. * @returns PdfObject * @since 5.3.4 */ public PdfObject getAttribute(PdfName name){ PdfDictionary attr = getAsDict(PdfName.A); if (attr != null){ if (attr.contains(name)) return attr.get(name); } return null; }
/** * Gets the first entarance of attribute. * @returns PdfObject * @since 5.3.4 */ public PdfObject getAttribute(PdfName name){ PdfDictionary attr = getAsDict(PdfName.A); if (attr != null){ if (attr.contains(name)) return attr.get(name); } return null; }
/** * Gets number of indirect. If type of directed indirect is PAGES, it refers PAGE object through KIDS. * (Contributed by Kazuya Ujihara) * @param indirect * 2004-06-13 */ private static int getNumber(PdfIndirectReference indirect) { PdfDictionary pdfObj = (PdfDictionary)PdfReader.getPdfObjectRelease(indirect); if (pdfObj.contains(PdfName.TYPE) && pdfObj.get(PdfName.TYPE).equals(PdfName.PAGES) && pdfObj.contains(PdfName.KIDS)) { PdfArray kids = (PdfArray)pdfObj.get(PdfName.KIDS); indirect = (PdfIndirectReference)kids.getPdfObject(0); } return indirect.getNumber(); }
/** * Gets number of indirect. If type of directed indirect is PAGES, it refers PAGE object through KIDS. * (Contributed by Kazuya Ujihara) * @param indirect * 2004-06-13 */ private static int getNumber(PdfIndirectReference indirect) { PdfDictionary pdfObj = (PdfDictionary)PdfReader.getPdfObjectRelease(indirect); if (pdfObj.contains(PdfName.TYPE) && pdfObj.get(PdfName.TYPE).equals(PdfName.PAGES) && pdfObj.contains(PdfName.KIDS)) { PdfArray kids = (PdfArray)pdfObj.get(PdfName.KIDS); indirect = (PdfIndirectReference)kids.getPdfObject(0); } return indirect.getNumber(); }
@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")); } 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); } } }
@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); } } }
@SuppressWarnings("unchecked") PdfArray calculate(HashMap<String, Object> map) throws IOException { PdfArray ar = new PdfArray(); for (Map.Entry<String, Object> entry: map.entrySet()) { String key = entry.getKey(); Object v = entry.getValue(); PdfDictionary dic = new PdfDictionary(); dic.put(PdfName.T, new PdfString(key, PdfObject.TEXT_UNICODE)); if (v instanceof HashMap) { dic.put(PdfName.KIDS, calculate((HashMap<String, Object>)v)); } else if(v instanceof PdfAction) { // (plaflamme) dic.put(PdfName.A, (PdfAction)v); } else if (v instanceof PdfAnnotation) { dic.put(PdfName.AA, (PdfAnnotation)v); } else if (v instanceof PdfDictionary && ((PdfDictionary)v).size() == 1 && ((PdfDictionary)v).contains(PdfName.N)) { dic.put(PdfName.AP, (PdfDictionary)v); } else { dic.put(PdfName.V, (PdfObject)v); } ar.add(dic); } return ar; } }
/** * Gets the first entarance of attribute. * @returns PdfObject * @since 5.3.4 */ public PdfObject getAttribute(PdfName name){ PdfDictionary attr = getAsDict(PdfName.A); if (attr != null){ if (attr.contains(name)) return attr.get(name); } PdfDictionary parent = getParent(); if (parent instanceof PdfStructureElement) return ((PdfStructureElement) parent).getAttribute(name); if (parent instanceof PdfStructureTreeRoot) return ((PdfStructureTreeRoot) parent).getAttribute(name); return new PdfNull(); }
@SuppressWarnings("unchecked") PdfArray calculate(HashMap<String, Object> map) throws IOException { PdfArray ar = new PdfArray(); for (Map.Entry<String, Object> entry: map.entrySet()) { String key = entry.getKey(); Object v = entry.getValue(); PdfDictionary dic = new PdfDictionary(); dic.put(PdfName.T, new PdfString(key, PdfObject.TEXT_UNICODE)); if (v instanceof HashMap) { dic.put(PdfName.KIDS, calculate((HashMap<String, Object>)v)); } else if(v instanceof PdfAction) { // (plaflamme) dic.put(PdfName.A, (PdfAction)v); } else if (v instanceof PdfAnnotation) { dic.put(PdfName.AA, (PdfAnnotation)v); } else if (v instanceof PdfDictionary && ((PdfDictionary)v).size() == 1 && ((PdfDictionary)v).contains(PdfName.N)) { dic.put(PdfName.AP, (PdfDictionary)v); } else { dic.put(PdfName.V, (PdfObject)v); } ar.add(dic); } return ar; } }
/** * Gets the first entarance of attribute. * @returns PdfObject * @since 5.3.4 */ public PdfObject getAttribute(PdfName name){ PdfDictionary attr = getAsDict(PdfName.A); if (attr != null){ if (attr.contains(name)) return attr.get(name); } PdfDictionary parent = getParent(); if (parent instanceof PdfStructureElement) return ((PdfStructureElement) parent).getAttribute(name); if (parent instanceof PdfStructureTreeRoot) return ((PdfStructureTreeRoot) parent).getAttribute(name); return new PdfNull(); }
dr.put(PdfName.FONT, fonts); if (!fonts.contains(PdfName.HELV)) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); dic.put(PdfName.BASEFONT, PdfName.HELVETICA); fonts.put(PdfName.HELV, addToBody(dic).getIndirectReference()); if (!fonts.contains(PdfName.ZADB)) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); dic.put(PdfName.BASEFONT, PdfName.ZAPFDINGBATS);
/** * Writes a <CODE>PdfImage</CODE> to the outputstream. * * @param pdfImage the image to be added * @param fixedRef the IndirectReference, may be null then a new indirect reference is returned * @return a <CODE>PdfIndirectReference</CODE> to the encapsulated image * @throws PdfException when a document isn't open yet, or has been closed */ PdfIndirectReference add(final PdfImage pdfImage, PdfIndirectReference fixedRef) throws PdfException { if (! imageDictionary.contains(pdfImage.name())) { PdfWriter.checkPdfIsoConformance(this, PdfIsoKeys.PDFISOKEY_IMAGE, pdfImage); if (fixedRef instanceof PRIndirectReference) { PRIndirectReference r2 = (PRIndirectReference)fixedRef; fixedRef = new PdfIndirectReference(0, getNewObjectNumber(r2.getReader(), r2.getNumber(), r2.getGeneration())); } try { if (fixedRef == null) fixedRef = addToBody(pdfImage).getIndirectReference(); else addToBody(pdfImage, fixedRef); } catch(IOException ioe) { throw new ExceptionConverter(ioe); } imageDictionary.put(pdfImage.name(), fixedRef); return fixedRef; } return (PdfIndirectReference) imageDictionary.get(pdfImage.name()); }
void addDocumentField(PdfIndirectReference ref) { PdfDictionary catalog = reader.getCatalog(); PdfDictionary acroForm = (PdfDictionary) PdfReader.getPdfObject(catalog.get(PdfName.ACROFORM), catalog); if (acroForm == null) { acroForm = new PdfDictionary(); catalog.put(PdfName.ACROFORM, acroForm); markUsed(catalog); } PdfArray fields = (PdfArray) PdfReader.getPdfObject(acroForm.get(PdfName.FIELDS), acroForm); if (fields == null) { fields = new PdfArray(); acroForm.put(PdfName.FIELDS, fields); markUsed(acroForm); } if (!acroForm.contains(PdfName.DA)) { acroForm.put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g ")); markUsed(acroForm); } fields.add(ref); markUsed(fields); }
void addDocumentField(PdfIndirectReference ref) { PdfDictionary catalog = reader.getCatalog(); PdfDictionary acroForm = (PdfDictionary) PdfReader.getPdfObject(catalog.get(PdfName.ACROFORM), catalog); if (acroForm == null) { acroForm = new PdfDictionary(); catalog.put(PdfName.ACROFORM, acroForm); markUsed(catalog); } PdfArray fields = (PdfArray) PdfReader.getPdfObject(acroForm.get(PdfName.FIELDS), acroForm); if (fields == null) { fields = new PdfArray(); acroForm.put(PdfName.FIELDS, fields); markUsed(acroForm); } if (!acroForm.contains(PdfName.DA)) { acroForm.put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g ")); markUsed(acroForm); } fields.add(ref); markUsed(fields); }
/** * Writes a <CODE>PdfImage</CODE> to the outputstream. * * @param pdfImage the image to be added * @param fixedRef the IndirectReference, may be null then a new indirect reference is returned * @return a <CODE>PdfIndirectReference</CODE> to the encapsulated image * @throws PdfException when a document isn't open yet, or has been closed */ PdfIndirectReference add(final PdfImage pdfImage, PdfIndirectReference fixedRef) throws PdfException { if (! imageDictionary.contains(pdfImage.name())) { PdfWriter.checkPdfIsoConformance(this, PdfIsoKeys.PDFISOKEY_IMAGE, pdfImage); if (fixedRef instanceof PRIndirectReference) { PRIndirectReference r2 = (PRIndirectReference)fixedRef; fixedRef = new PdfIndirectReference(0, getNewObjectNumber(r2.getReader(), r2.getNumber(), r2.getGeneration())); } try { if (fixedRef == null) fixedRef = addToBody(pdfImage).getIndirectReference(); else addToBody(pdfImage, fixedRef); } catch(IOException ioe) { throw new ExceptionConverter(ioe); } imageDictionary.put(pdfImage.name(), fixedRef); return fixedRef; } return (PdfIndirectReference) imageDictionary.get(pdfImage.name()); }
private void init(PdfDictionary parent, PdfName structureType) { if (!top.getWriter().getStandardStructElems().contains(structureType)) { PdfDictionary roleMap = top.getAsDict(PdfName.ROLEMAP); if (roleMap == null || !roleMap.contains(structureType)) throw new ExceptionConverter(new DocumentException(MessageLocalization.getComposedMessage("unknown.structure.element.role.1", structureType.toString()))); else