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


Java Document.setMargins方法代码示例

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


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

示例1: createDoc

import com.lowagie.text.Document; //导入方法依赖的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: testTableSpacingPercentage

import com.lowagie.text.Document; //导入方法依赖的package包/类
@Test
public void testTableSpacingPercentage() throws FileNotFoundException,
		DocumentException {
	Document document = PdfTestBase
			.createPdf("testTableSpacingPercentage.pdf");
	document.setMargins(72, 72, 72, 72);
	document.open();
	PdfPTable table = new PdfPTable(1);
	table.setSpacingBefore(20);
	table.setWidthPercentage(100);
	PdfPCell cell;
	cell = new PdfPCell();
	Phrase phase = new Phrase("John Doe");
	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // This has no
														// effect
	cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // This has no effect
	cell.addElement(phase);
	table.addCell(cell);
	document.add(table);
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:22,代码来源:TablePdfTest.java

示例3: main

import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
 * Creates a PDF document with different pages that have different margins.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A5, 36, 72, 108, 180);

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file

	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Margins.pdf"));

	// step 3: we open the document
	document.open();

	// step 4:
	document.add(new Paragraph(
			"The left margin of this document is 36pt (0.5 inch); the right margin 72pt (1 inch); the top margin 108pt (1.5 inch); the bottom margin 180pt (2.5 inch). "));
	Paragraph paragraph = new Paragraph();
	paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
	for (int i = 0; i < 20; i++) {
		paragraph.add("Hello World, Hello Sun, Hello Moon, Hello Stars, Hello Sea, Hello Land, Hello People. ");
	}
	document.add(paragraph);
	document.setMargins(180, 108, 72, 36);
	document.add(new Paragraph("Now we change the margins. You will see the effect on the next page."));
	document.add(paragraph);
	document.setMarginMirroring(true);
	document.add(new Paragraph("Starting on the next page, the margins will be mirrored."));
	document.add(paragraph);

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:38,代码来源:MarginsTest.java

示例4: exportDoc

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

示例5: generateReport

import com.lowagie.text.Document; //导入方法依赖的package包/类
public void generateReport(OutputStream os) throws Exception  {
	Document d = new Document (PageSize.A4.rotate());
	d.setMargins(20, 20, 20, 20);
	PdfWriter writer = PdfWriterFactory.newInstance(d, os, FontSettings.HELVETICA_10PT);
	// PdfWriter writer = PdfWriter.getInstance (d, os);
	writer.setStrictImageSequence(true);
	d.open ();

	//header
	Paragraph p = new Paragraph("Individual Need Rating Over Time",titleFont);
	p.setAlignment(Element.ALIGN_CENTER);
	d.add(p);
	d.add(Chunk.NEWLINE);

	//purpose
	Paragraph purpose = new Paragraph();
	purpose.add(new Chunk("Purpose of Report:",boldText));
	purpose.add(new Phrase("The purpose of this report is to show change over time in a specific Need Rating for an individual Consumer. It adds up the number of needs across all Domains grouped by Need Rating (e.g. Unmet Needs, Met Needs, No Needs, Unknown) for all selected OCANs that were conducted with the Consumer and displays the results in an individual need rating line graph. Each line graph that is displayed compares the Consumer and the Staff's perspective. The staff may share this report with their Consumer as well.",normalText));
	d.add(purpose);
	d.add(Chunk.NEWLINE);

	//report parameters
	PdfPTable table = new PdfPTable(2);
	table.setWidthPercentage(100);
	table.getDefaultCell().setBorder(0);
	table.addCell(makeCell(createFieldNameAndValuePhrase("Consumer Name:",reportBean.getConsumerName()),Element.ALIGN_LEFT));
	table.addCell(makeCell(createFieldNameAndValuePhrase("Report Date:",dateFormatter.format(reportBean.getReportDate())),Element.ALIGN_RIGHT));
	table.addCell(makeCell(createFieldNameAndValuePhrase("Staff Name:",reportBean.getStaffName()),Element.ALIGN_LEFT));
	table.addCell("");
	d.add(table);
	d.add(Chunk.NEWLINE);

	int height = 260;

	if(reportBean.isShowUnmetNeeds()) {
		d.add(Image.getInstance(reportBean.getUnmetNeedsChart().createBufferedImage((int)PageSize.A4.rotate().getWidth()-40, height), null));
	}

	if(reportBean.isShowMetNeeds()) {
		d.add(Image.getInstance(reportBean.getMetNeedsChart().createBufferedImage((int)PageSize.A4.rotate().getWidth()-40, height), null));
	}

	if(reportBean.isShowNoNeeds()) {
		d.add(Image.getInstance(reportBean.getNoNeedsChart().createBufferedImage((int)PageSize.A4.rotate().getWidth()-40, height), null));
	}
	if(reportBean.isShowUnknownNeeds()) {
		d.add(Image.getInstance(reportBean.getUnknownNeedsChart().createBufferedImage((int)PageSize.A4.rotate().getWidth()-40, height), null));
	}




	d.close();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:55,代码来源:IndividualNeedRatingOverTimeReportGenerator.java


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