use of com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup in project itext2 by albfernandez.
the class RtfDocumentHeader method writeSectionDefinition.
/**
* Writes the section definition data
* @param result
*/
public void writeSectionDefinition(final OutputStream result) {
try {
RtfHeaderFooterGroup header = convertHeaderFooter(this.header, RtfHeaderFooter.TYPE_HEADER);
RtfHeaderFooterGroup footer = convertHeaderFooter(this.footer, RtfHeaderFooter.TYPE_FOOTER);
if (header.hasTitlePage() || footer.hasTitlePage()) {
result.write(TITLE_PAGE);
header.setHasTitlePage();
footer.setHasTitlePage();
}
if (header.hasFacingPages() || footer.hasFacingPages()) {
result.write(FACING_PAGES);
header.setHasFacingPages();
footer.setHasFacingPages();
}
footer.writeContent(result);
header.writeContent(result);
pageSetting.writeSectionDefinition(result);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
use of com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup in project itext2 by albfernandez.
the class RtfTest method main.
/**
* Creates 1 RTF file.
*/
@Test
public void main() throws Exception {
Document doc = new Document();
RtfWriter2 writer2 = RtfWriter2.getInstance(doc, PdfTestBase.getOutputStream("testNew.rtf"));
writer2.setAutogenerateTOCEntries(true);
Table headerTable = new Table(3);
headerTable.addCell("Test Cell 1");
headerTable.addCell("Test Cell 2");
headerTable.addCell("Test Cell 3");
HeaderFooter header = new RtfHeaderFooter(headerTable);
RtfHeaderFooterGroup footer = new RtfHeaderFooterGroup();
footer.setHeaderFooter(new RtfHeaderFooter(new Phrase("This is the footer on the title page")), com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_FIRST_PAGE);
footer.setHeaderFooter(new RtfHeaderFooter(new Phrase("This is a left side page")), com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_LEFT_PAGES);
footer.setHeaderFooter(new RtfHeaderFooter(new Phrase("This is a right side page")), com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_RIGHT_PAGES);
doc.setHeader(header);
doc.setFooter(footer);
doc.open();
Paragraph p = new Paragraph();
p.add(new RtfTableOfContents("UPDATE ME!"));
doc.add(p);
p = new Paragraph("", new RtfFont("Staccato222 BT"));
p.add(new Chunk("Hello! "));
p.add(new Chunk("How do you do?"));
doc.add(p);
p.setAlignment(Element.ALIGN_RIGHT);
doc.add(p);
Anchor a = new Anchor("http://www.uni-klu.ac.at");
a.setReference("http://www.uni-klu.ac.at");
doc.add(a);
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "pngnow.png");
doc.add(new Chunk(img, 0, 0));
doc.add(new Annotation("Mark", "This works!"));
Chunk c = new Chunk("");
c.setNewPage();
doc.add(c);
List subList = new List(true, 40);
subList.add(new ListItem("Sub list 1"));
subList.add(new ListItem("Sub list 2"));
List list = new List(true, 20);
list.add(new ListItem("Test line 1"));
list.add(new ListItem("Test line 2 - This is a really long test line to test that linebreaks are working the way they are supposed to work so a really really long line of drivel is required"));
list.add(subList);
list.add(new ListItem("Test line 3 - \t\u20ac\t 60,-"));
doc.add(list);
list = new List(false, 20);
list.add(new ListItem("Bullet"));
list.add(new ListItem("Another one"));
doc.add(list);
doc.newPage();
Chapter chapter = new Chapter(new Paragraph("This is a Chapter"), 1);
chapter.add(new Paragraph("This is some text that belongs to this chapter."));
chapter.add(new Paragraph("A second paragraph. What a surprise."));
Section section = chapter.addSection(new Paragraph("This is a subsection"));
section.add(new Paragraph("Text in the subsection."));
doc.add(chapter);
com.lowagie.text.rtf.field.RtfTOCEntry rtfTOC = new com.lowagie.text.rtf.field.RtfTOCEntry("Table Test");
doc.add(rtfTOC);
Table table = new Table(3);
table.setPadding(2);
table.setAlignment(Element.ALIGN_LEFT);
table.setSpacing(2);
Cell emptyCell = new Cell("");
Cell cellLeft = new Cell("Left Alignment");
cellLeft.setHorizontalAlignment(Element.ALIGN_LEFT);
Cell cellCenter = new Cell("Center Alignment");
cellCenter.setHorizontalAlignment(Element.ALIGN_CENTER);
Cell cellRight = new Cell("Right Alignment");
cellRight.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cellLeft);
table.addCell(cellCenter);
table.addCell(cellRight);
Cell cellSpanHoriz = new Cell("This Cell spans two columns");
cellSpanHoriz.setColspan(2);
table.addCell(cellSpanHoriz);
table.addCell(emptyCell);
Cell cellSpanVert = new Cell("This Cell spans two rows");
cellSpanVert.setRowspan(2);
table.addCell(emptyCell);
table.addCell(cellSpanVert);
table.addCell(emptyCell);
table.addCell(emptyCell);
table.addCell(emptyCell);
Cell cellSpanHorizVert = new Cell("This Cell spans both two columns and two rows");
cellSpanHorizVert.setColspan(2);
cellSpanHorizVert.setRowspan(2);
table.addCell(emptyCell);
table.addCell(cellSpanHorizVert);
table.addCell(emptyCell);
RtfCell cellDotted = new RtfCell("Dotted border");
cellDotted.setBorders(new RtfBorderGroup(Rectangle.BOX, RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0)));
RtfCell cellEmbossed = new RtfCell("Embossed border");
cellEmbossed.setBorders(new RtfBorderGroup(Rectangle.BOX, RtfBorder.BORDER_EMBOSS, 1, new Color(0, 0, 0)));
RtfCell cellNoBorder = new RtfCell("No border");
cellNoBorder.setBorders(new RtfBorderGroup());
table.addCell(cellDotted);
table.addCell(cellEmbossed);
table.addCell(cellNoBorder);
doc.add(table);
for (int i = 0; i < 300; i++) {
doc.add(new Paragraph("Dummy line to get multi-page document. Line " + (i + 1)));
}
doc.close();
}
use of com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup in project itext2 by albfernandez.
the class MultipleHeaderFooterTest method main.
/**
* Extended font example.
*/
@Test
public void main() throws Exception {
Document document = new Document();
RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("MultipleHeaderFooter.rtf"));
// Create the Paragraph that will be used in the header.
Paragraph date = new Paragraph("01.01.2010");
date.setAlignment(Element.ALIGN_CENTER);
// Create the RtfHeaderFooterGroup for the header.
// To display the same header on both pages, but not the
// title page set them to left and right pages explicitly.
RtfHeaderFooterGroup header = new RtfHeaderFooterGroup();
header.setHeaderFooter(new RtfHeaderFooter(date), RtfHeaderFooter.DISPLAY_LEFT_PAGES);
header.setHeaderFooter(new RtfHeaderFooter(date), RtfHeaderFooter.DISPLAY_RIGHT_PAGES);
// Set the header
document.setHeader(header);
// Create the paragraphs that will be used as footers
Paragraph titleFooter = new Paragraph("Multiple headers / footers example");
titleFooter.setAlignment(Element.ALIGN_CENTER);
Paragraph leftFooter = new Paragraph("Page ");
leftFooter.add(new RtfPageNumber());
Paragraph rightFooter = new Paragraph("Page ");
rightFooter.add(new RtfPageNumber());
rightFooter.setAlignment(Element.ALIGN_RIGHT);
// Create the RtfHeaderGroup for the footer and set the footers
// at the desired positions
RtfHeaderFooterGroup footer = new RtfHeaderFooterGroup();
footer.setHeaderFooter(new RtfHeaderFooter(titleFooter), RtfHeaderFooter.DISPLAY_FIRST_PAGE);
footer.setHeaderFooter(new RtfHeaderFooter(leftFooter), RtfHeaderFooter.DISPLAY_LEFT_PAGES);
footer.setHeaderFooter(new RtfHeaderFooter(rightFooter), RtfHeaderFooter.DISPLAY_RIGHT_PAGES);
// Set the document footer
document.setFooter(footer);
document.open();
document.add(new Paragraph("This document has headers and footers created" + " using the RtfHeaderFooterGroup class.\n\n"));
// Add some content, so that the different headers / footers show up.
for (int i = 0; i < 300; i++) {
document.add(new Paragraph("Just a bit of content so that the headers become visible."));
}
document.close();
}
use of com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup in project itext2 by albfernandez.
the class RtfDocumentHeader method init.
/**
* initializes the RtfDocumentHeader.
*/
protected void init() {
this.codePage = new RtfCodePage(this.document);
this.colorList = new RtfColorList(this.document);
this.fontList = new RtfFontList(this.document);
this.listTable = new RtfListTable(this.document);
this.stylesheetList = new RtfStylesheetList(this.document);
this.infoGroup = new RtfInfoGroup(this.document);
this.protectionSetting = new RtfProtectionSetting(this.document);
this.pageSetting = new RtfPageSetting(this.document);
this.header = new RtfHeaderFooterGroup(this.document, RtfHeaderFooter.TYPE_HEADER);
this.footer = new RtfHeaderFooterGroup(this.document, RtfHeaderFooter.TYPE_FOOTER);
this.generator = new RtfGenerator(this.document);
}
Aggregations