List of usage examples for com.lowagie.text.pdf PdfPCell addElement
public void addElement(Element element)
From source file:ilarkesto.integration.itext.Paragraph.java
License:Open Source License
@Override public Element getITextElement() { com.lowagie.text.Paragraph p = new com.lowagie.text.Paragraph(); float maxSize = 0; for (AParagraphElement element : getElements()) { if (element instanceof TextChunk) { TextChunk textChunk = (TextChunk) element; FontStyle fontStyle = textChunk.getFontStyle(); FontSelector fontSelector = createFontSelector(fontStyle.getFont(), fontStyle); String text = textChunk.getText(); Phrase phrase = fontSelector.process(text); p.add(phrase);/*from w w w .j av a 2s . c o m*/ float size = (fontStyle.getSize() * 1.1f) + 1f; if (size > maxSize) maxSize = PdfBuilder.mmToPoints(size); } else if (element instanceof Image) { Image image = (Image) element; com.lowagie.text.Image itextImage; try { itextImage = image.getITextElement(); } catch (Exception ex) { log.warn("Including image failed:", image, ex); continue; } if (image.getAlign() != null) { itextImage.setAlignment(Image.convertAlign(image.getAlign()) | com.lowagie.text.Image.TEXTWRAP); p.add(itextImage); } else { Chunk chunk = new Chunk(itextImage, 0, 0); p.add(chunk); float size = image.getHeight() + 3; if (size > maxSize) maxSize = size; } } else { throw new RuntimeException("Unsupported paragraph element: " + element.getClass().getName()); } } p.setLeading(maxSize); p.setSpacingBefore(PdfBuilder.mmToPoints(spacingTop)); p.setSpacingAfter(PdfBuilder.mmToPoints(spacingBottom)); if (align != null) p.setAlignment(convertAlign(align)); if (height <= 0) return p; // wrap in table PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.setFixedHeight(PdfBuilder.mmToPoints(height)); cell.addElement(p); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); table.addCell(cell); return table; }
From source file:lmcpointofsalessystem.PDFCustomers.java
public PdfPTable getDatas(String tblName) { PdfPTable headerTable = new PdfPTable(1); String newT = tblName.toString(); try {// ww w . j a v a 2 s . co m rs = s.executeQuery( "select C.CustomerID, C.FirstName, C.LastName, C.Address, C.ContactNumber from Customers C"); //alias lang ung "E" String columnExe = ""; columnExe = "CustomerID,FirstName,LastName,Address,ContactNumber";//pdf column names String[] colH = columnExe.split(","); int colL = 0; colL = columnExe.split(",").length; headerTable = new PdfPTable(colL); for (int x = 0; x < colL; x++) { if (colH[x].toString().equals("C.CustomerID")) { colH[x] = "OrderNo1"; } else if (colH[x].toString().equals("C.FirstName")) { colH[x] = "O.CustNo"; } else if (colH[x].toString().equals("C.LastName")) { colH[x] = "OrderDate"; } else if (colH[x].toString().equals("C.Address")) { colH[x] = "ItemDesc"; } else if (colH[x].toString().equals("C.ContactNumber")) { colH[x] = "Unit"; } PdfPCell newHeader = new PdfPCell(); newHeader.addElement(new Paragraph(colH[x])); headerTable.addCell(newHeader); } //System.out.println(""+columnExe); rs = st.executeQuery("Select " + columnExe + " from Customers C"); int colNums = colH.length; int colCount = 0; while (rs.next() == true) { for (int x = 1; x <= colL; x++) { colCount += 1; PdfPCell newCell = new PdfPCell(); newCell.addElement(new Paragraph(rs.getString(x))); headerTable.setWidthPercentage(90); headerTable.addCell(newCell); } } float[] widths2 = new float[colNums]; for (int i = 0; i < colNums; i++) { widths2[i] = 150; } try { headerTable.setWidths(widths2); } catch (DocumentException ex) { Logger.getLogger(PDFCustomers.class.getName()).log(Level.SEVERE, null, ex); } } catch (SQLException ex) { Logger.getLogger(PDFCustomers.class.getName()).log(Level.SEVERE, null, ex); } return headerTable; }
From source file:lmcpointofsalessystem.PDFCustomersEmployee.java
public PdfPTable getDatas(String tblName) { PdfPTable headerTable = new PdfPTable(1); String newT = tblName.toString(); try {/* www . jav a 2s . co m*/ rs = s.executeQuery( "select C.CustomerID, C.FirstName, C.LastName, C.Address, C.ContactNumber from Customers C"); //alias lang ung "E" String columnExe = ""; columnExe = "CustomerID,FirstName,LastName,Address,ContactNumber";//pdf column names String[] colH = columnExe.split(","); int colL = 0; colL = columnExe.split(",").length; headerTable = new PdfPTable(colL); for (int x = 0; x < colL; x++) { if (colH[x].toString().equals("C.CustomerID")) { colH[x] = "OrderNo1"; } else if (colH[x].toString().equals("C.FirstName")) { colH[x] = "O.CustNo"; } else if (colH[x].toString().equals("C.LastName")) { colH[x] = "OrderDate"; } else if (colH[x].toString().equals("C.Address")) { colH[x] = "ItemDesc"; } else if (colH[x].toString().equals("C.ContactNumber")) { colH[x] = "Unit"; } PdfPCell newHeader = new PdfPCell(); newHeader.addElement(new Paragraph(colH[x])); headerTable.addCell(newHeader); } //System.out.println(""+columnExe); rs = st.executeQuery("Select " + columnExe + " from Customers C"); int colNums = colH.length; int colCount = 0; while (rs.next() == true) { for (int x = 1; x <= colL; x++) { colCount += 1; PdfPCell newCell = new PdfPCell(); newCell.addElement(new Paragraph(rs.getString(x))); headerTable.setWidthPercentage(90); headerTable.addCell(newCell); } } float[] widths2 = new float[colNums]; for (int i = 0; i < colNums; i++) { widths2[i] = 150; } try { headerTable.setWidths(widths2); } catch (DocumentException ex) { Logger.getLogger(PDFCustomersEmployee.class.getName()).log(Level.SEVERE, null, ex); } } catch (SQLException ex) { Logger.getLogger(PDFCustomersEmployee.class.getName()).log(Level.SEVERE, null, ex); } return headerTable; }
From source file:lmcpointofsalessystem.PDFOrders.java
public PdfPTable getDatas(String tblName) { ;//from www .ja v a2 s. c o m PdfPTable headerTable = new PdfPTable(1); String newT = tblName.toString(); String col1 = co.tblOrder.getColumnName(0); String col2 = co.tblOrder.getColumnName(1); int nrow = co.tblModel.getRowCount(); int ncol = co.tblModel.getColumnCount(); Object[][] tabledata = new Object[nrow][ncol]; for (int i = 0; i < nrow; i++) { for (int j = 0; j < ncol; j++) { tabledata[i][j] = co.tblModel.getValueAt(i, j); } } String columnExe = ""; columnExe = "empID,Fname,Lname,Username,Password,Address,Contact,Type"; String[] colH = columnExe.split(","); int colL = 0; colL = columnExe.split(",").length; headerTable = new PdfPTable(colL); for (int x = 0; x < colL; x++) { if (colH[x].toString().equals(col1)) { colH[x] = "OrderNo1"; } else if (colH[x].toString().equals(col2)) { colH[x] = "O.CustNo"; } PdfPCell newHeader = new PdfPCell(); newHeader.addElement(new Paragraph(colH[x])); headerTable.addCell(newHeader); } int colNums = colH.length; int colCount = 0; for (int x = 1; x <= colL; x++) { colCount += 1; PdfPCell newCell = new PdfPCell(); newCell.addElement(new Paragraph((x))); headerTable.setWidthPercentage(90); headerTable.addCell(newCell); } float[] widths2 = new float[colNums]; for (int i = 0; i < colNums; i++) { widths2[i] = 150; } try { headerTable.setWidths(widths2); } catch (DocumentException ex) { Logger.getLogger(PDFEmployees.class.getName()).log(Level.SEVERE, null, ex); } return headerTable; }
From source file:net.bull.javamelody.internal.web.pdf.PdfCounterRequestContextReport.java
License:Apache License
private void writeRequests(List<CounterRequestContext> contexts) throws DocumentException, IOException { final PdfPCell defaultCell = getDefaultCell(); final PdfPCell requestCell = new PdfPCell(); final Paragraph phrase = new Paragraph("", cellFont); int margin = 0; for (final CounterRequestContext context : contexts) { writeRequest(context, requestCell, margin); margin += 5;/* w ww .ja v a 2 s.c om*/ } // on utilise ici PdfPCell et addElement pour que les proprits // leading et indentationLeft des paragraphes soient prises en compte requestCell.addElement(phrase); requestCell.setGrayFill(defaultCell.getGrayFill()); requestCell.setPaddingTop(defaultCell.getPaddingTop()); addCell(requestCell); }
From source file:net.bull.javamelody.internal.web.pdf.PdfCounterRequestContextReport.java
License:Apache License
private void writeRequest(CounterRequestContext context, PdfPCell cell, int margin) throws DocumentException, IOException { final Paragraph paragraph = new Paragraph(getDefaultCell().getLeading() + cellFont.getSize()); paragraph.setIndentationLeft(margin); if (context.getParentCounter().getIconName() != null) { paragraph.add(new Chunk(getImage(context.getParentCounter().getIconName()), 0, -1)); }// www.j a v a2 s. c o m paragraph.add(new Phrase(context.getCompleteRequestName(), cellFont)); cell.addElement(paragraph); }
From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java
License:Apache License
private void writeRequest(CounterRequest childRequest, float executionsByRequest, boolean allChildHitsDisplayed) throws IOException, DocumentException { final PdfPCell defaultCell = getDefaultCell(); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); final Paragraph paragraph = new Paragraph(defaultCell.getLeading() + cellFont.getSize()); if (executionsByRequest != -1) { paragraph.setIndentationLeft(5); }/*from w ww. j a v a 2 s.c om*/ final Counter parentCounter = getCounterByRequestId(childRequest); if (parentCounter != null && parentCounter.getIconName() != null) { paragraph.add(new Chunk(getSmallImage(parentCounter.getIconName()), 0, -1)); } paragraph.add(new Phrase(childRequest.getName(), cellFont)); final PdfPCell requestCell = new PdfPCell(); requestCell.addElement(paragraph); requestCell.setGrayFill(defaultCell.getGrayFill()); requestCell.setPaddingTop(defaultCell.getPaddingTop()); addCell(requestCell); defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); if (executionsByRequest != -1) { addCell(nbExecutionsFormat.format(executionsByRequest)); } else { addCell(""); } writeRequestValues(childRequest, allChildHitsDisplayed); }
From source file:net.bull.javamelody.internal.web.pdf.PdfThreadInformationsReport.java
License:Apache License
private void writeThreadInformations(ThreadInformations threadInformations) throws DocumentException, IOException { final PdfPCell defaultCell = getDefaultCell(); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); addCell(threadInformations.getName()); defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER); if (threadInformations.isDaemon()) { addCell(getString("oui")); } else {//from ww w .j ava 2s. c o m addCell(getString("non")); } defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); addCell(integerFormat.format(threadInformations.getPriority())); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); final PdfPCell cell = new PdfPCell(); final Paragraph paragraph = new Paragraph(getDefaultCell().getLeading() + cellFont.getSize()); paragraph.add(new Chunk( getImage("bullets/" + HtmlThreadInformationsReport.getStateIcon(threadInformations)), 0, -1)); paragraph.add(new Phrase(String.valueOf(threadInformations.getState()), cellFont)); cell.addElement(paragraph); addCell(cell); if (stackTraceEnabled) { addCell(threadInformations.getExecutedMethod()); } if (cpuTimeEnabled) { defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); addCell(integerFormat.format(threadInformations.getCpuTimeMillis())); addCell(integerFormat.format(threadInformations.getUserTimeMillis())); } }
From source file:nl.dykema.jxmlnote.report.pdf.PdfTable.java
License:Open Source License
public Table add(Cell cel) { if (cel instanceof PdfCell) { super.addCell((PdfCell) cel); } else {/*ww w. j av a 2 s . c o m*/ PdfPCell c = new PdfPCell(); c.addElement(new Paragraph(new Chunk("Cannot mix different implementations"))); super.addCell(c); } return this; }
From source file:optika.sql.java
public PdfPCell getCellWhite(String text, int alignment, int bottom) { PdfPCell cell = new PdfPCell(); FontSelector selector = new FontSelector(); com.lowagie.text.Font f1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12); f1.setColor(Color.white);/*from w ww . j av a 2s . c o m*/ selector.addFont(f1); cell.addElement(selector.process(text)); cell.setPadding(0); cell.setHorizontalAlignment(alignment); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingBottom(bottom); return cell; }