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

📄 pdfannotation.java

📁 Java生成PDF Java生成PDF Java生成PDF
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public PDFPage getPage()    {        return (PDFPage)PeeredObject.getPeer(annot.getPage());    }    /**     * Set the page for this annotation. This is useful when     * moving annotations between documents or across pages - when     * simply adding a new annotation to a page, this method is     * identical to calling {@link PDFPage#addAnnotation}     * @since 1.1.23     */    public void setPage(PDFPage page)    {	annot.setPage(page.page);    }    /**     * Set whether the annotation is visible on screen. By default, all new     * annotations are visible     * @param screen whether the annotation should be displayed on the screen     * @param print whether the annotation should be printed     * @since 1.1.23     */    public void setVisible(boolean visible)    {	annot.setVisible(visible);    }    /**     * Set whether the annotation is included when the document is printed. By     * default, all new annotations are printed.     * @param screen whether the annotation should be displayed on the screen     * @param print whether the annotation should be printed     * @since 1.1.23     */    public void setPrintable(boolean printable)    {	annot.setPrintable(printable);    }    /**     * Returns whether the annotation is visible on the     * screen (true) or not (false)     * @since 1.1.23     */    public boolean isVisible()    {	return annot.isVisible();    }    /**     * Returns whether the annotation is included when the document     * is printed (true) or not (false)     * @since 1.1.23     */    public boolean isPrintable()    {	return annot.isPrintable();    }    /**     * Set the color of the annotation.     * <ul>     * <li>For <b>link</b> annotations, this is the color of the border around the     * annotation (assuming the border is on)</li>     * <li>For <b>text</b> annotations, this is color of the icon and highlights on     * the popup window</li>     * </ul>     */    public void setColor(Color c)    {	if (annot instanceof org.faceless.pdf2.AnnotationLink) {	    if (c==null) {		((org.faceless.pdf2.AnnotationLink)annot).setStyle(null);	    } else {		org.faceless.pdf2.PDFStyle style = new org.faceless.pdf2.PDFStyle();		style.setLineColor(c);		((org.faceless.pdf2.AnnotationLink)annot).setStyle(style);	    }	} else if (annot instanceof org.faceless.pdf2.AnnotationNote) {	    ((org.faceless.pdf2.AnnotationNote)annot).setType(((org.faceless.pdf2.AnnotationNote)annot).getType(), c);	}    }    /**     * For a link annotation, set the action that the annotation refers to.     * If this method is invoked on a non-link annotation it has no effect.     * Since 1.1.23, passing in a null action removes the action completely.     */    public void setAction(PDFAction action)    {	if (annot instanceof org.faceless.pdf2.AnnotationLink) {	    ((org.faceless.pdf2.AnnotationLink)annot).setAction(action==null ? null : action.action);	}    }    /**     * For a link annotation, get the action that the annotation refers to.     * If this method is invoked on a non-link annotation, null is returned.     */    public PDFAction getAction()    {	if (annot instanceof org.faceless.pdf2.AnnotationLink) {	    return (PDFAction)PeeredObject.getPeer(((org.faceless.pdf2.AnnotationLink)annot).getAction());	} else if (annot instanceof org.faceless.pdf2.WidgetAnnotation) {	    return (PDFAction)PeeredObject.getPeer(((org.faceless.pdf2.WidgetAnnotation)annot).getAction(org.faceless.pdf2.Event.CLICK));	} else {	    return null;	}    }    /**     * For a text or stamp annotation, set the contents of the annotation.     * The string may contain newlines.     * @since 1.1.12     */    public void setTextAnnotationContents(String contents)    {	if (annot instanceof org.faceless.pdf2.AnnotationNote) {	    ((org.faceless.pdf2.AnnotationNote)annot).setContents(contents);	} else if (annot instanceof org.faceless.pdf2.AnnotationStamp) {	    ((org.faceless.pdf2.AnnotationStamp)annot).setContents(contents);	}    }    /**     * For a text or stamp annotation, get the contents of the annotation.     * For other types of annotation, this returns <code>null</code>     * @return the content of the text annotation or <tt>null</tt>     * @since 1.1.12     */    public String getTextAnnotationContents()    {	if (annot instanceof org.faceless.pdf2.AnnotationNote) {	    return ((org.faceless.pdf2.AnnotationNote)annot).getContents();	} else if (annot instanceof org.faceless.pdf2.AnnotationStamp) {	    return ((org.faceless.pdf2.AnnotationStamp)annot).getContents();	} else {	    return null;	}    }    /**     * For a text annotation, set the label of the annotation. This     * is also used in Acrobat to represent the "author" of an     * annotation, and as such may be used on any type of annotation.     * The specified value may contain non-ASCII Unicode characters     * @since 1.1.12     */    public void setTextAnnotationLabel(String label)    {	if (annot instanceof org.faceless.pdf2.AnnotationNote) {	    ((org.faceless.pdf2.AnnotationNote)annot).setAuthor(label);	}    }    /**     * For a text annotation, get the label of the annotation. This     * is also used in Acrobat to represent the "author" of an     * annotation, and as such may be used on any type of annotation.     * @return the label/author of the annotation or <tt>null</tt>     * @since 1.1.12     */    public String getTextAnnotationLabel()    {	if (annot instanceof org.faceless.pdf2.AnnotationNote) {	    return ((org.faceless.pdf2.AnnotationNote)annot).getAuthor();	} else {	    return null;	}    }    /**     * Return the date when the annotation was last modified if     * specified, or <code>null</code> otherwise.     * @since 1.1.23     */    public Calendar getLastModified()    {        return annot.getModifyDate();    }    /**     * <p>     * Set an action to occur when the specified event happens to     * this annotation. These event actions are only used for annotations     * created by form elements - those returned from {@link FormElement#getAnnotations}.     * </p><p>     * The event can be one of {@link #EVENT_ONCLICK},     * {@link #EVENT_ONMOUSEOVER}, {@link #EVENT_ONMOUSEOUT},     * {@link #EVENT_ONMOUSEDOWN}, {@link #EVENT_ONMOUSEUP},     * {@link #EVENT_ONFOCUS}, {@link #EVENT_ONBLUR}, {@link #EVENT_ONCHANGE},     * {@link #EVENT_ONKEYPRESS} or {@link #EVENT_ONFORMAT} - although not     * every event type is applicable for every type of form element.     * </p>     * @param event the event the action applies to     * @param action the action you wish to occur, or <code>null</code> to remove the action     * @since 1.1.23     * @see FormElement     */    public void setEventAction(int event, PDFAction action)    {	org.faceless.pdf2.Event newevent=null;	if (annot instanceof org.faceless.pdf2.WidgetAnnotation) {	    if (event==EVENT_ONCLICK) newevent=org.faceless.pdf2.Event.CLICK;	    else if (event==EVENT_ONMOUSEOVER) newevent=org.faceless.pdf2.Event.MOUSEOVER;	    else if (event==EVENT_ONMOUSEOUT) newevent=org.faceless.pdf2.Event.MOUSEOUT;	    else if (event==EVENT_ONMOUSEDOWN) newevent=org.faceless.pdf2.Event.MOUSEDOWN;	    else if (event==EVENT_ONMOUSEUP) newevent=org.faceless.pdf2.Event.MOUSEUP;	    else if (event==EVENT_ONBLUR) newevent=org.faceless.pdf2.Event.BLUR;	    else if (event==EVENT_ONFOCUS) newevent=org.faceless.pdf2.Event.FOCUS;	    else if (event==EVENT_ONCHANGE) newevent=org.faceless.pdf2.Event.CHANGE;	    else if (event==EVENT_ONFORMAT) newevent=org.faceless.pdf2.Event.FORMAT;	    else if (event==EVENT_ONKEYPRESS) newevent=org.faceless.pdf2.Event.KEYPRESS;	    else if (event==EVENT_ONOTHERCHANGE) newevent=org.faceless.pdf2.Event.OTHERCHANGE;	    if (newevent!=null) {		if (event==EVENT_ONKEYPRESS || event==EVENT_ONFORMAT || event==EVENT_ONCHANGE || event==EVENT_ONOTHERCHANGE) {		    ((org.faceless.pdf2.WidgetAnnotation)annot).getField().setAction(newevent, action==null ? null : action.action);		} else {		    ((org.faceless.pdf2.WidgetAnnotation)annot).setAction(newevent, action==null ? null : action.action);		}	    }	}    }    /**     * Return the action that occurs when the specified event happens to     * this annotation. This is only used with annotations returned from     * form fields via the {@link FormElement#getAnnotations} method.     * @param the event you want the action for - one of the events listed in {@link #setEventAction}     * @return the action for that event, or <code>null</code> if no action is specified     * @since 1.1.23     * @see FormElement     */    public PDFAction getEventAction(int event)    {	if (annot instanceof org.faceless.pdf2.WidgetAnnotation) {	    org.faceless.pdf2.Event newevent=null;	    if (event==EVENT_ONCLICK) newevent=org.faceless.pdf2.Event.CLICK;	    else if (event==EVENT_ONMOUSEOVER) newevent=org.faceless.pdf2.Event.MOUSEOVER;	    else if (event==EVENT_ONMOUSEOUT) newevent=org.faceless.pdf2.Event.MOUSEOUT;	    else if (event==EVENT_ONMOUSEDOWN) newevent=org.faceless.pdf2.Event.MOUSEDOWN;	    else if (event==EVENT_ONMOUSEUP) newevent=org.faceless.pdf2.Event.MOUSEUP;	    else if (event==EVENT_ONBLUR) newevent=org.faceless.pdf2.Event.BLUR;	    else if (event==EVENT_ONFOCUS) newevent=org.faceless.pdf2.Event.FOCUS;	    else if (event==EVENT_ONCHANGE) newevent=org.faceless.pdf2.Event.CHANGE;	    else if (event==EVENT_ONFORMAT) newevent=org.faceless.pdf2.Event.FORMAT;	    else if (event==EVENT_ONKEYPRESS) newevent=org.faceless.pdf2.Event.KEYPRESS;	    else if (event==EVENT_ONOTHERCHANGE) newevent=org.faceless.pdf2.Event.OTHERCHANGE;	    if (newevent!=null) {		if (event==EVENT_ONKEYPRESS || event==EVENT_ONFORMAT || event==EVENT_ONCHANGE || event==EVENT_ONOTHERCHANGE) {		    return (PDFAction)PeeredObject.getPeer(((org.faceless.pdf2.WidgetAnnotation)annot).getField().getAction(newevent));		} else {		    return (PDFAction)PeeredObject.getPeer(((org.faceless.pdf2.WidgetAnnotation)annot).getAction(newevent));		}	    } else {		return null;	    }	} else {	    return null;	}    }    public String toString()    {        String out = "<annotation type=\""+getType()+"\" rect=\"";	float[] f = getRectangle();	out+=f[0]+","+f[1]+","+f[2]+","+f[3]+"\"";	if (getType().equals("Text")) {	    out+=" label=\""+getTextAnnotationLabel()+"\" content=\""+getTextAnnotationContents()+"\"";	} else if (getType().equals("Widget")) {	    String n = ((org.faceless.pdf2.WidgetAnnotation)annot).getValue();	    if (n!=null) {	        out+=" value=\""+n+"\"";	    }	}	if (!isVisible()) out+=" visible=\"false\"";	if (!isPrintable()) out+=" printable=\"false\"";	if (getAction()!=null) {	    out+=" action=\""+getAction()+"\"";	}	String[] triggers = { "E","X","D","U","Fo","Bl","V","K","F","C" };	for (int i=0;i<triggers.length;i++) {	    final String[] names = { "onMouseOver", "onMouseOut", "onMouseDown", "onMouseUp", "onFocus", "onBlur", "onChange", "onKeyPress", "onFormat", "onOtherChange" };	    PDFAction a = getEventAction(i);	    if (a!=null) {	       out+=" "+names[i]+"=\""+a+"\"";	    }	}	return out+"/>";    }}

⌨️ 快捷键说明

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