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


Java RtfWriter2类代码示例

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


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

示例1: main

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
/**
 * Extended font example.
 * 
 * 
 */
@Test
public void main() throws Exception {
	Document document = new Document();
	RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ExtendedFont.rtf"));
	document.open();

	// Create a RtfFont with the desired font name.
	RtfFont msComicSans = new RtfFont("Comic Sans MS");

	// Use the RtfFont like any other Font.
	document.add(new Paragraph("This paragraph uses the" + " Comic Sans MS font.", msComicSans));

	// Font size, font style and font colour can also be specified.
	RtfFont bigBoldGreenArial = new RtfFont("Arial", 36, Font.BOLD, Color.GREEN);

	document.add(new Paragraph("This is a really big bold green Arial text", bigBoldGreenArial));
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:24,代码来源:ExtendedFontTest.java

示例2: createDoc

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
public void createDoc() throws FileNotFoundException{
	 /** 创建Document对象(word文档)  */
       Rectangle rectPageSize = new Rectangle(PageSize.A4);
       rectPageSize = rectPageSize.rotate();
       // 创建word文档,并设置纸张的大小
       doc = new Document(PageSize.A4);
       file=new File(path+docFileName);
       fileOutputStream=new FileOutputStream(file);
       /** 建立一个书写器与document对象关联,通过书写器可以将文档写入到输出流中 */
       RtfWriter2.getInstance(doc, fileOutputStream );
       doc.open();
       //设置页边距,上、下25.4毫米,即为72f,左、右31.8毫米,即为90f  
       doc.setMargins(90f, 90f, 72f, 72f);
       //设置标题字体样式,粗体、二号、华文中宋  
       tfont  = DocStyleUtils.setFontStyle("华文中宋", 22f, Font.BOLD);  
       //设置正文内容的字体样式,常规、三号、仿宋_GB2312  
       bfont = DocStyleUtils.setFontStyle("仿宋_GB2312", 16f, Font.NORMAL);
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:19,代码来源:DocExportUtil.java

示例3: main

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
/**
 * Document settings example.
 * 
 * 
 */
@Test
public void main() throws Exception {
	Document document = new Document();

	// Keep a reference to the RtfWriter2 instance.
	RtfWriter2 writer2 = RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("DocumentSettings.rtf"));

	// Specify that the document caching is to be done on disk.
	writer2.getDocumentSettings().setDataCacheStyle(RtfDataCache.CACHE_DISK);

	// Specify that all \n are translated into soft linebreaks.
	writer2.getDocumentSettings().setAlwaysGenerateSoftLinebreaks(true);

	document.open();
	document.add(new Paragraph("This example has been cached on disk\nand all "
			+ "\\n have been translated into soft linebreaks."));
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:24,代码来源:DocumentSettingsTest.java

示例4: main

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
/**
 * Tab stops in paragraphs.
 * 
 * 
 */
@Test
public void main() throws Exception {
	Document document = new Document();
	RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("BasicTabs.rtf"));

	document.open();

	// Define the Paragraph to add tab stops to
	Paragraph par = new Paragraph();

	// Add the tab stops to the paragraph
	par.add(new RtfTab(70, RtfTab.TAB_LEFT_ALIGN));
	par.add(new RtfTab(400, RtfTab.TAB_RIGHT_ALIGN));

	// Add the text to the paragraph, placing the tab stops with \t
	par.add("\tFirst the text on the left-hand side\tThis text is right aligned.");

	document.add(par);

	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:27,代码来源:BasicTabsTest.java

示例5: main

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
/**
 * Demonstrates setting text into an RTF drawing object.
 * 
 * 
 */
@Test
public void main() throws Exception {
	Document document = new Document();
	RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("DrawingText.rtf"));

	document.open();

	// Create a new rectangle RtfShape.
	RtfShapePosition position = new RtfShapePosition(1000, 1000, 3000, 2000);
	RtfShape shape = new RtfShape(RtfShape.SHAPE_RECTANGLE, position);

	// Set the text to display in the drawing object
	shape.setShapeText("This text will appear in the drawing object.");

	document.add(shape);

	document.close();

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

示例6: printRtf

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
public void printRtf()throws IOException, DocumentException{
	//create an input stream from the rtf string bytes
	byte[] rtfBytes = handler.getOBXResult(0, 0).getBytes();
	ByteArrayInputStream rtfStream = new ByteArrayInputStream(rtfBytes);
	
	//create & open the document we are going to write to and its writer
	document = new Document();
	RtfWriter2 writer = RtfWriter2.getInstance(document,os);
	document.setPageSize(PageSize.LETTER);
	document.addTitle("Title of the Document");
	document.addCreator("OSCAR");
	document.open();
	
    //Create the fonts that we are going to use
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, 11, Font.NORMAL);
    boldFont = new Font(bf, 12, Font.BOLD);
 //   redFont = new Font(bf, 11, Font.NORMAL, Color.RED);
    
    //add the patient information
    addRtfPatientInfo();
    
    //add the results
	writer.importRtfDocument(rtfStream, null);
	
	document.close();
	os.flush();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:29,代码来源:LabPDFCreator.java

示例7: main

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
/**
 * Hello World! example
 * 
 */
@Test
public void main() throws Exception {
	// Step 1: Create a new Document
	Document document = new Document();

	// Step 2: Create a new instance of the RtfWriter2 with the document
	// and target output stream.
	RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("HelloWorld.rtf"));

	// Step 3: Open the document.
	document.open();

	// Step 4: Add content to the document.
	document.add(new Paragraph("Hello World!"));

	// Step 5: Close the document. It will be written to the target output
	// stream.
	document.close();

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

示例8: main

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
/**
    * Changing paragraph stylesheets properties.
    * 
    * 
    */
@Test
   public void main() throws Exception {
           Document document = new Document();
           RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ChangingStylesheets.rtf"));

           // Set the default style font name. This is inherited
           // by all other styles.
           RtfParagraphStyle.STYLE_NORMAL.setFontName("Times New Roman");
           // Set the colour of the level 1 heading to blue.
           RtfParagraphStyle.STYLE_HEADING_1.setColor(Color.BLUE);
           // Set the font name of the heading back to Arial again.
           RtfParagraphStyle.STYLE_HEADING_2.setFontName("Arial");
           // Change the font size
           RtfParagraphStyle.STYLE_HEADING_2.setSize(12);

           // Change the style properties to the desired values
           // before document.open()

           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.close();

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

示例9: main

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

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

示例10: main

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的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

示例11: main

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
/**
 * Demonstrates setting the horizontal and vertical anchors for a drawing
 * object
 * 
 * 
 */
@Test
public void main() throws Exception {
	Document document = new Document();
	RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("DrawingAnchor.rtf"));

	document.open();

	document.add(new Paragraph("This text is above the horizontal rule"));

	// Construct a new RtfShapePosition that covers the whole page
	// horizontally
	RtfShapePosition position = new RtfShapePosition(150, 0, 10400, 150);

	// The horizontal position is relative to the margins of the page
	position.setXRelativePos(RtfShapePosition.POSITION_X_RELATIVE_MARGIN);

	// The vertical position is relative to the paragraph
	position.setYRelativePos(RtfShapePosition.POSITION_Y_RELATIVE_PARAGRAPH);

	// Create a new line drawing object
	RtfShape shape = new RtfShape(RtfShape.SHAPE_LINE, position);

	// Add the shape to the paragraph, so that it is anchored to the
	// correct paragraph
	Paragraph par = new Paragraph();
	par.add(shape);
	document.add(par);

	document.add(new Paragraph("This text is below the horizontal rule"));

	document.close();

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

示例12: main

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
/**
 * Demonstrates creating freeform drawing objects
 * 
 * 
 */
@Test
public void main() throws Exception {
	Document document = new Document();
	RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("DrawingFreeform.rtf"));

	document.open();

	// Create a new rectangle RtfShape using the SHAPE_FREEFORM constant.
	RtfShapePosition position = new RtfShapePosition(1000, 1000, 4000, 4000);
	RtfShape shape = new RtfShape(RtfShape.SHAPE_FREEFORM, position);

	// Set the bottom and right extents of the drawing object.
	shape.setProperty(new RtfShapeProperty(RtfShapeProperty.PROPERTY_GEO_RIGHT, 3000));
	shape.setProperty(new RtfShapeProperty(RtfShapeProperty.PROPERTY_GEO_BOTTOM, 3000));

	// Define the vertices that make up the drawing object.
	// This list draws a basic table shape.
	shape.setProperty(new RtfShapeProperty(RtfShapeProperty.PROPERTY_VERTICIES, new Point[] { new Point(100, 100),
			new Point(2900, 100), new Point(2900, 200), new Point(2600, 200), new Point(2600, 1500),
			new Point(2520, 1500), new Point(2520, 200), new Point(480, 200), new Point(480, 1500),
			new Point(400, 1500), new Point(400, 200), new Point(100, 200) }));

	// A nice red Table :-)
	shape.setProperty(new RtfShapeProperty(RtfShapeProperty.PROPERTY_FILL_COLOR, Color.red));

	document.add(shape);

	document.close();

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

示例13: main

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的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

示例14: main

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
/**
    * Extended font styles example.
    * 
    * 
    */
@Test
   public void main() throws Exception {
           Document document = new Document();
           RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ExtendedFontStyles.rtf"));
           document.open();
           
           // Use the RtfFont.STYLE_* instead of the Font styles.
           RtfFont doubleStrikethrough = new RtfFont("Arial", RtfFont.UNDEFINED,
                   RtfFont.STYLE_DOUBLE_STRIKETHROUGH);
           RtfFont shadow = new RtfFont("Arial", RtfFont.UNDEFINED,
                   RtfFont.STYLE_SHADOW);
           
           // Or combine them with Font styles.
           RtfFont engravedItalic = new RtfFont("Arial", RtfFont.UNDEFINED,
                   RtfFont.STYLE_ENGRAVED | Font.ITALIC);
           
           // The hidden style is special since it hides text.
           RtfFont hidden = new RtfFont("Arial", RtfFont.UNDEFINED,
                   RtfFont.STYLE_HIDDEN);
           
           Paragraph paragraph = new Paragraph("This text is ", new RtfFont("Arial", 12));
           
           // Use the RtfFonts when creating the text.
           paragraph.add(new Chunk("deleted,", doubleStrikethrough));
           paragraph.add(new Chunk(" shady,", shadow));
           paragraph.add(new Chunk(" engraved and italic", engravedItalic));
           paragraph.add(" and");
           paragraph.add(new Chunk(" you won't see this", hidden));
           paragraph.add(" nothing.");
           
           document.add(paragraph);
           document.close();
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:39,代码来源:ExtendedFontStylesTest.java

示例15: createWriter

import com.lowagie.text.rtf.RtfWriter2; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:javamelody,项目名称:javamelody,代码行数:40,代码来源:MRtfWriter.java


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