当前位置: 首页>>代码示例>>Java>>正文


Java Document.setHeader方法代码示例

本文整理汇总了Java中com.lowagie.text.Document.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Java Document.setHeader方法的具体用法?Java Document.setHeader怎么用?Java Document.setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.lowagie.text.Document的用法示例。


在下文中一共展示了Document.setHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * 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();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:35,代码来源:TotalPageNumberTest.java

示例2: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * 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();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:48,代码来源:ExtendedHeaderFooterTest.java

示例3: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * 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();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:57,代码来源:MultipleHeaderFooterTest.java


注:本文中的com.lowagie.text.Document.setHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。