⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdfannotation.java

📁 处理PDF
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * @param page     * @param dest     * @return A PdfAnnotation     */    public static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight, int page, PdfDestination dest) {        PdfAnnotation annot = createLink(writer, rect, highlight);        PdfIndirectReference ref = writer.getPageReference(page);        dest.addPage(ref);        annot.put(PdfName.DEST, dest);        return annot;    }        /**     * 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 = new PdfAnnotation(writer, rect);        annot.put(PdfName.SUBTYPE, PdfName.FREETEXT);        annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));        annot.setDefaultAppearanceString(defaultAppearance);        return annot;    }    /**     * Adds a line to the document. Move over the line and a tooltip is shown.     * @param writer     * @param rect     * @param contents     * @param x1     * @param y1     * @param x2     * @param y2     * @return A PdfAnnotation     */    public static PdfAnnotation createLine(PdfWriter writer, Rectangle rect, String contents, float x1, float y1, float x2, float y2) {        PdfAnnotation annot = new PdfAnnotation(writer, rect);        annot.put(PdfName.SUBTYPE, PdfName.LINE);        annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));        PdfArray array = new PdfArray(new PdfNumber(x1));        array.add(new PdfNumber(y1));        array.add(new PdfNumber(x2));        array.add(new PdfNumber(y2));        annot.put(PdfName.L, array);        return annot;    }    /**     * Adds a circle or a square that shows a tooltip when you pass over it.     * @param writer     * @param rect     * @param contents The tooltip     * @param square true if you want a square, false if you want a circle     * @return A PdfAnnotation     */    public static PdfAnnotation createSquareCircle(PdfWriter writer, Rectangle rect, String contents, boolean square) {        PdfAnnotation annot = new PdfAnnotation(writer, rect);        if (square)            annot.put(PdfName.SUBTYPE, PdfName.SQUARE);        else            annot.put(PdfName.SUBTYPE, PdfName.CIRCLE);        annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));        return annot;    }    public static PdfAnnotation createMarkup(PdfWriter writer, Rectangle rect, String contents, int type, float quadPoints[]) {        PdfAnnotation annot = new PdfAnnotation(writer, rect);        PdfName name = PdfName.HIGHLIGHT;        switch (type) {            case MARKUP_UNDERLINE:                name = PdfName.UNDERLINE;                break;            case MARKUP_STRIKEOUT:                name = PdfName.STRIKEOUT;                break;            case MARKUP_SQUIGGLY:                name = PdfName.SQUIGGLY;                break;        }        annot.put(PdfName.SUBTYPE, name);        annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));        PdfArray array = new PdfArray();        for (int k = 0; k < quadPoints.length; ++k)        	array.add(new PdfNumber(quadPoints[k]));        annot.put(PdfName.QUADPOINTS, array);        return annot;    }    /**     * Adds a Stamp to your document. Move over the stamp and a tooltip is shown     * @param writer     * @param rect     * @param contents     * @param name     * @return A PdfAnnotation     */    public static PdfAnnotation createStamp(PdfWriter writer, Rectangle rect, String contents, String name) {        PdfAnnotation annot = new PdfAnnotation(writer, rect);        annot.put(PdfName.SUBTYPE, PdfName.STAMP);        annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));        annot.put(PdfName.NAME, new PdfName(name));        return annot;    }    public static PdfAnnotation createInk(PdfWriter writer, Rectangle rect, String contents, float inkList[][]) {        PdfAnnotation annot = new PdfAnnotation(writer, rect);        annot.put(PdfName.SUBTYPE, PdfName.INK);        annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));        PdfArray outer = new PdfArray();        for (int k = 0; k < inkList.length; ++k) {            PdfArray inner = new PdfArray();            float deep[] = inkList[k];            for (int j = 0; j < deep.length; ++j)                inner.add(new PdfNumber(deep[j]));            outer.add(inner);        }        annot.put(PdfName.INKLIST, outer);        return 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));    }    /** Creates a file attachment annotation     * @param writer     * @param rect     * @param contents     * @param fs     * @return the annotation     * @throws IOException     */    public static PdfAnnotation createFileAttachment(PdfWriter writer, Rectangle rect, String contents, PdfFileSpecification fs) throws IOException {        PdfAnnotation annot = new PdfAnnotation(writer, rect);        annot.put(PdfName.SUBTYPE, PdfName.FILEATTACHMENT);        if (contents != null)            annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));        annot.put(PdfName.FS, fs.getReference());        return annot;    }        /**     * Adds a popup to your document.     * @param writer     * @param rect     * @param contents     * @param open     * @return A PdfAnnotation     */    public static PdfAnnotation createPopup(PdfWriter writer, Rectangle rect, String contents, boolean open) {        PdfAnnotation annot = new PdfAnnotation(writer, rect);        annot.put(PdfName.SUBTYPE, PdfName.POPUP);        if (contents != null)            annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));        if (open)            annot.put(PdfName.OPEN, PdfBoolean.PDFTRUE);        return annot;    }    public void setDefaultAppearanceString(PdfContentByte cb) {        byte b[] = cb.getInternalBuffer().toByteArray();        int len = b.length;        for (int k = 0; k < len; ++k) {            if (b[k] == '\n')                b[k] = 32;        }        put(PdfName.DA, new PdfString(b));    }        public void setFlags(int flags) {        if (flags == 0)            remove(PdfName.F);        else            put(PdfName.F, new PdfNumber(flags));    }        public void setBorder(PdfBorderArray border) {        put(PdfName.BORDER, border);    }    public void setBorderStyle(PdfBorderDictionary border) {        put(PdfName.BS, border);    }        /**     * 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);    }        public void setAppearance(PdfName ap, PdfTemplate template) {        PdfDictionary dic = (PdfDictionary)get(PdfName.AP);        if (dic == null)            dic = new PdfDictionary();        dic.put(ap, template.getIndirectReference());        put(PdfName.AP, dic);        if (!form)            return;        if (templates == null)            templates = new HashMap();        templates.put(template, null);    }    public void setAppearance(PdfName ap, String state, PdfTemplate template) {        PdfDictionary dicAp = (PdfDictionary)get(PdfName.AP);        if (dicAp == null)            dicAp = new PdfDictionary();        PdfDictionary dic;        PdfObject obj = dicAp.get(ap);        if (obj != null && obj.isDictionary())            dic = (PdfDictionary)obj;        else            dic = new PdfDictionary();        dic.put(new PdfName(state), template.getIndirectReference());        dicAp.put(ap, dic);        put(PdfName.AP, dicAp);        if (!form)            return;        if (templates == null)            templates = new HashMap();        templates.put(template, null);    }        public void setAppearanceState(String state) {        if (state == null) {            remove(PdfName.AS);            return;        }        put(PdfName.AS, new PdfName(state));    }        public void setColor(Color color) {        put(PdfName.C, new PdfColor(color));    }        public void setTitle(String title) {        if (title == null) {            remove(PdfName.T);            return;        }        put(PdfName.T, new PdfString(title, PdfObject.TEXT_UNICODE));    }        public void setPopup(PdfAnnotation popup) {        put(PdfName.POPUP, popup.getIndirectReference());        popup.put(PdfName.PARENT, getIndirectReference());    }        public void setAction(PdfAction action) {        put(PdfName.A, action);    }        public void setAdditionalActions(PdfName key, PdfAction action) {        PdfDictionary dic;        PdfObject obj = get(PdfName.AA);        if (obj != null && obj.isDictionary())            dic = (PdfDictionary)obj;        else            dic = new PdfDictionary();        dic.put(key, action);        put(PdfName.AA, dic);    }        /** Getter for property used.     * @return Value of property used.     */    public boolean isUsed() {        return used;    }        /** Setter for property used.     */    public void setUsed() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -