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

📄 rtfwriter.java

📁 iText是一个能够快速产生PDF文件的java类库。iText的java类对于那些要产生包含文本
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * $Id: RtfWriter.java 2752 2007-05-15 14:58:33Z blowagie $
 * $Name$
 *
 * Copyright 2001, 2002 by Mark Hall
 *
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the License.
 *
 * The Original Code is 'iText, a free JAVA-PDF library'.
 *
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
 * All Rights Reserved.
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
 *
 * Contributor(s): all the names of the contributors are added in the source code
 * where applicable.
 *
 * Alternatively, the contents of this file may be used under the terms of the
 * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
 * provisions of LGPL are applicable instead of those above.  If you wish to
 * allow use of your version of this file only under the terms of the LGPL
 * License and not to allow others to use your version of this file under
 * the MPL, indicate your decision by deleting the provisions above and
 * replace them with the notice and other provisions required by the LGPL.
 * If you do not delete the provisions above, a recipient may use your version
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the MPL as stated above or under the terms of the GNU
 * Library General Public License as published by the Free Software Foundation;
 * either version 2 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
 * details.
 *
 * If you didn't download this code from the following link, you should check if
 * you aren't using an obsolete version:
 * http://www.lowagie.com/iText/
 */

package com.lowagie.text.rtf;

import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.ListIterator;

import com.lowagie.text.Anchor;
import com.lowagie.text.Annotation;
import com.lowagie.text.Chunk;
import com.lowagie.text.DocWriter;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.Font;
import com.lowagie.text.HeaderFooter;
import com.lowagie.text.Image;
import com.lowagie.text.ListItem;
import com.lowagie.text.Meta;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.Section;
import com.lowagie.text.SimpleTable;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.codec.wmf.MetaDo;

/**
 * If you are creating a new project using the rtf part of iText, please
 * consider using the new RtfWriter2. The RtfWriter is in bug-fix-only mode,
 * will be deprecated end of 2005 and removed end of 2007.
 * 
 * A <CODE>DocWriter</CODE> class for Rich Text Files (RTF).
 * <P>
 * A <CODE>RtfWriter</CODE> can be added as a <CODE>DocListener</CODE>
 * to a certain <CODE>Document</CODE> by getting an instance.
 * Every <CODE>Element</CODE> added to the original <CODE>Document</CODE>
 * will be written to the <CODE>OutputStream</CODE> of this <CODE>RtfWriter</CODE>.
 * <P>
 * Example:
 * <BLOCKQUOTE><PRE>
 * // creation of the document with a certain size and certain margins
 * Document document = new Document(PageSize.A4, 50, 50, 50, 50);
 * try {
 *    // this will write RTF to the Standard OutputStream
 *    <STRONG>RtfWriter.getInstance(document, System.out);</STRONG>
 *    // this will write Rtf to a file called text.rtf
 *    <STRONG>RtfWriter.getInstance(document, new FileOutputStream("text.rtf"));</STRONG>
 *    // this will write Rtf to for instance the OutputStream of a HttpServletResponse-object
 *    <STRONG>RtfWriter.getInstance(document, response.getOutputStream());</STRONG>
 * }
 * catch(DocumentException de) {
 *    System.err.println(de.getMessage());
 * }
 * // this will close the document and all the OutputStreams listening to it
 * <STRONG>document.close();</CODE>
 * </PRE></BLOCKQUOTE>
 * <P>
 * <STRONG>LIMITATIONS</STRONG><BR>
 * There are currently still a few limitations on what the RTF Writer can do:
 * <ul>
 *    <li>Watermarks</li>
 *    <li>Viewer preferences</li>
 *    <li>Encryption</li>
 *    <li>Embedded fonts</li>
 *    <li>Phrases with a leading</li>
 *    <li>Lists with non-bullet symbols</li>
 *    <li>Nested tables</li>
 *    <li>Images other than JPEG and PNG</li>
 *    <li>Rotated images</li>
 * </ul>
 * <br />
 *
 * @author Mark Hall (mhall@edu.uni-klu.ac.at)
 * @author Steffen Stundzig (Steffen.Stundzig@smb-tec.com)
 * @author Eric Mattes (ericmattes@yahoo.com)
 * @author Raul Wegmann (raul.wegmann@uam.es)
 * @deprecated The RtfWriter is deprecated and will be removed from the iText library end of 2007
 */
public class RtfWriter extends DocWriter {
    /**
     * Static Constants
     */

    /**
     * General
     */

    /** This is the escape character which introduces RTF tags. */
    public static final byte escape = (byte) '\\';

    /** This is another escape character which introduces RTF tags. */
    private static final byte[] extendedEscape = "\\*\\".getBytes();

    /** This is the delimiter between RTF tags and normal text. */
    protected static final byte delimiter = (byte) ' ';

    /** This is another delimiter between RTF tags and normal text. */
    private static final byte commaDelimiter = (byte) ';';

    /** This is the character for beginning a new group. */
    public static final byte openGroup = (byte) '{';

    /** This is the character for closing a group. */
    public static final byte closeGroup = (byte) '}';

    /**
     * RTF Information
     */

    /** RTF begin and version. */
    private static final byte[] docBegin = "rtf1".getBytes();

    /** RTF encoding. */
    private static final byte[] ansi = "ansi".getBytes();

    /** RTF encoding codepage. */
    private static final byte[] ansiCodepage = "ansicpg".getBytes();

    /**
     *Font Data
     */

    /** Begin the font table tag. */
    private static final byte[] fontTable = "fonttbl".getBytes();

    /** Font number tag. */
    protected static final byte fontNumber = (byte) 'f';

    /** Font size tag. */
    protected static final byte[] fontSize = "fs".getBytes();

    /** Font color tag. */
    protected static final byte[] fontColor = "cf".getBytes();

    /** Modern font tag. */
    private static final byte[] fontModern = "fmodern".getBytes();

    /** Swiss font tag. */
    private static final byte[] fontSwiss = "fswiss".getBytes();

    /** Roman font tag. */
    private static final byte[] fontRoman = "froman".getBytes();

    /** Tech font tag. */
    private static final byte[] fontTech = "ftech".getBytes();

    /** Font charset tag. */
    private static final byte[] fontCharset = "fcharset".getBytes();

    /** Font Courier tag. */
    private static final byte[] fontCourier = "Courier".getBytes();

    /** Font Arial tag. */
    private static final byte[] fontArial = "Arial".getBytes();

    /** Font Symbol tag. */
    private static final byte[] fontSymbol = "Symbol".getBytes();

    /** Font Times New Roman tag. */
    private static final byte[] fontTimesNewRoman = "Times New Roman".getBytes();

    /** Font Windings tag. */
    private static final byte[] fontWindings = "Windings".getBytes();

    /** Default Font. */
    private static final byte[] defaultFont = "deff".getBytes();

    /** First indent tag. */
    private static final byte[] firstIndent = "fi".getBytes();

    /** Left indent tag. */
    private static final byte[] listIndent = "li".getBytes();

    /** Right indent tag. */
    private static final byte[] rightIndent = "ri".getBytes();

    /**
     * Sections / Paragraphs
     */

    /** Reset section defaults tag. */
    private static final byte[] sectionDefaults = "sectd".getBytes();

    /** Begin new section tag. */
    private static final byte[] section = "sect".getBytes();

    /** Reset paragraph defaults tag. */
    public static final byte[] paragraphDefaults = "pard".getBytes();

    /** Begin new paragraph tag. */
    public static final byte[] paragraph = "par".getBytes();

	/** Page width of a section. */
	public static final byte[] sectionPageWidth = "pgwsxn".getBytes();

	/** Page height of a section. */
	public static final byte[] sectionPageHeight = "pghsxn".getBytes();

    /**
     * Lists
     */

    /** Begin the List Table */
    private static final byte[] listtableGroup = "listtable".getBytes();

    /** Begin the List Override Table */
    private static final byte[] listoverridetableGroup = "listoverridetable".getBytes();

    /** Begin a List definition */
    private static final byte[] listDefinition = "list".getBytes();

    /** List Template ID */
    private static final byte[] listTemplateID = "listtemplateid".getBytes();

    /** RTF Writer outputs hybrid lists */
    private static final byte[] hybridList = "hybrid".getBytes();

    /** Current List level */
    private static final byte[] listLevelDefinition = "listlevel".getBytes();

    /** Level numbering (old) */
    private static final byte[] listLevelTypeOld = "levelnfc".getBytes();

    /** Level numbering (new) */
    private static final byte[] listLevelTypeNew = "levelnfcn".getBytes();

    /** Level alignment (old) */
    private static final byte[] listLevelAlignOld = "leveljc".getBytes();

    /** Level alignment (new) */
    private static final byte[] listLevelAlignNew = "leveljcn".getBytes();

    /** Level starting number */
    private static final byte[] listLevelStartAt = "levelstartat".getBytes();

    /** Level text group */
    private static final byte[] listLevelTextDefinition = "leveltext".getBytes();

    /** Filler for Level Text Length */
    private static final byte[] listLevelTextLength = "\'0".getBytes();

    /** Level Text Numbering Style */
    private static final byte[] listLevelTextStyleNumbers = "\'00.".getBytes();

    /** Level Text Bullet Style */
    private static final byte[] listLevelTextStyleBullet = "u-3913 ?".getBytes();

    /** Level Numbers Definition */
    private static final byte[] listLevelNumbersDefinition = "levelnumbers".getBytes();

    /** Filler for Level Numbers */
    private static final byte[] listLevelNumbers = "\\'0".getBytes();

    /** Tab Stop */
    private static final byte[] tabStop = "tx".getBytes();

    /** Actual list begin */
    private static final byte[] listBegin = "ls".getBytes();

    /** Current list level */
    private static final byte[] listCurrentLevel = "ilvl".getBytes();

    /** List text group for older browsers */
    private static final byte[] listTextOld = "listtext".getBytes();

    /** Tab */
    private static final byte[] tab = "tab".getBytes();

    /** Old Bullet Style */
    private static final byte[] listBulletOld = "\'b7".getBytes();

    /** Current List ID */
    private static final byte[] listID = "listid".getBytes();

    /** List override */
    private static final byte[] listOverride = "listoverride".getBytes();

    /** Number of overrides */
    private static final byte[] listOverrideCount = "listoverridecount".getBytes();

    /**
     * Text Style
     */

    /** Bold tag. */
    protected static final byte bold = (byte) 'b';

    /** Italic tag. */
    protected static final byte italic = (byte) 'i';

    /** Underline tag. */
    protected static final byte[] underline = "ul".getBytes();

    /** Strikethrough tag. */
    protected static final byte[] strikethrough = "strike".getBytes();

    /** Text alignment left tag. */
    public static final byte[] alignLeft = "ql".getBytes();

    /** Text alignment center tag. */
    public static final byte[] alignCenter = "qc".getBytes();

    /** Text alignment right tag. */
    public static final byte[] alignRight = "qr".getBytes();

    /** Text alignment justify tag. */
    public static final byte[] alignJustify = "qj".getBytes();

    /**
     * Colors
     */

    /** Begin colour table tag. */
    private static final byte[] colorTable = "colortbl".getBytes();

⌨️ 快捷键说明

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