📄 document.java
字号:
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { listener = (DocListener) iterator.next(); listener.resetPageCount(); } } /** * Sets the page number. * * @param pageN * the new page number */ public void setPageCount(int pageN) { this.pageN = pageN; DocListener listener; for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { listener = (DocListener) iterator.next(); listener.setPageCount(pageN); } } /** * Returns the current page number. * * @return the current page number */ public int getPageNumber() { return this.pageN; } /** * Closes the document. * <P> * 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) { open = false; close = true; } DocListener listener; for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { listener = (DocListener) iterator.next(); listener.close(); } } // methods concerning the header or some meta information /** * Adds a user defined header to the document. * * @param name * the name of the header * @param content * the content of the header * @return <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise */ public boolean addHeader(String name, String content) { try { return add(new Header(name, content)); } catch (DocumentException de) { throw new ExceptionConverter(de); } } /** * Adds the title to a Document. * * @param title * the title * @return <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise */ public boolean addTitle(String title) { try { return add(new Meta(Element.TITLE, title)); } catch (DocumentException de) { throw new ExceptionConverter(de); } } /** * Adds the subject to a Document. * * @param subject * the subject * @return <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise */ public boolean addSubject(String subject) { try { return add(new Meta(Element.SUBJECT, subject)); } catch (DocumentException de) { throw new ExceptionConverter(de); } } /** * Adds the keywords to a Document. * * @param keywords * adds the keywords to the document * @return <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise */ public boolean addKeywords(String keywords) { try { return add(new Meta(Element.KEYWORDS, keywords)); } catch (DocumentException de) { throw new ExceptionConverter(de); } } /** * Adds the author to a Document. * * @param author * the name of the author * @return <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise */ public boolean addAuthor(String author) { try { return add(new Meta(Element.AUTHOR, author)); } catch (DocumentException de) { throw new ExceptionConverter(de); } } /** * Adds the creator to a Document. * * @param creator * the name of the creator * @return <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise */ public boolean addCreator(String creator) { try { return add(new Meta(Element.CREATOR, creator)); } catch (DocumentException de) { throw new ExceptionConverter(de); } } /** * Adds the producer to a Document. * * @return <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise */ public boolean addProducer() { try { return add(new Meta(Element.PRODUCER, "iText by lowagie.com")); } catch (DocumentException de) { throw new ExceptionConverter(de); } } /** * Adds the current date and time to a Document. * * @return <CODE>true</CODE> if successful, <CODE>false</CODE> otherwise */ public boolean addCreationDate() { try { /* bugfix by 'taqua' (Thomas) */ final SimpleDateFormat sdf = new SimpleDateFormat( "EEE MMM dd HH:mm:ss zzz yyyy"); return add(new Meta(Element.CREATIONDATE, sdf.format(new Date()))); } catch (DocumentException de) { throw new ExceptionConverter(de); } } // methods to get the layout of the document. /** * Returns the left margin. * * @return the left margin */ public float leftMargin() { return marginLeft; } /** * Return the right margin. * * @return the right margin */ public float rightMargin() { return marginRight; } /** * Returns the top margin. * * @return the top margin */ public float topMargin() { return marginTop; } /** * Returns the bottom margin. * * @return the bottom margin */ public float bottomMargin() { return marginBottom; } /** * Returns the lower left x-coordinate. * * @return the lower left x-coordinate */ public float left() { return pageSize.getLeft(marginLeft); } /** * Returns the upper right x-coordinate. * * @return the upper right x-coordinate */ public float right() { return pageSize.getRight(marginRight); } /** * Returns the upper right y-coordinate. * * @return the upper right y-coordinate */ public float top() { return pageSize.getTop(marginTop); } /** * Returns the lower left y-coordinate. * * @return the lower left y-coordinate */ public float bottom() { return pageSize.getBottom(marginBottom); } /** * Returns the lower left x-coordinate considering a given margin. * * @param margin * a margin * @return the lower left x-coordinate */ public float left(float margin) { return pageSize.getLeft(marginLeft + margin); } /** * Returns the upper right x-coordinate, considering a given margin. * * @param margin * a margin * @return the upper right x-coordinate */ public float right(float margin) { return pageSize.getRight(marginRight + margin); } /** * Returns the upper right y-coordinate, considering a given margin. * * @param margin * a margin * @return the upper right y-coordinate */ public float top(float margin) { return pageSize.getTop(marginTop + margin); } /** * Returns the lower left y-coordinate, considering a given margin. * * @param margin * a margin * @return the lower left y-coordinate */ public float bottom(float margin) { return pageSize.getBottom(marginBottom + margin); } /** * Gets the pagesize. * * @return the page size */ public Rectangle getPageSize() { return this.pageSize; } /** * Checks if the document is open. * * @return <CODE>true</CODE> if the document is open */ public boolean isOpen() { return open; } /** * Gets the iText version. * This method may only be changed by Paulo Soares and/or Bruno Lowagie. * @return iText version */ public static final String getVersion() { return ITEXT_VERSION; } /** * Adds a JavaScript onLoad function to the HTML body tag * * @param code * the JavaScript code to be executed on load of the HTML page */ public void setJavaScript_onLoad(String code) { this.javaScript_onLoad = code; } /** * Gets the JavaScript onLoad command. * * @return the JavaScript onLoad command */ public String getJavaScript_onLoad() { return this.javaScript_onLoad; } /** * Adds a JavaScript onUnLoad function to the HTML body tag * * @param code * the JavaScript code to be executed on unload of the HTML page */ public void setJavaScript_onUnLoad(String code) { this.javaScript_onUnLoad = code; } /** * Gets the JavaScript onUnLoad command. * * @return the JavaScript onUnLoad command */ public String getJavaScript_onUnLoad() { return this.javaScript_onUnLoad; } /** * Adds a style class to the HTML body tag * * @param htmlStyleClass * the style class for the HTML body tag */ public void setHtmlStyleClass(String htmlStyleClass) { this.htmlStyleClass = htmlStyleClass; } /** * Gets the style class of the HTML body tag * * @return the style class of the HTML body tag */ public String getHtmlStyleClass() { return this.htmlStyleClass; } /** * Set the margin mirroring. It will mirror margins for odd/even pages. * <p> * Note: it will not work with {@link Table}. * * @param marginMirroring * <CODE>true</CODE> to mirror the margins * @return always <CODE>true</CODE> */ public boolean setMarginMirroring(boolean marginMirroring) { this.marginMirroring = marginMirroring; DocListener listener; for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { listener = (DocListener) iterator.next(); listener.setMarginMirroring(marginMirroring); } return true; } /** * Gets the margin mirroring flag. * * @return the margin mirroring flag */ public boolean isMarginMirroring() { return marginMirroring; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -