📄 rtfwriter.java
字号:
/** * $Id: RtfWriter.java,v 1.9 2001/12/03 14:16:15 blowagie Exp $ * $Name: $ * * Copyright 2001 by Mark Hall * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as published * by the Free Software Foundation; either versioni 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. * */package com.lowagie.text.rtf;import com.lowagie.text.*;import java.io.*;import java.util.*;import java.awt.Color;import java.text.SimpleDateFormat;import java.text.ParsePosition;/** * 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>Only PNG / JPEG Images are supported.</LI> * <LI>Rotating of Images is not supported.</LI> * <LI>Only one Header and one Footer are possible.</LI> * <LI>Nested Tables are not supported.</LI> * <LI>The <CODE>Leading</CODE> is not supported.</LI> * </UL> */public class RtfWriter extends DocWriter implements DocListener{ /** * 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. */ private 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. */ private static final byte fontNumber = (byte) 'f'; /** Font size tag. */ private static final byte[] fontSize = "fs".getBytes(); /** Font color tag. */ private 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(); /** List indent tag. */ private static final byte[] listIndent = "li".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(); /** * 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. */ private static final byte bold = (byte) 'b'; /** Italic tag. */ private static final byte italic = (byte) 'i'; /** Underline tag. */ private static final byte[] underline = "ul".getBytes(); /** Strikethrough tag. */ private static final byte[] strikethrough = "strike".getBytes(); /** Text alignment left tag. */ private static final byte[] alignLeft = "ql".getBytes(); /** Text alignment center tag. */ private static final byte[] alignCenter = "qc".getBytes(); /** Text alignment right tag. */ private static final byte[] alignRight = "qr".getBytes(); /** Text alignment justify tag. */ private static final byte[] alignJustify = "qj".getBytes(); /** * Colors */ /** Begin colour table tag. */ private static final byte[] colorTable = "colortbl".getBytes(); /** 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(); /** * Header / Footer */ /** Begin header group tag. */ private static final byte[] headerBegin = "header".getBytes(); /** Begin footer group tag. */ private static final byte[] footerBegin = "footer".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(); /** * 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(); /** Picture width */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -