/** * Checks if some value is valid for a certain key. */ private boolean isPossibleValue(PdfName value, PdfName[] accepted) { for (int i = 0; i < accepted.length; i++) { if (accepted[i].equals(value)) { return true; } } return false; }
/** @see com.itextpdf.text.pdf.interfaces.PdfDocumentActions#setAdditionalAction(com.itextpdf.text.pdf.PdfName, com.itextpdf.text.pdf.PdfAction) */ public void setAdditionalAction(final PdfName actionType, final PdfAction action) throws DocumentException { if (!(actionType.equals(DOCUMENT_CLOSE) || actionType.equals(WILL_SAVE) || actionType.equals(DID_SAVE) || actionType.equals(WILL_PRINT) || actionType.equals(DID_PRINT))) { throw new DocumentException(MessageLocalization.getComposedMessage("invalid.additional.action.type.1", actionType.toString())); } pdf.addAdditionalAction(actionType, action); }
/** * 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); }
private Signature initSignature(PublicKey key) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException { String digestAlgorithm = getDigestAlgorithm(); if (PdfName.ADBE_X509_RSA_SHA1.equals(getFilterSubtype())) digestAlgorithm = "SHA1withRSA"; Signature signature; if (provider == null) signature = Signature.getInstance(digestAlgorithm); else signature = Signature.getInstance(digestAlgorithm, provider); signature.initVerify(key); return signature; }
/** * Sets the annotation's highlighting mode. The values can be * <CODE>HIGHLIGHT_NONE</CODE>, <CODE>HIGHLIGHT_INVERT</CODE>, * <CODE>HIGHLIGHT_OUTLINE</CODE> and <CODE>HIGHLIGHT_PUSH</CODE>; * @param highlight the annotation's highlighting mode */ public void setHighlighting(PdfName highlight) { if (highlight.equals(HIGHLIGHT_INVERT)) remove(PdfName.H); else put(PdfName.H, highlight); }
/** @see com.itextpdf.text.pdf.interfaces.PdfPageActions#setPageAction(com.itextpdf.text.pdf.PdfName, com.itextpdf.text.pdf.PdfAction) */ public void setPageAction(final PdfName actionType, final PdfAction action) throws DocumentException { if (!actionType.equals(PAGE_OPEN) && !actionType.equals(PAGE_CLOSE)) throw new DocumentException(MessageLocalization.getComposedMessage("invalid.page.additional.action.type.1", actionType.toString())); pdf.setPageAction(actionType, action); }
/** @see com.itextpdf.text.pdf.interfaces.PdfPageActions#setPageAction(com.itextpdf.text.pdf.PdfName, com.itextpdf.text.pdf.PdfAction) */ public void setPageAction(final PdfName actionType, final PdfAction action) throws DocumentException { if (!actionType.equals(PAGE_OPEN) && !actionType.equals(PAGE_CLOSE)) throw new DocumentException(MessageLocalization.getComposedMessage("invalid.page.additional.action.type.1", actionType.toString())); pdf.setPageAction(actionType, action); }
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); }
@Override public PdfAnnotation createAnnotation(float llx, float lly, float urx, float ury, PdfAction action, PdfName subtype) { PdfAnnotation a = super.createAnnotation(llx, lly, urx, ury, action, subtype); if (!PdfName.POPUP.equals(subtype)) a.put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT)); return a; }
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 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 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); } } } }
@Override public PdfAnnotation createAnnotation(Rectangle rect, PdfName subtype) { PdfAnnotation a = super.createAnnotation(rect, subtype); if (!PdfName.POPUP.equals(subtype)) a.put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT)); return a; }
@Override public PdfAnnotation createAnnotation(float llx, float lly, float urx, float ury, PdfString title, PdfString content, PdfName subtype) { PdfAnnotation a = super.createAnnotation(llx, lly, urx, ury, title, content, subtype); if (!PdfName.POPUP.equals(subtype)) a.put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT)); return a; }
@Override public PdfAnnotation createAnnotation(float llx, float lly, float urx, float ury, PdfString title, PdfString content, PdfName subtype) { PdfAnnotation a = super.createAnnotation(llx, lly, urx, ury, title, content, subtype); if (!PdfName.POPUP.equals(subtype)) a.put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT)); return a; }
public void checkElementRole(IAccessibleElement element, IAccessibleElement parent) { if (parent != null && (parent.getRole() == null || PdfName.ARTIFACT.equals(parent.getRole()))) element.setRole(null); else if ((taggingMode & markInlineElementsOnly) != 0) { if (element.isInline() && element.getRole() == null && (parent == null || !parent.isInline())) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("inline.elements.with.role.null.are.not.allowed")); } }
public void setWidget(Rectangle rect, PdfName highlight) { put(PdfName.TYPE, PdfName.ANNOT); put(PdfName.SUBTYPE, PdfName.WIDGET); put(PdfName.RECT, new PdfRectangle(rect)); annotation = true; if (highlight != null && !highlight.equals(HIGHLIGHT_INVERT)) put(PdfName.H, highlight); }
public void checkElementRole(IAccessibleElement element, IAccessibleElement parent) { if (parent != null && (parent.getRole() == null || PdfName.ARTIFACT.equals(parent.getRole()))) element.setRole(null); else if ((taggingMode & markInlineElementsOnly) != 0) { if (element.isInline() && element.getRole() == null && (parent == null || !parent.isInline())) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("inline.elements.with.role.null.are.not.allowed")); } }