本文整理匯總了Java中com.itextpdf.text.Element類的典型用法代碼示例。如果您正苦於以下問題:Java Element類的具體用法?Java Element怎麽用?Java Element使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Element類屬於com.itextpdf.text包,在下文中一共展示了Element類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFillCell
import com.itextpdf.text.Element; //導入依賴的package包/類
public PdfPCell getFillCell(){
PdfPCell fillCell = new PdfPCell();
fillCell.setBorderWidth( 0f );
fillCell.setLeft(0);
fillCell.setTop(0);
fillCell.setRight( 0 );
fillCell.setBottom( 0 );
fillCell.setUseAscender( true );
fillCell.setIndent(0);
fillCell.setHorizontalAlignment( Element.ALIGN_LEFT );
fillCell.setVerticalAlignment( Element.ALIGN_BOTTOM );
fillCell.setPaddingLeft( 0f);
fillCell.setPaddingBottom(0f);
fillCell.setPaddingRight(0f );
fillCell.setPaddingTop( 0f );
fillCell.setBorder( 0 );
renderEmptyCell(fillCell);
return fillCell;
}
示例2: cellRodape
import com.itextpdf.text.Element; //導入依賴的package包/類
private PdfPTable cellRodape(String value, boolean l,boolean r,int align)
{
Font fontCorpoTableO= FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED ,7.5f);
PdfPTable pTable = new PdfPTable(1);
pTable.setWidthPercentage(100f);
PdfPCell cellValue = new PdfPCell(new Phrase(value,fontCorpoTableO));
if(l){cellValue.setBorderWidthLeft(0);}
if(r){cellValue.setBorderWidthRight(0);}
switch (align)
{
case Element.ALIGN_RIGHT:cellValue.setHorizontalAlignment(Element.ALIGN_RIGHT);break;
case Element.ALIGN_LEFT:cellValue.setHorizontalAlignment(Element.ALIGN_LEFT);break;
case Element.ALIGN_CENTER:cellValue.setHorizontalAlignment(Element.ALIGN_CENTER);break;
default:break;
}
pTable.addCell(cellValue);
return pTable;
}
示例3: generatePage
import com.itextpdf.text.Element; //導入依賴的package包/類
@Override
public PdfPTable generatePage() throws Exception {
Image image = Image.getInstance(imageFile.toURL());
float heightToWidthRatio = (210f / 297f);
Image imageCropped = ImageUtils.cropImageToMeetRatio(pdfWriter, image, heightToWidthRatio);
PdfPCell cell = new PdfPCell(imageCropped, true);
cell.setBorder(0);
cell.setPadding(COVER_MARGIN);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setExtraParagraphSpace(0);
cell.setRightIndent(0);
PdfPTable table = new PdfPTable(1);
;
table.setWidthPercentage(100f);
table.setWidths(new int[]{1});
table.setExtendLastRow(true);
table.addCell(cell);
return table;
}
示例4: getObjectDescription
import com.itextpdf.text.Element; //導入依賴的package包/類
private Paragraph getObjectDescription()
{
Paragraph p = new Paragraph();
p.setLeading(0, 1.2f);
p.setAlignment(Element.ALIGN_JUSTIFIED);
p.setSpacingAfter(10);
p.setSpacingBefore(50);
if(o.getDescription()!=null){
p.add(new Chunk(o.getDescription(), bodyFont));
}
else{
p.add(new Chunk("No description recorded", bodyFont));
}
return p;
}
示例5: buildPdfPCell
import com.itextpdf.text.Element; //導入依賴的package包/類
private PdfPCell buildPdfPCell(HeaderFooter phf,String text,int type){
PdfPCell cell=new PdfPCell();
cell.setPadding(0);
cell.setBorder(Rectangle.NO_BORDER);
Font font=FontBuilder.getFont(phf.getFontFamily(), phf.getFontSize(), phf.isBold(), phf.isItalic(),phf.isUnderline());
String fontColor=phf.getForecolor();
if(StringUtils.isNotEmpty(fontColor)){
String[] color=fontColor.split(",");
font.setColor(Integer.valueOf(color[0]), Integer.valueOf(color[1]), Integer.valueOf(color[2]));
}
Paragraph graph=new Paragraph(text,font);
cell.setPhrase(graph);
switch(type){
case 1:
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
break;
case 2:
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
break;
case 3:
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
break;
}
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
return cell;
}
示例6: createGridColumnHeader
import com.itextpdf.text.Element; //導入依賴的package包/類
private void createGridColumnHeader(PdfPTable table, Collection<ColumnHeader> topHeaders, int maxHeaderLevel) throws Exception {
for (int i = 1; i < 50; i++) {
List<ColumnHeader> result = new ArrayList<ColumnHeader>();
generateGridHeadersByLevel(topHeaders, i, result);
for (ColumnHeader header : result) {
PdfPCell cell = new PdfPCell(createParagraph(header));
if (header.getBgColor() != null) {
int[] colors = header.getBgColor();
cell.setBackgroundColor(new BaseColor(colors[0], colors[1], colors[2]));
}
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(header.getAlign());
cell.setColspan(header.getColspan());
if (header.getColumnHeaders().size() == 0) {
int rowspan = maxHeaderLevel - (header.getLevel() - 1);
if (rowspan > 0) {
cell.setRowspan(rowspan);
}
}
table.addCell(cell);
}
}
}
示例7: onEndPage
import com.itextpdf.text.Element; //導入依賴的package包/類
@Override
public void onEndPage(PdfWriter writer, Document document) {
PdfPTable table = new PdfPTable(2);
table.setTotalWidth(527);
table.setWidthPercentage(100);
table.setLockedWidth(true);
table.getDefaultCell().setFixedHeight(105f);
table.getDefaultCell().setBorderWidth(0);
table.addCell("");
table.addCell(csmLogoImage);
table.writeSelectedRows(0, -1, 100, 840, writer.getDirectContent());
ColumnText.showTextAligned(writer.getDirectContent(),
Element.ALIGN_LEFT,
new Phrase(lebData.getSchuelername() + " " + lebData.getSchuljahr() + " " + lebData.getSchulhalbjahr().getId() + " Seite " + document.getPageNumber(), fusszeilenFont),
100, 75, 0);
}
示例8: getPhotoCell
import com.itextpdf.text.Element; //導入依賴的package包/類
private static PdfPCell getPhotoCell(BufferedImage bufferedImage, float scalePercent, boolean isHorizontallyCentered) throws BadElementException, IOException {
Image jpeg = Image.getInstance(bufferedImage, null);
jpeg.scalePercent(scalePercent);
jpeg.setAlignment(Image.MIDDLE);
PdfPCell photoCell = new PdfPCell(jpeg);
photoCell.setBorder(0);
if (isHorizontallyCentered) {
photoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
} else {
photoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
}
photoCell.setVerticalAlignment(Element.ALIGN_TOP);
int height = (int) Math.ceil(bufferedImage.getHeight() * scalePercent / 100);
photoCell.setFixedHeight(height);
return photoCell;
}
示例9: funcaoTitulo
import com.itextpdf.text.Element; //導入依賴的package包/類
private Phrase funcaoTitulo(int i) {
String txt;
Font fontcabecatable = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED ,10f );
switch (i)
{
case 0:txt="Nr. Factura";break;
case 1:txt="Nome do Segurado"; break;
case 2:txt="Prémio";break;
case 3:txt="Imposto 6%";break;
case 4:txt="Imposto 5%";break;
case 5:txt="FGA 2.6%";break;
default:txt="TOTAL";break;
}
a=com.itextpdf.text.Element.ALIGN_CENTER;
Phrase rt = new Phrase(txt,fontcabecatable);
return rt;
}
示例10: createGridTableDatas
import com.itextpdf.text.Element; //導入依賴的package包/類
private void createGridTableDatas(PdfPTable table, Collection<ReportData> datas) {
for (ReportData data : datas) {
PdfPCell cell = new PdfPCell(createParagraph(data.getTextChunk()));
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
int level = this.calculateIndentationCount(data.getTextChunk().getText());
if (data.getBgColor() != null) {
int[] colors = data.getBgColor();
cell.setBackgroundColor(new BaseColor(colors[0], colors[1], colors[2]));
}
if (level == 0) {
cell.setHorizontalAlignment(data.getAlign());
} else {
cell.setIndent(20 * level);
}
table.addCell(cell);
}
}
示例11: testShowTextAlignedVsSimpleColumnTopAlignment
import com.itextpdf.text.Element; //導入依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/32162759/columntext-showtextaligned-vs-columntext-setsimplecolumn-top-alignment">
* ColumnText.ShowTextAligned vs ColumnText.SetSimpleColumn Top Alignment
* </a>
* <p>
* Indeed, the coordinates do not line up. The y coordinate of
* {@link ColumnText#showTextAligned(PdfContentByte, int, Phrase, float, float, float)}
* denotes the baseline while {@link ColumnText#setSimpleColumn(Rectangle)} surrounds
* the text to come.
* </p>
*/
@Test
public void testShowTextAlignedVsSimpleColumnTopAlignment() throws DocumentException, IOException
{
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "ColumnTextTopAligned.pdf")));
document.open();
Font fontQouteItems = new Font(BaseFont.createFont(), 12);
PdfContentByte canvas = writer.getDirectContent();
// Item Number
ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("36222-0", fontQouteItems), 60, 450, 0);
// Estimated Qty
ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("47", fontQouteItems), 143, 450, 0);
// Item Description
ColumnText ct = new ColumnText(canvas); // Uses a simple column box to provide proper text wrapping
ct.setSimpleColumn(new Rectangle(193, 070, 390, 450));
ct.setText(new Phrase("In-Situ : Poly Cable - 100'\nPoly vented rugged black gable 100ft\nThis is an additional description. It can wrap an extra line if it needs to so this text is long.", fontQouteItems));
ct.go();
document.close();
}
示例12: extractBlogInfo
import com.itextpdf.text.Element; //導入依賴的package包/類
/**
* 根據URL提前blog的基本信息,返回結果>>:[主題 ,分類,日期,內容]等.
*
* @param blogURL
* @return
* @throws Exception
*/
public static String[] extractBlogInfo(String blogURL) throws Exception {
String[] info = new String[4];
org.jsoup.nodes.Document doc = Jsoup.connect(blogURL).get();
org.jsoup.nodes.Element e_title = doc.select("h2.title").first();
info[0] = e_title.text();
org.jsoup.nodes.Element e_category = doc.select("a[rel=category tag]")
.first();
info[1] = e_category.attr("href").replace("http://www.micmiu.com/", "");
org.jsoup.nodes.Element e_date = doc.select("span.post-info-date")
.first();
String dateStr = e_date.text().split("日期")[1].trim();
info[2] = dateStr;
org.jsoup.nodes.Element entry = doc.select("div.entry").first();
info[3] = formatContentTag(entry);
return info;
}
示例13: onEndPage
import com.itextpdf.text.Element; //導入依賴的package包/類
/**
* Adds a header to every page
* @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
* com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
*/
public void onEndPage(PdfWriter writer, Document document) {
PdfPTable table = new PdfPTable(3);
try {
table.setWidths(new int[]{40,5,10});
table.setTotalWidth(100);
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
Font font=new Font(chineseFont,8);
font.setColor(new BaseColor(55,55,55));
Paragraph paragraph=new Paragraph("第 "+writer.getPageNumber()+" 頁 共",font);
paragraph.setAlignment(Element.ALIGN_RIGHT);
table.addCell(paragraph);
Image img=Image.getInstance(total);
img.scaleAbsolute(28, 28);
PdfPCell cell = new PdfPCell(img);
cell.setBorder(Rectangle.NO_BORDER);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
PdfPCell c = new PdfPCell(new Paragraph("頁",font));
c.setHorizontalAlignment(Element.ALIGN_LEFT);
c.setBorder(Rectangle.NO_BORDER);
table.addCell(c);
float center=(document.getPageSize().getWidth())/2-120/2;
table.writeSelectedRows(0, -1,center,30, writer.getDirectContent());
}
catch(DocumentException de) {
throw new ExceptionConverter(de);
}
}
示例14: addTitlePage
import com.itextpdf.text.Element; //導入依賴的package包/類
private void addTitlePage(Document document) throws DocumentException {
addEmptyLine(document, 5);
Paragraph title = new Paragraph("Data Dictionary by Arrah technology");
title.setAlignment(Element.ALIGN_CENTER);
document.add(title);
addEmptyLine(document, 1);
Paragraph url = new Paragraph("http://sourceforge.net/projects/dataquality/");
url.setAlignment(Element.ALIGN_CENTER);
document.add(url);
addEmptyLine(document, 3);
Paragraph rtime = new Paragraph("Report generated on: " + new Date());
rtime.setAlignment(Element.ALIGN_CENTER);
document.add(rtime);
document.newPage();
}
示例15: stampTextOriginal
import com.itextpdf.text.Element; //導入依賴的package包/類
/**
* The OP's original code transformed into Java
*/
void stampTextOriginal(InputStream source, OutputStream target) throws DocumentException, IOException
{
Date today = new Date();
PdfReader reader = new PdfReader(source);
PdfStamper stamper = new PdfStamper(reader, target);
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED);
int tSize = 24;
String mark = "DRAFT " + today;
int angle = 45;
float height = reader.getPageSizeWithRotation(1).getHeight()/2;
float width = reader.getPageSizeWithRotation(1).getWidth()/2;
PdfContentByte cb = stamper.getOverContent(1);
cb.setColorFill(new BaseColor(255,200,200));
cb.setFontAndSize(bf, tSize);
cb.beginText();
cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle);
cb.endText();
stamper.close();
reader.close();
}