I have also found that settings made through RtfParagraphStyle are not
reflected in
the actual TOC of the final document in Word. The example below demonstrates
the
problem. I define 2 TOC RtfParagraphStyles: MYTOC1 and MYTOC2. When I open the
generated doc in Word these 2 styles are listed as registered paragraph styles
but are
not used in the generated TOC.
_______________________________________________________________________
package com.dave;
import java.awt.Color;
import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.rtf.RtfWriter2;
import com.lowagie.text.rtf.field.RtfTOCEntry;
import com.lowagie.text.rtf.field.RtfTableOfContents;
import com.lowagie.text.rtf.style.RtfFont;
import com.lowagie.text.rtf.style.RtfParagraphStyle;
public class TOCTest {
/**
* @param args
*/
public static void main(String[] args) {
try {
Document document = new Document(PageSize.LETTER, 50,
50, 50,
50);
RtfWriter2 rtfWriter = RtfWriter2.getInstance(document,
new FileOutputStream("TOCTest.rtf"));
RtfFont header1Font = new RtfFont("Arial", 16,
Font.BOLD,
Color.BLACK);
RtfFont header2Font = new RtfFont("Arial", 14,
Font.BOLD,
Color.BLACK);
RtfFont mainFont = new RtfFont("Arial", 12,
Font.NORMAL,
Color.BLACK);
RtfParagraphStyle myToc1 = new RtfParagraphStyle
("MYTOC1", "Arial", 14, Font.BOLD, Color.RED);
RtfParagraphStyle myToc2 = new RtfParagraphStyle
("MYTOC2", "Arial", 12, Font.NORMAL, Color.GREEN);
myToc2.setIndentLeft(20);
rtfWriter.getDocumentSettings().registerParagraphStyle(myToc1);
rtfWriter.getDocumentSettings().registerParagraphStyle(myToc2);
document.open();
document.add(new Paragraph("Table of Contents",
header1Font));
document.add(Chunk.NEWLINE);
Paragraph para = new Paragraph();
para.add(new RtfTableOfContents("RIGHT CLICK HERE AND
SELECT
\"UPDATE FIELD\" TO UPDATE.", header2Font));
document.add(para);
document.add(Chunk.NEXTPAGE);
String title = "Header One";
document.add(new RtfTOCEntry(title, myToc1));
document.add(new Paragraph(title, header1Font));
document.add(Chunk.NEWLINE);
title = "Section 1.1";
document.add(new RtfTOCEntry(title, myToc2));
document.add(new Paragraph(title, header2Font));
document.add(Chunk.NEWLINE);
String body = "Text for section 1.1.";
document.add(new Paragraph(body, mainFont));
document.add(Chunk.NEWLINE);
title = "Section 1.2";
document.add(new RtfTOCEntry(title, myToc2));
document.add(new Paragraph(title, header2Font));
document.add(Chunk.NEWLINE);
body = "Text for section 1.2.";
document.add(new Paragraph(body, mainFont));
document.add(Chunk.NEWLINE);
document.add(Chunk.NEXTPAGE);
title = "Header Two";
document.add(new RtfTOCEntry(title, myToc1));
document.add(new Paragraph(title, header1Font));
document.add(Chunk.NEWLINE);
title = "Section 2.1";
document.add(new RtfTOCEntry(title, myToc2));
document.add(new Paragraph(title, header2Font));
document.add(Chunk.NEWLINE);
body = "Text for section 2.1.";
document.add(new Paragraph(body, mainFont));
document.add(Chunk.NEWLINE);
title = "Section 2.2";
document.add(new RtfTOCEntry(title, myToc2));
document.add(new Paragraph(title, header2Font));
document.add(Chunk.NEWLINE);
body = "Text for section 2.2.";
document.add(new Paragraph(body, mainFont));
document.add(Chunk.NEWLINE);
document.close();
} catch(Exception e){
System.out.println("Exception: " + e.getMessage());
}
}
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions