private void writeAttributes(MBeanNode mbean) throws DocumentException { final String description = mbean.getDescription(); final List<MBeanAttribute> attributes = mbean.getAttributes(); if (description != null || !attributes.isEmpty()) { currentTable = createAttributesTable(); if (description != null) { currentTable.getDefaultCell().setColspan(3); addCell('(' + description + ')'); currentTable.getDefaultCell().setColspan(1); } for (final MBeanAttribute attribute : attributes) { writeAttribute(attribute); } final Paragraph paragraph = new Paragraph(); paragraph.setIndentationLeft(margin); paragraph.add(currentTable); addToDocument(paragraph); addText("\n"); } }
cell.setColspan(colspan); pdfTable.addCell(cell);
//Create the table which will be 2 Columns wide and make it 100% of the page PdfPTable myTable = new PdfPtable(2); myTable.setWidthPercentage(100.0f); //create a 3 cells and add them to the table PdfPCell cellOne = new PdfPCell(new Paragraph("Hello World")); PdfPCell cellTwo = new PdfPCell(new Paragraph("Bottom Left")); PdfPcell cellThree = new PdfPCell(new Paragraph("Bottom Right")); cellOne.setColspan(2); cellOne.setBorder(Rectangle.BOTTOM); cellOne.setHorizontalAlignment(Element.ALIGN_LEFT); cellTwo.setBorder(Rectangle.NO_BORDER); cellTwo.setHorizontalAlignment(Element.ALIGN_LEFT); cellThree.setBorder(Rectangle.LEFT); cellThree.setHorizontalAlignment(Element.ALIGN_RIGHT); //Add the three cells to the table myTable.addCell(cellOne); myTable.addCell(cellTwo); myTable.addCell(cellThree); //Do something to add the table to your root document
table.getDefaultCell().setBorder(Rectangle.NO_BORDER); PdfPCell cellMerchantTitle = rowCellStyle("Merchant", fontTitleSize); cellMerchantTitle.setColspan(2); table.addCell(cellSystemTitle); table.completeRow();
PdfPCell cell = new PdfPCell(Image.getInstance(header)); cell.setColspan(3); table.addCell(cell);
PdfPTable table = new PdfPTable(4) // 4 Columns PdfPCell cell; cell = new PdfPCell( new Phrase("Cell with colspan of 4") ) ; cell. setColspan(4) ; // an entire row anotherCell = new PdfPCell( new Phrase("Cell with colspan of 4") ); anotherCell.setColspan(4); // a second row
/** * Creates an empty cell. * * @param colspan The column span of the cell. * @param height The height of the column. * @return A PdfCell. */ public static PdfPCell getEmptyCell( int colSpan, int height ) { PdfPCell cell = new PdfPCell(); cell.setColspan( colSpan ); cell.setBorder( 0 ); cell.setMinimumHeight( height ); return cell; }
PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); PdfPCell cell = new PdfPCell(new Phrase("Table XYZ (Continued)")); cell.setColspan(5); table.addCell(cell); table.setHeaderRows(1); table.setSkipFirstHeader(true); for (int i = 0; i < 350; i++) { table.addCell(String.valueOf(i+1)); } document.add(table);
for (PdfTemplate chart : charts) { PdfPTable table = new PdfPTable(3); // 3 columns. table.setWidthPercentage(100); PdfPCell cell = new PdfPCell(Image.getInstance(chart), true); cell.setColspan(3); table.addCell(cell); PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1")); PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2")); PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3")); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); document.add(table); document.newPage(); }
PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); PdfPCell cell = new PdfPCell(new Phrase("Table XYZ (Continued)")); cell.setColspan(5); table.addCell(cell); cell = new PdfPCell(new Phrase("Continue on next page")); cell.setColspan(5); table.addCell(cell); table.setHeaderRows(2); table.setFooterRows(1); table.setSkipFirstHeader(true); table.setSkipLastFooter(true); for (int i = 0; i < 350; i++) { table.addCell(String.valueOf(i+1)); } document.add(table);
/** * Methode qui ajoute le tableau de data dans le fichier pdf * @param data1 liste de listes * @param title titre du tableau * @param document document pdf * @throws DocumentException * @author Adrien Hadoux */ public static void addDataToDocPdf(java.util.List<java.util.List> _liste,String _title,Document _document) throws DocumentException{ //TODO ADRIEN rien a dire la. Un conseil essaie d'utiliser la fonction Clean Up et Format d'eclipse qui te permette d'avoir un //code + propre. En l'etat, ce code est bon, je chipote... PdfPTable table = new PdfPTable(_liste.size()); //-- titre --// PdfPCell cell = new PdfPCell(new Paragraph(_title)); cell.setColspan(_liste.size()); table.addCell(cell); //-- remplissage --// for(java.util.List sousListe:_liste) for(Object l:sousListe) table.addCell(l.toString()); _document.add(table); }
/** * Methode qui ajoute le tableau de data dans le fichier pdf * @param data1 liste de listes * @param title titre du tableau * @param document document pdf * @throws DocumentException * @author Adrien Hadoux */ public static void addDataToDocPdf(java.util.List<java.util.List> _liste,String _title,Document _document) throws DocumentException{ PdfPTable table = new PdfPTable(_liste.size()); //-- titre --// PdfPCell cell = new PdfPCell(new Paragraph(_title)); cell.setColspan(_liste.size()); table.addCell(cell); //-- remplissage --// for(java.util.List sousListe:_liste) for(Object l:sousListe) table.addCell(l.toString()); _document.add(table); }
/** * Creates a cell. * * @param text The text to include in the cell. * @param colspan The column span of the cell. * @param font The font of the cell text. * @param horizontalAlign The vertical alignment of the text in the cell. * @return A PdfCell. */ public static PdfPCell getCell( String text, int colspan, Font font, int horizontalAlign ) { Paragraph paragraph = new Paragraph( text, font ); PdfPCell cell = new PdfPCell( paragraph ); cell.setColspan( colspan ); cell.setBorder( 0 ); cell.setMinimumHeight( 15 ); cell.setHorizontalAlignment( horizontalAlign ); return cell; }
/** * Methode qui ajoute le tableau de data dans le fichier pdf * @param _data tableau de donnes * @param _title titre du tableau * @param _document document pdf * @throws DocumentException * @author Adrien Hadoux */ public static void addDataToDocPdf(Object[][] _data,String _title,Document _document) throws DocumentException{ PdfPTable table = new PdfPTable(2); //-- titre --// PdfPCell cell = new PdfPCell(new Paragraph(_title)); cell.setColspan(2); table.addCell(cell); //-- remplissage --// for(int i=0;i<_data.length;i++) for(int j=0;j<_data.length;i++) table.addCell(_data[i][j].toString()); _document.add(table); }
private void writeAttributes(MBeanNode mbean) throws DocumentException { final String description = mbean.getDescription(); final List<MBeanAttribute> attributes = mbean.getAttributes(); if (description != null || !attributes.isEmpty()) { currentTable = createAttributesTable(); if (description != null) { currentTable.getDefaultCell().setColspan(3); addCell('(' + description + ')'); currentTable.getDefaultCell().setColspan(1); } for (final MBeanAttribute attribute : attributes) { writeAttribute(attribute); } final Paragraph paragraph = new Paragraph(); paragraph.setIndentationLeft(margin); paragraph.add(currentTable); addToDocument(paragraph); addText("\n"); } }
/** * Methode qui ajoute le tableau de data dans le fichier pdf * @param _data tableau de donnes * @param _title titre du tableau * @param _document document pdf * @throws DocumentException * @author Adrien Hadoux */ public static void addDataToDocPdf(Object[][] _data,String _title,Document _document) throws DocumentException{ PdfPTable table = new PdfPTable(2); //-- titre --// PdfPCell cell = new PdfPCell(new Paragraph(_title)); cell.setColspan(2); table.addCell(cell); //-- remplissage --// for(int i=0;i<_data.length;i++) for(int j=0;j<_data.length;i++) table.addCell(_data[i][j].toString()); _document.add(table); }
... PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(new Phrase("A")); cell.setColspan(2); cell.setRowspan(2); table.addCell(cell); table.addCell("B"); table.addCell("C"); table.addCell("D"); table.addCell("E"); table.addCell("F"); document.add(table); ...
// a table with three columns PdfPTable table = new PdfPTable(3); // the cell object PdfPCell cell; // we add a cell with colspan 3 cell = new PdfPCell(new Phrase("Cell with colspan 3")); cell.setColspan(3); table.addCell(cell); // now we add a cell with rowspan 2 cell = new PdfPCell(new Phrase("Cell with rowspan 2")); cell.setRowspan(2); table.addCell(cell); // we add the four remaining cells with addCell() table.addCell("row 1; cell 1"); table.addCell("row 1; cell 2"); table.addCell("row 2; cell 1"); table.addCell("row 2; cell 2");
Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("span-in-table.pdf")); document.open(); PdfPTable table = new PdfPTable(3); table.addCell("A"); PdfPCell cell = new PdfPCell(new Phrase("B")); cell.setColspan(2); cell.setRowspan(2); table.addCell(cell); table.addCell("C"); table.addCell("D"); table.addCell("E"); table.addCell("F"); document.add(table); document.close();
PdfPTable table = new PdfPTable(3); table.addCell("cell A0"); table.addCell("cell A1"); table.addCell("cell A2"); table.addCell("cell B0"); table.addCell("cell B1"); table.addCell("cell B2"); PdfPCell cell = new PdfPCell(); cell.setColspan(2); cell.addElement(new Phrase("C0 & C1")); table.addCell(cell); table.addCell("cell C2");