public void setBorder(PdfBorderArray border) { put(PdfName.BORDER, border); }
/** * A wrapper around PdfAnnotation constructor. * It is recommended to use this wrapper instead of direct constructor as this is a convenient way to override PdfAnnotation construction when needed. * * @param rect * @param subtype * @return */ public PdfAnnotation createAnnotation(Rectangle rect, PdfName subtype) { PdfAnnotation a = new PdfAnnotation(this, rect); if (subtype != null) a.put(PdfName.SUBTYPE, subtype); return a; }
/** * Creates an Annotation with an Action. * @param writer * @param rect * @param highlight * @param action * @return A PdfAnnotation */ public static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight, PdfAction action) { PdfAnnotation annot = createLink(writer, rect, highlight); annot.putEx(PdfName.A, action); return annot; }
public void setPopup(PdfAnnotation popup) { put(PdfName.POPUP, popup.getIndirectReference()); popup.put(PdfName.PARENT, getIndirectReference()); }
void addAnnotation(PdfAnnotation annot, PdfDictionary pageN) { try { ArrayList<PdfAnnotation> allAnnots = new ArrayList<PdfAnnotation>(); if (annot.isForm()) { fieldsAdded = true; getAcroFields(); for (int k = 0; k < allAnnots.size(); ++k) { annot = allAnnots.get(k); if (annot.getPlaceInPage() > 0) pageN = reader.getPageN(annot.getPlaceInPage()); if (annot.isForm()) { if (!annot.isUsed()) { HashSet<PdfTemplate> templates = annot.getTemplates(); if (templates != null) fieldTemplates.addAll(templates); if (annot.isAnnotation()) { PdfObject pdfobj = PdfReader.getPdfObject(pageN.get(PdfName.ANNOTS), pageN); PdfArray annots = null; } else annots = (PdfArray) pdfobj; annots.add(annot.getIndirectReference()); markUsed(annots); if (!annot.isUsed()) { PdfRectangle rect = (PdfRectangle) annot.get(PdfName.RECT); if (rect != null && (rect.left() != 0 || rect.right() != 0 || rect.top() != 0 || rect.bottom() != 0)) { int rotation = reader.getPageRotation(pageN);
/** * Creates a screen PdfAnnotation * @param writer * @param rect * @param clipTitle * @param fs * @param mimeType * @param playOnDisplay * @return a screen PdfAnnotation * @throws IOException */ public static PdfAnnotation createScreen(PdfWriter writer, Rectangle rect, String clipTitle, PdfFileSpecification fs, String mimeType, boolean playOnDisplay) throws IOException { PdfAnnotation ann = writer.createAnnotation(rect, PdfName.SCREEN); ann.put (PdfName.F, new PdfNumber(FLAGS_PRINT)); ann.put(PdfName.TYPE, PdfName.ANNOT); ann.setPage(); PdfIndirectReference ref = ann.getIndirectReference(); PdfAction action = PdfAction.rendition(clipTitle,fs,mimeType, ref); PdfIndirectReference actionRef = writer.addToBody(action).getIndirectReference(); // for play on display add trigger event if (playOnDisplay) { PdfDictionary aa = new PdfDictionary(); aa.put(new PdfName("PV"), actionRef); ann.put(PdfName.AA, aa); } ann.put(PdfName.A, actionRef); return ann; }
/** * Creates an Annotation with an local destination. * @param writer * @param rect * @param highlight * @param namedDestination * @return A PdfAnnotation */ public static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight, String namedDestination) { PdfAnnotation annot = createLink(writer, rect, highlight); annot.put(PdfName.DEST, new PdfString(namedDestination, PdfObject.TEXT_UNICODE)); return annot; }
Rectangle rect = new Rectangle(220, 350, 475, 595); PdfAnnotation annotation = PdfAnnotation.createLine(writer, rect, "Cambridge Innovation Center", 225, 355, 470, 590); PdfArray le = new PdfArray(); le.add(new PdfName("OpenArrow")); le.add(new PdfName("None")); annotation.setTitle("You are here:"); annotation.setColor(BaseColor.RED); annotation.setFlags(PdfAnnotation.FLAGS_PRINT); annotation.setBorderStyle( new PdfBorderDictionary(5, PdfBorderDictionary.STYLE_SOLID)); annotation.put(new PdfName("LE"), le); annotation.put(new PdfName("IT"), new PdfName("LineArrow")); writer.addAnnotation(annotation);
targetArea.setBorderWidth(0); PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(), targetArea.getRight(), targetArea.getTop(), action); annot.put(PdfName.SUBTYPE, PdfName.LINK); annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0)); _writer.addAnnotation(annot); return; PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(), targetArea.getRight(), targetArea.getTop(), action); annot.put(PdfName.SUBTYPE, PdfName.LINK); annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0)); _writer.addAnnotation(annot);
void addAnnotation(final PdfAnnotation annot) { boolean needToTag = isTagged() && annot.getRole() != null && (!(annot instanceof PdfFormField) || ((PdfFormField)annot).getKids() == null); if (needToTag) { openMCBlock(annot); } writer.addAnnotation(annot); if (needToTag) { PdfStructureElement strucElem = pdf.getStructElement(annot.getId()); if (strucElem != null) { int structParent = pdf.getStructParentIndex(annot); annot.put(PdfName.STRUCTPARENT, new PdfNumber(structParent)); strucElem.setAnnotation(annot, getCurrentPage()); writer.getStructureTreeRoot().setAnnotationMark(structParent, strucElem.getReference()); } closeMCBlock(annot); } }
void addAnnotation(PdfAnnotation annot, int page) { - annot.setPage(page); + if (annot.isAnnotation()) + annot.setPage(page); addAnnotation(annot, reader.getPageN(page)); }
public void applyCTM(AffineTransform ctm) { PdfArray origRect = getAsArray(PdfName.RECT); if (origRect != null) { PdfRectangle rect; if (origRect.size() == 4) { rect = new PdfRectangle(origRect.getAsNumber(0).floatValue(), origRect.getAsNumber(1).floatValue(), origRect.getAsNumber(2).floatValue(), origRect.getAsNumber(3).floatValue()); } else { rect = new PdfRectangle(origRect.getAsNumber(0).floatValue(), origRect.getAsNumber(1).floatValue()); } put(PdfName.RECT, rect.transform(ctm)); } }
/** * Add some free text to the document. * @param writer * @param rect * @param contents * @param defaultAppearance * @return A PdfAnnotation */ public static PdfAnnotation createFreeText(PdfWriter writer, Rectangle rect, String contents, PdfContentByte defaultAppearance) { PdfAnnotation annot = writer.createAnnotation(rect, PdfName.FREETEXT); annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE)); annot.setDefaultAppearanceString(defaultAppearance); return annot; }
public static PdfAnnotation shallowDuplicate(PdfAnnotation annot) { PdfAnnotation dup; if (annot.isForm()) { dup = new PdfFormField(annot.writer); PdfFormField dupField = (PdfFormField)dup; PdfFormField srcField = (PdfFormField)annot; dupField.parent = srcField.parent; dupField.kids = srcField.kids; } else dup = annot.writer.createAnnotation(null, (PdfName)annot.get(PdfName.SUBTYPE)); dup.merge(annot); dup.form = annot.form; dup.annotation = annot.annotation; dup.templates = annot.templates; return dup; } }
PdfObject subtype = annot.get(PdfName.SUBTYPE); if (subtype == null) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("annotation.type.1.not.allowed", "null")); PdfNumber ca = annot.getAsNumber(PdfName.CA); if (ca != null && ca.floatValue() != 1.0) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("an.annotation.dictionary.shall.not.contain.the.ca.key.with.a.value.other.than.1")); PdfNumber f = annot.getAsNumber(PdfName.F); if (f == null) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("an.annotation.dictionary.shall.contain.the.f.key")); if (PdfName.TEXT.equals(annot.getAsName(PdfName.SUBTYPE))) { if (checkFlag(flags, PdfAnnotation.FLAGS_NOZOOM) == false || checkFlag(flags, PdfAnnotation.FLAGS_NOROTATE) == false) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("text.annotations.should.set.the.nozoom.and.norotate.flag.bits.of.the.f.key.to.1")); if (annot.contains(PdfName.C) || annot.contains(PdfName.IC)) { ICC_Profile colorProfile = ((PdfAWriter) writer).getColorProfile(); String cs = ""; PdfDictionary ap = getDirectDictionary(annot.get(PdfName.AP)); if (ap != null) { if (ap.contains(PdfName.R) || ap.contains(PdfName.D)) { if (PdfName.WIDGET.equals(annot.getAsName(PdfName.SUBTYPE)) && (annot.contains(PdfName.AA) || annot.contains(PdfName.A))) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("widget.annotation.dictionary.or.field.dictionary.shall.not.include.a.or.aa.entry")); if (contentAnnotations.contains(subtype) && !annot.contains(PdfName.CONTENTS)) { throw new PdfAConformanceException(obj1, MessageLocalization.getComposedMessage("annotation.of.type.1.should.have.contents.key", subtype.toString()));
public void addAnnotation(PdfWriter writer, Document document, Rectangle rect, String text) { PdfAnnotation annotation = new PdfAnnotation(writer, new Rectangle( rect.getRight() + 10, rect.getBottom(), rect.getRight() + 30, rect.getTop())); annotation.setTitle("Text annotation"); annotation.put(PdfName.SUBTYPE, PdfName.TEXT); annotation.put(PdfName.OPEN, PdfBoolean.PDFFALSE); annotation.put(PdfName.NAME, new PdfName(text)); writer.addAnnotation(annotation); }
public void addAnnotation(final PdfAnnotation annot, boolean applyCTM) { if (applyCTM && state.CTM.getType() != AffineTransform.TYPE_IDENTITY) { annot.applyCTM(state.CTM); } addAnnotation(annot); }
/** Creates a file attachment annotation. * @param writer the <CODE>PdfWriter</CODE> * @param rect the dimensions in the page of the annotation * @param contents the file description * @param fileStore an array with the file. If it's <CODE>null</CODE> * the file will be read from the disk * @param file the path to the file. It will only be used if * <CODE>fileStore</CODE> is not <CODE>null</CODE> * @param fileDisplay the actual file name stored in the pdf * @throws IOException on error * @return the annotation */ public static PdfAnnotation createFileAttachment(PdfWriter writer, Rectangle rect, String contents, byte fileStore[], String file, String fileDisplay) throws IOException { return createFileAttachment(writer, rect, contents, PdfFileSpecification.fileEmbedded(writer, file, fileDisplay, fileStore)); }