本文整理匯總了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);
}
示例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();
}
示例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();
}
示例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();
}
}
示例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