Java 类com.lowagie.text.rtf.headerfooter.RtfHeaderFooter 实例源码

项目:itext2    文件:RtfDocumentHeader.java   
/**
 * 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();
    }       
}
项目:itext2    文件:RtfDocumentHeader.java   
/**
 * 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);
}
项目:itext2    文件:RtfDocumentHeader.java   
/**
 * Converts a HeaderFooter into a RtfHeaderFooterGroup. Depending on which class
 * the HeaderFooter is, the correct RtfHeaderFooterGroup is created.
 * 
 * @param hf The HeaderFooter to convert.
 * @param type Whether the conversion is being done on a footer or header
 * @return The converted RtfHeaderFooterGroup.
 * @see com.lowagie.text.rtf.headerfooter.RtfHeaderFooter
 * @see com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup
 */
private RtfHeaderFooterGroup convertHeaderFooter(HeaderFooter hf, int type) {
    if(hf != null) {
        if(hf instanceof RtfHeaderFooterGroup) {
            return new RtfHeaderFooterGroup(this.document, (RtfHeaderFooterGroup) hf, type);
        } else if(hf instanceof RtfHeaderFooter) {
            return new RtfHeaderFooterGroup(this.document, (RtfHeaderFooter) hf, type);
        } else {
            return new RtfHeaderFooterGroup(this.document, hf, type);
        }
    } else {
        return new RtfHeaderFooterGroup(this.document, type);
    }
}
项目:itext2    文件:PageNumberTest.java   
/**
 * Demonstrates creating a footer with the current page number
 * 
 * 
 */
@Test
public void main() throws Exception {
    Document document = new Document();
    RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("PageNumber.rtf"));

    // Create a new Paragraph for the footer
    Paragraph par = new Paragraph("Page ");
    par.setAlignment(Element.ALIGN_RIGHT);

    // Add the RtfPageNumber to the Paragraph
    par.add(new RtfPageNumber());

    // Create an RtfHeaderFooter with the Paragraph and set it
    // as a footer for the document
    RtfHeaderFooter footer = new RtfHeaderFooter(par);
    document.setFooter(footer);

    document.open();

    for (int i = 1; i <= 300; i++) {
        document.add(new Paragraph("Line " + i + "."));
    }

    document.close();

}
项目:itext2    文件:TotalPageNumberTest.java   
/**
 * Demonstrates creating a header with page number and total number of pages
 * 
 * 
 */
@Test
public void main() throws Exception {
    Document document = new Document();
    RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("TotalPageNumber.rtf"));

    // Create a new Paragraph for the footer
    Paragraph par = new Paragraph("Page ");

    // Add the RtfPageNumber to the Paragraph
    par.add(new RtfPageNumber());

    // Add the RtfTotalPageNumber to the Paragraph
    par.add(" of ");
    par.add(new RtfTotalPageNumber());

    // Create an RtfHeaderFooter with the Paragraph and set it
    // as a header for the document
    RtfHeaderFooter header = new RtfHeaderFooter(par);
    document.setHeader(header);

    document.open();

    for (int i = 1; i <= 300; i++) {
        document.add(new Paragraph("Line " + i + "."));
    }

    document.close();

}
项目:itext2    文件:ExtendedHeaderFooterTest.java   
/**
 * Extended headers / footers example
 * 
 * 
 */
@Test
public void main() throws Exception {
    Document document = new Document();
    RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ExtendedHeaderFooter.rtf"));

    // Create the Paragraphs that will be used in the header.
    Paragraph date = new Paragraph("01.01.2010");
    date.setAlignment(Paragraph.ALIGN_RIGHT);
    Paragraph address = new Paragraph("TheFirm\nTheRoad 24, TheCity\n" + "+00 99 11 22 33 44");

    // Create the RtfHeaderFooter with an array containing the Paragraphs to
    // add
    RtfHeaderFooter header = new RtfHeaderFooter(new Element[] { date, address });

    // Set the header
    document.setHeader(header);

    // Create the table that will be used as the footer
    Table footer = new Table(2);
    footer.setBorder(0);
    footer.getDefaultCell().setBorder(0);
    footer.setWidth(100);
    footer.addCell(new Cell("(c) Mark Hall"));
    Paragraph pageNumber = new Paragraph("Page ");

    // The RtfPageNumber is an RTF specific element that adds a page number
    // field
    pageNumber.add(new RtfPageNumber());
    pageNumber.setAlignment(Paragraph.ALIGN_RIGHT);
    footer.addCell(new Cell(pageNumber));

    // Create the RtfHeaderFooter and set it as the footer to use
    document.setFooter(new RtfHeaderFooter(footer));

    document.open();

    document.add(new Paragraph("This document has headers and footers created"
            + " using the RtfHeaderFooter class."));

    document.close();

}
项目:javamelody    文件:MRtfWriter.java   
/**
 * We create a writer that listens to the document and directs a RTF-stream to out
 *
 * @param table
 *           MBasicTable
 * @param document
 *           Document
 * @param out
 *           OutputStream
 * @return DocWriter
 */
@Override
protected DocWriter createWriter(final MBasicTable table, final Document document,
        final OutputStream out) {
    final RtfWriter2 writer = RtfWriter2.getInstance(document, out);

    // title
    final String title = buildTitle(table);
    if (title != null) {
        final HeaderFooter header = new RtfHeaderFooter(new Paragraph(title));
        header.setAlignment(Element.ALIGN_LEFT);
        header.setBorder(Rectangle.NO_BORDER);
        document.setHeader(header);
        document.addTitle(title);
    }

    // advanced page numbers : x/y
    final Paragraph footerParagraph = new Paragraph();
    final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
    footerParagraph.add(new RtfPageNumber(font));
    footerParagraph.add(new Phrase(" / ", font));
    footerParagraph.add(new RtfTotalPageNumber(font));
    footerParagraph.setAlignment(Element.ALIGN_CENTER);
    final HeaderFooter footer = new RtfHeaderFooter(footerParagraph);
    footer.setBorder(Rectangle.TOP);
    document.setFooter(footer);

    return writer;
}
项目:nextreports-engine    文件:RtfExporter.java   
private void buildHeader() throws DocumentException, QueryException {
    header = buildRtfTable(PRINT_PAGE_HEADER);
    if (header == null) {
        return;
    }
    printPageHeaderBand();
    HeaderFooter hf = new RtfHeaderFooter(header);
    document.setHeader(hf);
}
项目:nextreports-engine    文件:RtfExporter.java   
private void buildFooter() throws DocumentException, QueryException {
    footer = buildRtfTable(PRINT_PAGE_FOOTER);
    if (footer == null) {
        return;
    }
    printPageFooterBand();
    RtfHeaderFooterGroup footerGroup = new RtfHeaderFooterGroup();
    RtfHeaderFooter hf = new RtfHeaderFooter(footer);
    footerGroup.setHeaderFooter(hf, RtfHeaderFooter.DISPLAY_ALL_PAGES);
    document.setFooter(footerGroup);
}
项目:itext2    文件:MultipleHeaderFooterTest.java   
/**
 * 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();

}