protected String xmlName(PdfName name) { String xmlName = name.toString().replaceFirst("/", ""); xmlName = Character.toLowerCase(xmlName.charAt(0)) + xmlName.substring(1); return xmlName; }
protected String xmlName(PdfName name) { String xmlName = name.toString().replaceFirst("/", ""); xmlName = Character.toLowerCase(xmlName.charAt(0)) + xmlName.substring(1); return xmlName; }
/** toString method */ public String toString() { return action.toString() + (fields == null ? "" : fields.toString()); } }
private boolean compareNamesExtended(PdfName outName, PdfName cmpName, ObjectPath currentPath, CompareResult compareResult) { if (cmpName.compareTo(outName) == 0) { return true; } else { if (compareResult != null && currentPath != null) compareResult.addError(currentPath, String.format("PdfName. Expected: %s. Found: %s", cmpName.toString(), outName.toString())); return false; } }
/** toString method */ public String toString() { return action.toString() + (fields == null ? "" : fields.toString()); } }
private boolean compareNamesExtended(PdfName outName, PdfName cmpName, ObjectPath currentPath, CompareResult compareResult) { if (cmpName.compareTo(outName) == 0) { return true; } else { if (compareResult != null && currentPath != null) compareResult.addError(currentPath, String.format("PdfName. Expected: %s. Found: %s", cmpName.toString(), outName.toString())); return false; } }
/** * Returns the version as a byte[]. * @param version the version character */ public byte[] getVersionAsByteArray(char version) { return DocWriter.getISOBytes(getVersionAsName(version).toString().substring(1)); }
/** * Returns the version as a byte[]. * @param version the version character */ public byte[] getVersionAsByteArray(char version) { return DocWriter.getISOBytes(getVersionAsName(version).toString().substring(1)); }
/** * Visualizes a PdfDictionary object. * @param dictionary a com.itextpdf.text.pdf.PdfDictionary object */ public void listDict(PdfDictionary dictionary) { out.println("<<"); PdfObject value; for (PdfName key: dictionary.getKeys()) { value = dictionary.get(key); out.print(key.toString()); out.print(' '); listAnyObject(value); } out.println(">>"); }
/** * Visualizes a PdfDictionary object. * @param dictionary a com.itextpdf.text.pdf.PdfDictionary object */ public void listDict(PdfDictionary dictionary) { out.println("<<"); PdfObject value; for (PdfName key: dictionary.getKeys()) { value = dictionary.get(key); out.print(key.toString()); out.print(' '); listAnyObject(value); } out.println(">>"); }
/** @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); }
@Override protected void checkStructElem(PdfWriter writer, int key, Object obj1) { if (obj1 instanceof PdfStructureElement) { PdfStructureElement structElem = (PdfStructureElement) obj1; PdfName role = structElem.getStructureType(); if (PdfName.FIGURE.equals(role) || PdfName.FORMULA.equals(role) || PdfName.FORM.equals(role)) { PdfObject o = structElem.get(PdfName.ALT); if (o instanceof PdfString && o.toString().length() > 0) { } else { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("alt.entry.should.specify.alternate.description.for.1.element", role.toString())); } } } }
@Override protected void checkStructElem(PdfWriter writer, int key, Object obj1) { if (obj1 instanceof PdfStructureElement) { PdfStructureElement structElem = (PdfStructureElement) obj1; PdfName role = structElem.getStructureType(); if (PdfName.FIGURE.equals(role) || PdfName.FORMULA.equals(role) || PdfName.FORM.equals(role)) { PdfObject o = structElem.get(PdfName.ALT); if (o instanceof PdfString && o.toString().length() > 0) { } else { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("alt.entry.should.specify.alternate.description.for.1.element", role.toString())); } } } }
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); }
/** @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); }
/** @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); }
/** * Sets the open and close page additional action. * * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE> * or <CODE>PdfWriter.PAGE_CLOSE</CODE> * @param action the action to perform * @param page the page where the action will be applied. The first page is 1 * @throws PdfException if the action type is invalid */ void setPageAction(PdfName actionType, PdfAction action, int page) throws PdfException { if (!actionType.equals(PAGE_OPEN) && !actionType.equals(PAGE_CLOSE)) throw new PdfException(MessageLocalization.getComposedMessage("invalid.page.additional.action.type.1", actionType.toString())); PdfDictionary pg = reader.getPageN(page); PdfDictionary aa = (PdfDictionary) PdfReader.getPdfObject(pg.get(PdfName.AA), pg); if (aa == null) { aa = new PdfDictionary(); pg.put(PdfName.AA, aa); markUsed(pg); } aa.put(actionType, action); markUsed(aa); }
@Override protected void checkImage(PdfWriter writer, int key, Object obj1) { PdfImage image = (PdfImage) obj1; if (image.get(PdfName.SMASK) != null && !PdfName.NONE.equals(image.getAsName(PdfName.SMASK))) throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("the.smask.key.is.not.allowed.in.images")); if (image.contains(PdfName.ALTERNATES)) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("an.image.dictionary.shall.not.contain.alternates.key")); } if (image.contains(PdfName.OPI)) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("an.image.dictionary.shall.not.contain.opi.key")); } PdfBoolean interpolate = image.getAsBoolean(PdfName.INTERPOLATE); if (interpolate != null && interpolate.booleanValue()) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("the.value.of.interpolate.key.shall.not.be.true")); } PdfName intent = image.getAsName(PdfName.INTENT); if (intent != null && !(PdfName.RELATIVECOLORIMETRIC.equals(intent) || PdfName.ABSOLUTECOLORIMETRIC.equals(intent) || PdfName.PERCEPTUAL.equals(intent) || PdfName.SATURATION.equals(intent))) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("1.value.of.intent.key.is.not.allowed", intent.toString())); } }