use of com.lowagie.text.rtf.style.RtfParagraphStyle in project itext2 by albfernandez.
the class ExtendingStylesheetsTest method main.
/**
* Creation of new paragraph stylesheets.
*/
@Test
public void main() throws Exception {
Document document = new Document();
RtfWriter2 writer = RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ExtendingStylesheets.rtf"));
// Create the new RtfParagraphStyle. The second parameter is the name of
// the RtfParagraphStyle that this style will inherit default properties
// from.
RtfParagraphStyle incorrectStyle = new RtfParagraphStyle("Incorrect", "Normal");
// Change the desired properties
incorrectStyle.setColor(Color.RED);
incorrectStyle.setStyle(Font.STRIKETHRU);
// Register the new paragraph stylesheet with the RtfWriter2.
writer.getDocumentSettings().registerParagraphStyle(incorrectStyle);
// Create a new RtfParagraphStyle that does not inherit from any other
// style.
RtfParagraphStyle correctStyle = new RtfParagraphStyle("Correct", "Arial", 12, Font.NORMAL, Color.GREEN);
// Register the new paragraph stylesheet with the RtfWriter2.
writer.getDocumentSettings().registerParagraphStyle(correctStyle);
// Change the default font name. This will propagate to the paragraph
// stylesheet
// that inherits, but not the other one.
RtfParagraphStyle.STYLE_NORMAL.setFontName("Times New Roman");
document.open();
// Simply set the stylesheet you wish to use as the Font
// of the Paragraph
document.add(new Paragraph("This is a heading level 1", RtfParagraphStyle.STYLE_HEADING_1));
document.add(new Paragraph("This is a heading level 2", RtfParagraphStyle.STYLE_HEADING_2));
document.add(new Paragraph("Just some text that is formatted " + "in the default style.", RtfParagraphStyle.STYLE_NORMAL));
document.add(new Paragraph("This paragraph should be removed.", incorrectStyle));
document.add(new Paragraph("It should be replaced with this.", correctStyle));
document.close();
}
use of com.lowagie.text.rtf.style.RtfParagraphStyle in project itext2 by albfernandez.
the class TableOfContentsTest method main.
/**
* Demonstrates creating and styling a table of contents
*/
@Test
public void main() throws Exception {
Document document = new Document();
RtfWriter2 rtfWriter2 = RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("TableOfContents.rtf"));
// Create paragraph stylesheets for each heading level. They must be named
// "toc N" for each heading level you are using
RtfParagraphStyle tocLevel1Style = new RtfParagraphStyle("toc 1", "Times New Roman", 11, Font.NORMAL, Color.BLACK);
RtfParagraphStyle tocLevel2Style = new RtfParagraphStyle("toc 2", "Times New Roman", 10, Font.NORMAL, Color.BLACK);
tocLevel2Style.setIndentLeft(10);
// Register the paragraph stylesheets with the RtfWriter2
rtfWriter2.getDocumentSettings().registerParagraphStyle(tocLevel1Style);
rtfWriter2.getDocumentSettings().registerParagraphStyle(tocLevel2Style);
document.open();
// Create a Paragraph and add the table of contents to it
Paragraph par = new Paragraph();
par.add(new RtfTableOfContents("Right-click here and select \"Update\" " + "to see the table of contents."));
document.add(par);
for (int i = 1; i <= 5; i++) {
// Create a level 1 heading
document.add(new Paragraph("Heading " + i, RtfParagraphStyle.STYLE_HEADING_1));
for (int j = 1; j <= 3; j++) {
// Create a level 2 heading
document.add(new Paragraph("Heading " + i + "." + j, RtfParagraphStyle.STYLE_HEADING_2));
for (int k = 1; k <= 20; k++) {
document.add(new Paragraph("Line " + k + " in section " + i + "." + k));
}
}
}
document.close();
}
Aggregations