當前位置: 首頁>>代碼示例>>Java>>正文


Java Paragraph.setAlignment方法代碼示例

本文整理匯總了Java中com.lowagie.text.Paragraph.setAlignment方法的典型用法代碼示例。如果您正苦於以下問題:Java Paragraph.setAlignment方法的具體用法?Java Paragraph.setAlignment怎麽用?Java Paragraph.setAlignment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.lowagie.text.Paragraph的用法示例。


在下文中一共展示了Paragraph.setAlignment方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.lowagie.text.Paragraph; //導入方法依賴的package包/類
/**
    * Generates a document with a header containing Page x of y and with a Watermark on every page.
    */
@Test
public void main() throws Exception {
       	// step 1: creating the document
           Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
           // step 2: creating the writer
           PdfWriter writer = PdfWriter.getInstance(doc, PdfTestBase.getOutputStream( "pageNumbersWatermark.pdf"));
           // step 3: initialisations + opening the document
           writer.setPageEvent(new PageNumbersWatermarkTest());
           doc.open();
           // step 4: adding content
           String text = "some padding text ";
           for (int k = 0; k < 10; ++k) {
               text += text;
           }
           Paragraph p = new Paragraph(text);
           p.setAlignment(Element.ALIGN_JUSTIFIED);
           doc.add(p);
           // step 5: closing the document
           doc.close();
       
   }
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:25,代碼來源:PageNumbersWatermarkTest.java

示例2: main

import com.lowagie.text.Paragraph; //導入方法依賴的package包/類
/**
 * Space Word Ratio.
 */
@Test
public void main() throws Exception {
	// step 1
	Document document = new Document(PageSize.A4, 50, 350, 50, 50);
	// step 2
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("spacewordratio.pdf"));
	// step 3
	document.open();
	// step 4
	String text = "Flanders International Filmfestival Ghent - Internationaal Filmfestival van Vlaanderen Gent";
	Paragraph p = new Paragraph(text);
	p.setAlignment(Element.ALIGN_JUSTIFIED);
	document.add(p);
	document.newPage();
	writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
	document.add(p);

	// step 5
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:24,代碼來源:SpaceWordRatioTest.java

示例3: main

import com.lowagie.text.Paragraph; //導入方法依賴的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: newPara

import com.lowagie.text.Paragraph; //導入方法依賴的package包/類
private static Element newPara(String text, int alignment, int type) {
	Font font = FontFactory.getFont("Helvetica", 10, type, Color.BLACK);
	Paragraph p = new Paragraph(text, font);
	p.setAlignment(alignment);
	p.setLeading(font.getSize() * 1.2f);
	return p;
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:8,代碼來源:MultiColumnSimpleTest.java

示例5: main

import com.lowagie.text.Paragraph; //導入方法依賴的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

示例6: main

import com.lowagie.text.Paragraph; //導入方法依賴的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

示例7: generateTitle

import com.lowagie.text.Paragraph; //導入方法依賴的package包/類
private Paragraph generateTitle() {
    Paragraph title = new Paragraph(new Chunk(generateTitleString(), TITLE_FONT));
    title.setAlignment(Element.ALIGN_CENTER);
    return title;
}
 
開發者ID:university-information-system,項目名稱:uis,代碼行數:6,代碼來源:GradePDFView.java

示例8: setParagraphStyle

import com.lowagie.text.Paragraph; //導入方法依賴的package包/類
/** 
 * 功能說明:設置段落的樣式,設置前半截內容和後半截內容格式不一樣的段落樣式</BR> 
 * 修改日:2011-04-27 
 * @author myclover 
 * @param content  前半截內容 
 * @param font     字體的樣式 
 * @param firstLineIndent 首行縮進多少字符,16f約等於一個字符 
 * @param appendStr 後半截內容 
 * @return 
 */  
public static Paragraph setParagraphStyle(String content , Font font , float firstLineIndent , String appendStr){  
    Paragraph par = setParagraphStyle(content, font, 0f, 12f);  
    Phrase phrase = new Phrase();  
    phrase.add(par);  
    phrase.add(appendStr);  
    Paragraph paragraph = new Paragraph(phrase);  
    paragraph.setFirstLineIndent(firstLineIndent);  
    //設置對齊方式為兩端對齊  
    paragraph.setAlignment(Paragraph.ALIGN_JUSTIFIED_ALL);  
    return paragraph;  
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:22,代碼來源:DocStyleUtils.java

示例9: RtfHeaderFooter

import com.lowagie.text.Paragraph; //導入方法依賴的package包/類
/**
 * Constructs a RtfHeaderFooter based on a HeaderFooter with a certain type and displayAt
 * location. For internal use only.
 * 
 * @param doc The RtfDocument this RtfHeaderFooter belongs to
 * @param headerFooter The HeaderFooter to base this RtfHeaderFooter on
 * @param type The type of RtfHeaderFooter
 * @param displayAt The display location of this RtfHeaderFooter
 */
protected RtfHeaderFooter(RtfDocument doc, HeaderFooter headerFooter, int type, int displayAt) {
    super(new Phrase(""), false);
    this.document = doc;
    this.type = type;
    this.displayAt = displayAt;
    Paragraph par = new Paragraph();
    par.setAlignment(headerFooter.alignment());
    if (headerFooter.getBefore() != null) {
        par.add(headerFooter.getBefore());
    }
    if (headerFooter.isNumbered()) {
        par.add(new RtfPageNumber(this.document));
    }
    if (headerFooter.getAfter() != null) {
        par.add(headerFooter.getAfter());
    }
    try {
        this.content = new Object[1];
        if(this.document != null) {
            this.content[0] = this.document.getMapper().mapElement(par)[0];
            ((RtfBasicElement) this.content[0]).setInHeader(true);
        } else {
            this.content[0] = par;
        }
    } catch(DocumentException de) {
        de.printStackTrace();
    }
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:38,代碼來源:RtfHeaderFooter.java

示例10: getParagraph

import com.lowagie.text.Paragraph; //導入方法依賴的package包/類
/**
 * Creates a Paragraph object based on a list of properties.
 * @param attributes
 * @return a Paragraph
 */
public static Paragraph getParagraph(Properties attributes) {
	Paragraph paragraph = new Paragraph(getPhrase(attributes));
	String value;
	value = attributes.getProperty(ElementTags.ALIGN);
	if (value != null) {
		paragraph.setAlignment(value);
	}
	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		paragraph.setIndentationLeft(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		paragraph.setIndentationRight(Float.parseFloat(value + "f"));
	}
	return paragraph;
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:23,代碼來源:ElementFactory.java

示例11: main

import com.lowagie.text.Paragraph; //導入方法依賴的package包/類
/**
    * PdfTemplates can be wrapped in an Image.
    */
@Test
   public  void main() throws Exception {
       
           
       // step 1: creation of a document-object
       Rectangle rect = new Rectangle(PageSize.A4);
       rect.setBackgroundColor(new Color(238, 221, 88));
       Document document = new Document(rect, 50, 50, 50, 50);
	// step 2: we create a writer that listens to the document
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("templateImages.pdf"));
	// step 3: we open the document
	document.open();
	// step 4:
	PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
	BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
			BaseFont.NOT_EMBEDDED);
	String text = "Vertical";
	float size = 16;
	float width = bf.getWidthPoint(text, size);
	template.beginText();
	template.setRGBColorFillF(1, 1, 1);
	template.setFontAndSize(bf, size);
	template.setTextMatrix(0, 2);
	template.showText(text);
	template.endText();
	template.setWidth(width);
	template.setHeight(size + 2);
	template.sanityCheck();
	Image img = Image.getInstance(template);
	img.setRotationDegrees(90);
	Chunk ck = new Chunk(img, 0, 0);
	PdfPTable table = new PdfPTable(3);
	table.setWidthPercentage(100);
	table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
	table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
	PdfPCell cell = new PdfPCell(img);
	cell.setPadding(4);
	cell.setBackgroundColor(new Color(0, 0, 255));
	cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");
	table.addCell(cell);
	table.addCell("I see a template everywhere");
	table.addCell(cell);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");

	Paragraph p1 = new Paragraph("This is a template ");
	p1.add(ck);
	p1.add(" just here.");
	p1.setLeading(img.getScaledHeight() * 1.1f);
	document.add(p1);
	document.add(table);
	Paragraph p2 = new Paragraph("More templates ");
	p2.setLeading(img.getScaledHeight() * 1.1f);
	p2.setAlignment(Element.ALIGN_JUSTIFIED);
	img.scalePercent(70);
	for (int k = 0; k < 20; ++k)
		p2.add(ck);
	document.add(p2);
	// step 5: we close the document
	document.close();

   }
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:70,代碼來源:TemplateImagesTest.java

示例12: main

import com.lowagie.text.Paragraph; //導入方法依賴的package包/類
/**
 * Generates a StudentCard
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Rectangle rect = new Rectangle(243, 153);
	rect.setBackgroundColor(new Color(0xFF, 0xFF, 0xCC));
	Document document = new Document(rect, 10, 10, 10, 10);

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("studentcard.pdf"));

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

	// step 4:
	Font font = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, Color.BLUE);
	Paragraph p = new Paragraph("Ghent University", font);
	p.setAlignment(Element.ALIGN_CENTER);
	document.add(p);
	PdfContentByte cb = writer.getDirectContent();
	Font f = FontFactory.getFont(FontFactory.HELVETICA, 8);
	PdfPTable outertable = new PdfPTable(3);
	outertable.setTotalWidth(200);
	outertable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
	float[] outer = { 60, 25, 15 };
	outertable.setWidths(outer);
	PdfPTable innertable = new PdfPTable(2);
	float[] inner = { 35, 65 };
	innertable.setWidths(inner);
	innertable.addCell(new Paragraph("name:", f));
	innertable.addCell(new Paragraph("Bruno Lowagie", f));
	innertable.addCell(new Paragraph("date of birth:", f));
	innertable.addCell(new Paragraph("June 10th, 1970", f));
	innertable.addCell(new Paragraph("Study Program:", f));
	innertable.addCell(new Paragraph("master in civil engineering", f));
	innertable.addCell(new Paragraph("option:", f));
	innertable.addCell(new Paragraph("architecture", f));
	outertable.addCell(innertable);
	outertable.getDefaultCell().setBackgroundColor(new Color(0xFF, 0xDE, 0xAD));
	outertable.addCell(Image.getInstance(PdfTestBase.RESOURCES_DIR + "bruno.jpg"));
	BarcodeEAN codeEAN = new BarcodeEAN();
	codeEAN.setCodeType(Barcode.EAN13);
	codeEAN.setCode("8010012529736");
	Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
	imageEAN.setRotationDegrees(90);
	outertable.getDefaultCell().setBackgroundColor(Color.WHITE);
	outertable.addCell(imageEAN);
	outertable.writeSelectedRows(0, -1, 20, 100, writer.getDirectContent());

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:56,代碼來源:StudentCardTest.java

示例13: main

import com.lowagie.text.Paragraph; //導入方法依賴的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

示例14: generateReport

import com.lowagie.text.Paragraph; //導入方法依賴的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

示例15: generalCellForApptHistory

import com.lowagie.text.Paragraph; //導入方法依賴的package包/類
private PdfPCell generalCellForApptHistory(String text) {
	Paragraph p = new Paragraph(text,getFont());
       p.setAlignment(Paragraph.ALIGN_LEFT);
       PdfPCell cell1 = new PdfPCell(p);
       cell1.setBorder(PdfPCell.NO_BORDER);
       cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
       return cell1;

}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:10,代碼來源:OscarChartPrinter.java


注:本文中的com.lowagie.text.Paragraph.setAlignment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。