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


Java RtfWriter2.getInstance方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例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包/类
/**
 * 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: initDocumentFormat

import com.lowagie.text.rtf.RtfWriter2; //导入方法依赖的package包/类
/**
 * Initializes the document writer format.
 * @param document the document
 * @param outputStream the export stream
 * @param exportType the export format
 * @throws DocumentException if the document cannot be initialized or is not one of the itext supported format
 */
public static void initDocumentFormat(Document document, ByteArrayOutputStream outputStream, ExportType exportType)
    throws DocumentException {
    if (exportType == ExportType.PDF) {
        PdfWriter.getInstance(document, outputStream);
    } else if (exportType == ExportType.RTF || exportType == ExportType.DOC) {
        RtfWriter2.getInstance(document, outputStream);
    }
}
 
开发者ID:NASA-Tournament-Lab,项目名称:CoECI-OPM-Service-Credit-Redeposit-Deposit-Application,代码行数:16,代码来源:ReportHelper.java

示例13: initExport

import com.lowagie.text.rtf.RtfWriter2; //导入方法依赖的package包/类
protected void initExport() throws QueryException {
	if (!bean.isSubreport()) {
		Padding margins = bean.getReportLayout().getPagePadding();
		
		Rectangle rectangle;
		if (ReportLayout.CUSTOM.equals(bean.getReportLayout().getPageFormat())) {
			PaperSize customSize = bean.getReportLayout().getPaperSize();
			rectangle = new Rectangle(customSize.getWidthPoints(), customSize.getHeightPoints());
		} else {
			rectangle = PageSize.getRectangle(getPageFormat());
		}
		
		document = new Document(rectangle, getPoints(margins.getLeft()),
				getPoints(margins.getRight()), getPoints(margins.getTop()), getPoints(margins.getBottom()));
		if (bean.getReportLayout().getOrientation() == LANDSCAPE) {
			document.setPageSize(rectangle.rotate());
		}
		RtfWriter2 writer2 = RtfWriter2.getInstance(document, getOut());
	}
	try {
		if (!bean.isSubreport()) {
			buildHeader();
			buildFooter();
			addMetaData();
			document.open();
		}
		table = buildRtfTable(PRINT_DOCUMENT);
	} catch (DocumentException e) {
		e.printStackTrace();
		throw new QueryException(e);
	}
}
 
开发者ID:nextreports,项目名称:nextreports-engine,代码行数:33,代码来源:RtfExporter.java

示例14: exportDoc

import com.lowagie.text.rtf.RtfWriter2; //导入方法依赖的package包/类
public static void exportDoc(String fileName){  
    try {  
        Document doc = new Document();  
        RtfWriter2.getInstance(doc, new FileOutputStream(fileName));  
        // 打开文档  
        doc.open();  
        //设置页边距,上、下25.4毫米,即为72f,左、右31.8毫米,即为90f  
        doc.setMargins(90f, 90f, 72f, 72f);  

        //设置标题字体样式,粗体、二号、华文中宋  
        Font tfont = DocStyleUtils.setFontStyle("华文中宋", 22f, Font.BOLD);  
        //设置正文内容的字体样式,常规、三号、仿宋_GB2312  
        Font bfont = DocStyleUtils.setFontStyle("仿宋_GB2312", 16f, Font.NORMAL);  

        //构建标题,居中对齐,12f表示单倍行距  
        Paragraph title = DocStyleUtils.setParagraphStyle("测试Itext导出Word文档", tfont, 12f, Paragraph.ALIGN_CENTER);  
        //构建正文内容  
        StringBuffer contentSb = new StringBuffer();  
        contentSb.append("最近项目很忙,这个是项目中使用到的,所以现在总结一下,以便今后可以参考使用,");  
        contentSb.append("2011年4月27日 — 2011年5月20日,对以下技术进行使用,");  
        contentSb.append("Itext、");  
        contentSb.append("Excel、");  
        contentSb.append("Word、");  
        contentSb.append("PPT。");  

        //首行缩进2字符,行间距1.5倍行距  
        Paragraph bodyPar = DocStyleUtils.setParagraphStyle(contentSb.toString(), bfont, 32f, 18f);  
        Paragraph bodyEndPar = DocStyleUtils.setParagraphStyle("截至2011年4月28日,各种技术已经完全实现。", bfont, 32f, 18f);  
        //设置空行  
        Paragraph blankRow = new Paragraph(18f, " ", bfont);  
        Paragraph deptPar = DocStyleUtils.setParagraphStyle("(技术开发部盖章)", bfont, 12f, Paragraph.ALIGN_RIGHT);  
        Paragraph datePar = DocStyleUtils.setParagraphStyle("2011-04-30", bfont, 12f, Paragraph.ALIGN_RIGHT);  

        //向文档中添加内容  
        doc.add(title);  
        doc.add(blankRow);  
        doc.add(bodyPar);  
        doc.add(bodyEndPar);  
        doc.add(blankRow);  
        doc.add(blankRow);  
        doc.add(blankRow);  
        doc.add(deptPar);  
        doc.add(datePar);  

        //最后一定要记住关闭  
        doc.close();  

    } catch (Exception e) {  
        e.printStackTrace();  
    }  
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:52,代码来源:TestDoc.java

示例15: doGet

import com.lowagie.text.rtf.RtfWriter2; //导入方法依赖的package包/类
/**
 * Returns a PDF, RTF or HTML document.
 * 
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
    
    // we retrieve the presentationtype
    String presentationtype = request.getParameter("presentationtype");
    
    // step 1
    Document document = new Document();
    try {
        // step 2: we set the ContentType and create an instance of the corresponding Writer
        if ("pdf".equals(presentationtype)) {
            response.setContentType("application/pdf");
            PdfWriter.getInstance(document, response.getOutputStream());
        }
        else if ("html".equals(presentationtype)) {
            response.setContentType("text/html");
            HtmlWriter.getInstance(document, response.getOutputStream());
        }
        else if ("rtf".equals(presentationtype)) {
            response.setContentType("text/rtf");
            RtfWriter2.getInstance(document, response.getOutputStream());
        }
        else {
            response.sendRedirect("http://itextdocs.lowagie.com/tutorial/general/webapp/index.html#HelloWorld");
        }
        
        // step 3
        document.open();
        
        // step 4
        document.add(new Paragraph("Hello World"));
        document.add(new Paragraph(new Date().toString()));
    }
    catch(DocumentException de) {
        de.printStackTrace();
        System.err.println("document: " + de.getMessage());
    }
    
    // step 5: we close the document (the outputstream is also closed internally)
    document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:47,代码来源:HelloWorldServlet.java


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