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

📄 rtfwriter.java

📁 iText是一个能够快速产生PDF文件的java类库。iText的java类对于那些要产生包含文本
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /** Red value tag. */
    private static final byte[] colorRed = "red".getBytes();

    /** Green value tag. */
    private static final byte[] colorGreen = "green".getBytes();

    /** Blue value tag. */
    private static final byte[] colorBlue = "blue".getBytes();

    /**
     * Information Group
     */

    /** Begin the info group tag.*/
    private static final byte[] infoBegin = "info".getBytes();

    /** Author tag. */
    private static final byte[] metaAuthor = "author".getBytes();

    /** Subject tag. */
    private static final byte[] metaSubject = "subject".getBytes();

    /** Keywords tag. */
    private static final byte[] metaKeywords = "keywords".getBytes();

    /** Title tag. */
    private static final byte[] metaTitle = "title".getBytes();

    /** Producer tag. */
    private static final byte[] metaProducer = "operator".getBytes();

    /** Creation Date tag. */
    private static final byte[] metaCreationDate = "creationdate".getBytes();

    /** Year tag. */
    private static final byte[] year = "yr".getBytes();

    /** Month tag. */
    private static final byte[] month = "mo".getBytes();

    /** Day tag. */
    private static final byte[] day = "dy".getBytes();

    /** Hour tag. */
    private static final byte[] hour = "hr".getBytes();

    /** Minute tag. */
    private static final byte[] minute = "min".getBytes();

    /** Second tag. */
    private static final byte[] second = "sec".getBytes();

    /** Start superscript. */
    private static final byte[] startSuper = "super".getBytes();

    /** Start subscript. */
    private static final byte[] startSub = "sub".getBytes();

    /** End super/sub script. */
    private static final byte[] endSuperSub = "nosupersub".getBytes();

    /**
     * Header / Footer
     */

    /** Title Page tag */
    private static final byte[] titlePage = "titlepg".getBytes();

    /** Facing pages tag */
    private static final byte[] facingPages = "facingp".getBytes();

    /** Begin header group tag. */
    private static final byte[] headerBegin = "header".getBytes();

    /** Begin footer group tag. */
    private static final byte[] footerBegin = "footer".getBytes();

    // header footer 'left', 'right', 'first'
    private static final byte[] headerlBegin = "headerl".getBytes();

    private static final byte[] footerlBegin = "footerl".getBytes();

    private static final byte[] headerrBegin = "headerr".getBytes();

    private static final byte[] footerrBegin = "footerr".getBytes();

    private static final byte[] headerfBegin = "headerf".getBytes();

    private static final byte[] footerfBegin = "footerf".getBytes();

    /**
     * Paper Properties
     */

    /** Paper width tag. */
    private static final byte[] rtfPaperWidth = "paperw".getBytes();

    /** Paper height tag. */
    private static final byte[] rtfPaperHeight = "paperh".getBytes();

    /** Margin left tag. */
    private static final byte[] rtfMarginLeft = "margl".getBytes();

    /** Margin right tag. */
    private static final byte[] rtfMarginRight = "margr".getBytes();

    /** Margin top tag. */
    private static final byte[] rtfMarginTop = "margt".getBytes();

    /** Margin bottom tag. */
    private static final byte[] rtfMarginBottom = "margb".getBytes();

    /** New Page tag. */
    private static final byte[] newPage = "page".getBytes();

    /** Document Landscape tag 1. */
    private static final byte[] landscapeTag1 = "landscape".getBytes();

    /** Document Landscape tag 2. */
    private static final byte[] landscapeTag2 = "lndscpsxn".getBytes();

    /**
     * Annotations
     */

    /** Annotation ID tag. */
    private static final byte[] annotationID = "atnid".getBytes();

    /** Annotation Author tag. */
    private static final byte[] annotationAuthor = "atnauthor".getBytes();

    /** Annotation text tag. */
    private static final byte[] annotation = "annotation".getBytes();

    /**
     * Images
     */

    /** Begin the main Picture group tag */
    private static final byte[] pictureGroup = "shppict".getBytes();

    /** Begin the picture tag */
    private static final byte[] picture = "pict".getBytes();

    /** PNG Image */
    private static final byte[] picturePNG = "pngblip".getBytes();

    /** JPEG Image */
    private static final byte[] pictureJPEG = "jpegblip".getBytes();

    /** BMP Image */
    private static final byte[] pictureBMP = "dibitmap0".getBytes();

    /** WMF Image */
    private static final byte[] pictureWMF = "wmetafile8".getBytes();

    /** Picture width */
    private static final byte[] pictureWidth = "picw".getBytes();

    /** Picture height */
    private static final byte[] pictureHeight = "pich".getBytes();

    /** Picture scale horizontal percent */
    private static final byte[] pictureScaleX = "picscalex".getBytes();

    /** Picture scale vertical percent */
    private static final byte[] pictureScaleY = "picscaley".getBytes();

    /**
     * Fields (for page numbering)
     */

    /** Begin field tag */
    protected static final byte[] field = "field".getBytes();

    /** Content fo the field */
    protected static final byte[] fieldContent = "fldinst".getBytes();

    /** PAGE numbers */
    protected static final byte[] fieldPage = "PAGE".getBytes();

    /** HYPERLINK field */
    protected static final byte[] fieldHyperlink = "HYPERLINK".getBytes();

    /** Last page number (not used) */
    protected static final byte[] fieldDisplay = "fldrslt".getBytes();


    /** Class variables */

    /**
     * Because of the way RTF works and the way itext works, the text has to be
     * stored and is only written to the actual OutputStream at the end.
     */

    /** This <code>ArrayList</code> contains all fonts used in the document. */
    private ArrayList fontList = new ArrayList();

    /** This <code>ArrayList</code> contains all colours used in the document. */
    private ArrayList colorList = new ArrayList();

    /** This <code>ByteArrayOutputStream</code> contains the main body of the document. */
    private ByteArrayOutputStream content = null;

    /** This <code>ByteArrayOutputStream</code> contains the information group. */
    private ByteArrayOutputStream info = null;

    /** This <code>ByteArrayOutputStream</code> contains the list table. */
    private ByteArrayOutputStream listtable = null;

    /** This <code>ByteArrayOutputStream</code> contains the list override table. */
    private ByteArrayOutputStream listoverride = null;

    /** Document header. */
    private HeaderFooter header = null;

    /** Document footer. */
    private HeaderFooter footer = null;

    /** Left margin. */
    private int marginLeft = 1800;

    /** Right margin. */
    private int marginRight = 1800;

    /** Top margin. */
    private int marginTop = 1440;

    /** Bottom margin. */
    private int marginBottom = 1440;

    /** Page width. */
    private int pageWidth = 11906;

    /** Page height. */
    private int pageHeight = 16838;

    /** Factor to use when converting. */
    public final static double TWIPSFACTOR = 20;//20.57140;

    /** Current list ID. */
    private int currentListID = 1;

    /** List of current Lists. */
    private ArrayList listIds = null;

    /** Current List Level. */
    private int listLevel = 0;

    /** Current maximum List Level. */
    private int maxListLevel = 0;

    /** Write a TOC */
    private boolean writeTOC = false;

    /** Special title page */
    private boolean hasTitlePage = false;

    /** Currently writing either Header or Footer */
    private boolean inHeaderFooter = false;

    /** Currently writing a Table */
    private boolean inTable = false;

    /** Landscape or Portrait Document */
    private boolean landscape = false;

    /** Protected Constructor */

    /**
     * Constructs a <CODE>RtfWriter</CODE>.
     *
     * @param doc         The <CODE>Document</CODE> that is to be written as RTF
     * @param os          The <CODE>OutputStream</CODE> the writer has to write to.
     */

    protected RtfWriter(Document doc, OutputStream os) {
        super(doc, os);
        document.addDocListener(this);
        initDefaults();
    }

    /** Public functions special to the RtfWriter */

    /**
     * This method controls whether TOC entries are automatically generated
     *
     * @param writeTOC    boolean value indicating whether a TOC is to be generated
     */
    public void setGenerateTOCEntries(boolean writeTOC) {
        this.writeTOC = writeTOC;
    }

    /**
     * Gets the current setting of writeTOC
     *
     * @return    boolean value indicating whether a TOC is being generated
     */
    public boolean getGeneratingTOCEntries() {
        return writeTOC;
    }

    /**
     * This method controls whether the first page is a title page
     *
     * @param hasTitlePage    boolean value indicating whether the first page is a title page
     */
    public void setHasTitlePage(boolean hasTitlePage) {
        this.hasTitlePage = hasTitlePage;
    }

    /**
     * Gets the current setting of hasTitlePage
     *
     * @return    boolean value indicating whether the first page is a title page
     */
    public boolean getHasTitlePage() {
        return hasTitlePage;
    }

    /**
     * Explicitly sets the page format to use.
     * Otherwise the RtfWriter will try to guess the format by comparing pagewidth and pageheight
     *
     * @param landscape boolean value indicating whether we are using landscape format or not
     */
    public void setLandscape(boolean landscape) {
        this.landscape = landscape;
    }

    /**
     * Returns the current landscape setting
     *
     * @return boolean value indicating the current page format
     */
    public boolean getLandscape() {
        return landscape;
    }

    /** Public functions from the DocWriter Interface */

    /**
     * Gets an instance of the <CODE>RtfWriter</CODE>.
     *
     * @param document    The <CODE>Document</CODE> that has to be written
     * @param os  The <CODE>OutputStream</CODE> the writer has to write to.
     * @return    a new <CODE>RtfWriter</CODE>
     */
    public static RtfWriter getInstance(Document document, OutputStream os) {
        return new RtfWriter(document, os);
    }

    /**
     * Signals that the <CODE>Document</CODE> has been opened and that
     * <CODE>Elements</CODE> can be added.
     */
    public void open() {
        super.open();
    }

    /**
     * Signals that the <CODE>Document</CODE> was closed and that no other
     * <CODE>Elements</CODE> will be added.
     * <p>
     * The content of the font table, color table, information group, content, header, footer are merged into the final
     * <code>OutputStream</code>
     */
    public void close() {
        if (open) {
            writeDocument();
            super.close();
        }
    }

    /**
     * Adds the footer to the bottom of the <CODE>Document</CODE>.
     * @param footer

⌨️ 快捷键说明

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