/** * Adds a <CODE>PdfWriter</CODE> to the <CODE>PdfDocument</CODE>. * * @param writer the <CODE>PdfWriter</CODE> that writes everything * what is added to this document to an outputstream. * @throws DocumentException on error */ public void addWriter(PdfWriter writer) throws DocumentException { if (this.writer == null) { this.writer = writer; annotationsImp = new PdfAnnotationsImp(writer); return; } throw new DocumentException("You can only add a writer to a PdfDocument once."); }
void addAnnotation(PdfAnnotation annot) { pageEmpty = false; annotationsImp.addAnnotation(annot); }
void addCalculationOrder(PdfFormField formField) { annotationsImp.addCalculationOrder(formField); }
if (annotationsImp.hasValidAcroForm()) { try { catalog.put(PdfName.ACROFORM, writer.addToBody(annotationsImp.getAcroForm()).getIndirectReference());
if (annotationsImp.hasUnusedAnnotations()) { PdfArray array = annotationsImp.rotateAnnotations(writer, pageSize); if (array.size() != 0) page.put(PdfName.ANNOTS, array);
if (line != null) rect = new Rectangle(annot.llx(indentRight() - line.widthLeft()), annot.ury(indentTop() - currentHeight - 20), annot.urx(indentRight() - line.widthLeft() + 20), annot.lly(indentTop() - currentHeight)); PdfAnnotation an = PdfAnnotationsImp.convertAnnotation(writer, annot, rect); annotationsImp.addPlainAnnotation(an); pageEmpty = false; break;
void addFormFieldRaw(PdfFormField field) { annotations.add(field); ArrayList kids = field.getKids(); if (kids != null) { for (int k = 0; k < kids.size(); ++k) addFormFieldRaw((PdfFormField)kids.get(k)); } }
/** * Implements a link to other part of the document. The jump will * be made to a local destination with the same name, that must exist. * @param name the name for this link * @param llx the lower left x corner of the activation area * @param lly the lower left y corner of the activation area * @param urx the upper right x corner of the activation area * @param ury the upper right y corner of the activation area */ void localGoto(String name, float llx, float lly, float urx, float ury) { PdfAction action = getLocalGotoAction(name); annotationsImp.addPlainAnnotation(new PdfAnnotation(writer, llx, lly, urx, ury, action)); }
/** * Gets the AcroForm object. * @return the PdfAcroform object of the PdfDocument */ PdfAcroForm getAcroForm() { return annotationsImp.getAcroForm(); }
/** * Closes the document. * <B> * Once all the content has been written in the body, you have to close * the body. After that nothing can be written to the body anymore. */ public void close() { if (close) { return; } try { boolean wasImage = (imageWait != null); newPage(); if (imageWait != null || wasImage) newPage(); if (annotationsImp.hasUnusedAnnotations()) throw new RuntimeException("Not all annotations could be added to the document (the document doesn't have enough pages)."); PdfPageEvent pageEvent = writer.getPageEvent(); if (pageEvent != null) pageEvent.onCloseDocument(writer, this); super.close(); writer.addLocalDestinations(localDestinations); calculateOutlineCount(); writeOutlines(); } catch(Exception e) { throw ExceptionConverter.convertException(e); } writer.close(); }
annotationsImp.resetAnnotations(); pageResources = new PageResources();
PdfAnnotation an = PdfAnnotationsImp.convertAnnotation(writer, annot, new Rectangle(llx, lly, urx, ury)); if (an == null) return;
if (annotationsImp.hasValidAcroForm()) { try { catalog.put(PdfName.ACROFORM, writer.addToBody(annotationsImp.getAcroForm()).getIndirectReference());
if (annotationsImp.hasUnusedAnnotations()) { PdfArray array = annotationsImp.rotateAnnotations(writer, pageSize); if (array.size() != 0) page.put(PdfName.ANNOTS, array);
if (line != null) rect = new Rectangle(annot.llx(indentRight() - line.widthLeft()), annot.ury(indentTop() - currentHeight - 20), annot.urx(indentRight() - line.widthLeft() + 20), annot.lly(indentTop() - currentHeight)); PdfAnnotation an = PdfAnnotationsImp.convertAnnotation(writer, annot, rect); annotationsImp.addPlainAnnotation(an); pageEmpty = false; break;
void addFormFieldRaw(PdfFormField field) { annotations.add(field); ArrayList kids = field.getKids(); if (kids != null) { for (int k = 0; k < kids.size(); ++k) addFormFieldRaw((PdfFormField)kids.get(k)); } }
/** * Implements a link to other part of the document. The jump will * be made to a local destination with the same name, that must exist. * @param name the name for this link * @param llx the lower left x corner of the activation area * @param lly the lower left y corner of the activation area * @param urx the upper right x corner of the activation area * @param ury the upper right y corner of the activation area */ void localGoto(String name, float llx, float lly, float urx, float ury) { PdfAction action = getLocalGotoAction(name); annotationsImp.addPlainAnnotation(new PdfAnnotation(writer, llx, lly, urx, ury, action)); }
/** * Gets the AcroForm object. * @return the PdfAcroform object of the PdfDocument */ PdfAcroForm getAcroForm() { return annotationsImp.getAcroForm(); }
/** * Closes the document. * <B> * Once all the content has been written in the body, you have to close * the body. After that nothing can be written to the body anymore. */ public void close() { if (close) { return; } try { boolean wasImage = (imageWait != null); newPage(); if (imageWait != null || wasImage) newPage(); if (annotationsImp.hasUnusedAnnotations()) throw new RuntimeException(MessageLocalization.getComposedMessage("not.all.annotations.could.be.added.to.the.document.the.document.doesn.t.have.enough.pages")); PdfPageEvent pageEvent = writer.getPageEvent(); if (pageEvent != null) pageEvent.onCloseDocument(writer, this); super.close(); writer.addLocalDestinations(localDestinations); calculateOutlineCount(); writeOutlines(); } catch(Exception e) { throw new ExceptionConverter(e); } writer.close(); }
annotationsImp.resetAnnotations(); pageResources = new PageResources();