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