Beispiel #1
0
        public void Write(RtfWriter writer, Stream str)
        {
            writer.writeInitialFontSignature(str, this);
            byte[] tmp = System.Text.ASCIIEncoding.ASCII.GetBytes(RtfWriter.filterSpecialChar(content.ToString()));
            str.Write(tmp, 0, tmp.Length);
            writer.writeFinishingFontSignature(str, this);

            if (addTOCAsTOCEntry)
            {
                RtfTOCEntry entry = new RtfTOCEntry(entryName, entryFont);
                entry.HideText();
                try {
                    writer.Add(entry);
                } catch (DocumentException de) {
                    Console.WriteLine(de.StackTrace);
                    throw new RuntimeException("underlying " + de.Message);
                }
            }

            // line break after headline
            str.WriteByte(RtfWriter.escape);
            str.Write(RtfWriter.paragraph, 0, RtfWriter.paragraph.Length);
            str.WriteByte(RtfWriter.delimiter);

            // toc field entry
            str.WriteByte(RtfWriter.openGroup);
            str.WriteByte(RtfWriter.escape);
            str.Write(RtfWriter.field, 0, RtfWriter.field.Length);
            // field initialization stuff
            str.WriteByte(RtfWriter.openGroup);
            str.WriteByte(RtfWriter.escape);
            str.Write(RtfWriter.fieldContent, 0, RtfWriter.fieldContent.Length);
            str.WriteByte(RtfWriter.delimiter);
            str.Write(ASCIIEncoding.ASCII.GetBytes("TOC"), 0, ASCIIEncoding.ASCII.GetBytes("TOC").Length);
            // create the TOC based on the 'toc entries'
            str.WriteByte(RtfWriter.delimiter);
            str.WriteByte(RtfWriter.escape);
            str.WriteByte(RtfWriter.escape);
            str.Write(ASCIIEncoding.ASCII.GetBytes("f"), 0, ASCIIEncoding.ASCII.GetBytes("f").Length);
            str.WriteByte(RtfWriter.delimiter);
            // create Hyperlink TOC Entrie
            str.WriteByte(RtfWriter.escape);
            str.WriteByte(RtfWriter.escape);
            str.Write(ASCIIEncoding.ASCII.GetBytes("h"), 0, ASCIIEncoding.ASCII.GetBytes("h").Length);
            str.WriteByte(RtfWriter.delimiter);
            // create the TOC based on the paragraph level
            str.WriteByte(RtfWriter.delimiter);
            str.WriteByte(RtfWriter.escape);
            str.WriteByte(RtfWriter.escape);
            str.Write(ASCIIEncoding.ASCII.GetBytes("u"), 0, ASCIIEncoding.ASCII.GetBytes("u").Length);
            str.WriteByte(RtfWriter.delimiter);
            // create the TOC based on the paragraph headlines 1-5
            str.WriteByte(RtfWriter.delimiter);
            str.WriteByte(RtfWriter.escape);
            str.WriteByte(RtfWriter.escape);
            str.Write(ASCIIEncoding.ASCII.GetBytes("o"), 0, ASCIIEncoding.ASCII.GetBytes("o").Length);
            str.WriteByte(RtfWriter.delimiter);
            str.Write(ASCIIEncoding.ASCII.GetBytes("\"1-5\""), 0, ASCIIEncoding.ASCII.GetBytes("\"1-5\"").Length);
            str.WriteByte(RtfWriter.delimiter);
            str.WriteByte(RtfWriter.closeGroup);

            // field default result stuff
            str.WriteByte(RtfWriter.openGroup);
            str.WriteByte(RtfWriter.escape);
            str.Write(RtfWriter.fieldDisplay, 0, RtfWriter.fieldDisplay.Length);
            str.WriteByte(RtfWriter.delimiter);
            str.Write(ASCIIEncoding.ASCII.GetBytes(defaultText), 0, ASCIIEncoding.ASCII.GetBytes(defaultText).Length);
            str.WriteByte(RtfWriter.delimiter);
            str.WriteByte(RtfWriter.closeGroup);
            str.WriteByte(RtfWriter.closeGroup);
        }
Beispiel #2
0
        /**
         * @see com.lowagie.text.rtf.RtfField#write(com.lowagie.text.rtf.RtfWriter, java.io.Stream)
         */
        public void Write(RtfWriter writer, Stream outp)
        {
            writer.WriteInitialFontSignature(outp, this);
            byte[] t = DocWriter.GetISOBytes(RtfWriter.FilterSpecialChar(Content, true));
            outp.Write(t, 0, t.Length);
            writer.WriteFinishingFontSignature(outp, this);

            if (addTOCAsTOCEntry)
            {
                RtfTOCEntry entry = new RtfTOCEntry(entryName, entryFont);
                entry.HideText();
                writer.Add(entry);
            }

            // line break after headline
            outp.WriteByte(RtfWriter.escape);
            outp.Write(RtfWriter.paragraph, 0, RtfWriter.paragraph.Length);
            outp.WriteByte(RtfWriter.delimiter);

            // toc field entry
            outp.WriteByte(RtfWriter.openGroup);
            outp.WriteByte(RtfWriter.escape);
            outp.Write(RtfWriter.field, 0, RtfWriter.field.Length);
            // field initialization stuff
            outp.WriteByte(RtfWriter.openGroup);
            outp.WriteByte(RtfWriter.escape);
            outp.Write(RtfWriter.fieldContent, 0, RtfWriter.fieldContent.Length);
            outp.WriteByte(RtfWriter.delimiter);
            t = DocWriter.GetISOBytes("TOC");
            outp.Write(t, 0, t.Length);
            // create the TOC based on the 'toc entries'
            outp.WriteByte(RtfWriter.delimiter);
            outp.WriteByte(RtfWriter.escape);
            outp.WriteByte(RtfWriter.escape);
            outp.WriteByte((byte)'f');
            outp.WriteByte(RtfWriter.delimiter);
            // create Hyperlink TOC Entrie
            outp.WriteByte(RtfWriter.escape);
            outp.WriteByte(RtfWriter.escape);
            outp.WriteByte((byte)'h');
            outp.WriteByte(RtfWriter.delimiter);
            // create the TOC based on the paragraph level
            outp.WriteByte(RtfWriter.delimiter);
            outp.WriteByte(RtfWriter.escape);
            outp.WriteByte(RtfWriter.escape);
            outp.WriteByte((byte)'u');
            outp.WriteByte(RtfWriter.delimiter);
            // create the TOC based on the paragraph headlines 1-5
            outp.WriteByte(RtfWriter.delimiter);
            outp.WriteByte(RtfWriter.escape);
            outp.WriteByte(RtfWriter.escape);
            outp.WriteByte((byte)'o');
            outp.WriteByte(RtfWriter.delimiter);
            t = DocWriter.GetISOBytes("\"1-5\"");
            outp.Write(t, 0, t.Length);
            outp.WriteByte(RtfWriter.delimiter);
            outp.WriteByte(RtfWriter.closeGroup);

            // field default result stuff
            outp.WriteByte(RtfWriter.openGroup);
            outp.WriteByte(RtfWriter.escape);
            outp.Write(RtfWriter.fieldDisplay, 0, RtfWriter.fieldDisplay.Length);
            outp.WriteByte(RtfWriter.delimiter);
            t = DocWriter.GetISOBytes(defaultText);
            outp.Write(t, 0, t.Length);
            outp.WriteByte(RtfWriter.delimiter);
            outp.WriteByte(RtfWriter.closeGroup);
            outp.WriteByte(RtfWriter.closeGroup);
        }