com.lowagie.text.Table Java Examples
The following examples show how to use
com.lowagie.text.Table.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyFirstTableTest.java From itext2 with GNU Lesser General Public License v3.0 | 7 votes |
/** * A very simple Table example. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, PdfTestBase.getOutputStream("MyFirstTable.pdf")); // step 3: we open the document document.open(); // step 4: we create a table and add it to the document Table table = new Table(2, 2); // 2 rows, 2 columns table.addCell("0.0"); table.addCell("0.1"); table.addCell("1.0"); table.addCell("1.1"); document.add(table); document.add(new Paragraph("converted to PdfPTable:")); table.setConvert2pdfptable(true); document.add(table); // step 5: we close the document document.close(); }
Example #2
Source File: PdfTable.java From MesquiteCore with GNU Lesser General Public License v3.0 | 6 votes |
/** * Constructs a <CODE>PdfTable</CODE>-object. * * @param table a <CODE>Table</CODE> * @param left the left border on the page * @param right the right border on the page * @param top the start position of the top of the table * @param supportUpdateRowAdditions * if true, table rows will be deleted after building the PdfTable table, * in order to preserve memory and detect future row additions */ PdfTable(Table table, float left, float right, float top, boolean supportUpdateRowAdditions) { // constructs a Rectangle (the bottomvalue will be changed afterwards) super(left, top, right, top); this.table = table; table.complete(); // copying the attributes from class Table cloneNonPositionParameters(table); this.columns = table.columns(); positions = table.getWidths(left, right - left); // initialisation of some parameters setLeft(positions[0]); setRight(positions[positions.length - 1]); headercells = new ArrayList(); cells = new ArrayList(); updateRowAdditionsInternal(); if (supportUpdateRowAdditions) { table.deleteAllRows(); } }
Example #3
Source File: Coversheet.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
/** * Get the PDF Table containing trip information like trip id, date, and destination * * @returns {@link Table} used for a PDF */ protected Table getTripInfo() throws BadElementException { final Table retval = new Table(3); retval.setWidth(100f); retval.setBorder(NO_BORDER); retval.addCell(getHeaderCell("Trip/Event ID")); final Cell dateHeaderCell = getHeaderCell("Date"); retval.addCell(dateHeaderCell); retval.addCell(getHeaderCell("Destination/Event Name")); retval.endHeaders(); retval.addCell(getBorderlessCell(getTripId())); final Cell dateCell = getBorderlessCell(getDate()); retval.addCell(dateCell); retval.addCell(getBorderlessCell(getDestination())); return retval; }
Example #4
Source File: Coversheet.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
/** * Get the PDF Table with personal information about the initiator and traveler * * @returns {@link Table} used for a PDF */ protected Table getPersonalInfo() throws BadElementException { final Table retval = new Table(2); retval.setWidth(100f); retval.setBorder(NO_BORDER); retval.addCell(getHeaderCell("Traveler")); final Cell initiatorHeaderCell = getHeaderCell("Request Submitted By"); retval.addCell(initiatorHeaderCell); retval.endHeaders(); retval.addCell(getTravelerInfo()); final Cell initiatorCell = getInitiatorInfo(); retval.addCell(initiatorCell); return retval; }
Example #5
Source File: Coversheet.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
public Table getExpenses() throws BadElementException { final Table retval = new Table(3); retval.setWidth(100f); retval.setBorder(NO_BORDER); retval.addCell(getHeaderCell("Expenses")); retval.addCell(getHeaderCell("Amount")); retval.addCell(getHeaderCell("Receipt Required?")); retval.endHeaders(); for (final Map<String, String> expense : expenses) { retval.addCell(getBorderlessCell(expense.get("expenseType"))); retval.addCell(getBorderlessCell(expense.get("amount"))); retval.addCell(getBorderlessCell(expense.get("receipt"))); } return retval; }
Example #6
Source File: PdfTable.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Constructs a <CODE>PdfTable</CODE>-object. * * @param table a <CODE>Table</CODE> * @param left the left border on the page * @param right the right border on the page * @param top the start position of the top of the table * @since a parameter of this method has been removed in iText 2.0.8 */ PdfTable(Table table, float left, float right, float top) { // constructs a Rectangle (the bottom value will be changed afterwards) super(left, top, right, top); this.table = table; table.complete(); // copying the attributes from class Table cloneNonPositionParameters(table); this.columns = table.getColumns(); positions = table.getWidths(left, right - left); // initialization of some parameters setLeft(positions[0]); setRight(positions[positions.length - 1]); headercells = new ArrayList(); cells = new ArrayList(); updateRowAdditionsInternal(); }
Example #7
Source File: PatchRtfTableTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testImportTableRemovesUnusedRow() throws BadElementException { Table table = Mockito.mock( Table.class ); Row row = Mockito.mock( Row.class ); RtfDocument rtfDocument = new RtfDocument(); List<Row> rows = new ArrayList<>( 5 ); for ( int i = 0; i < 5; i++ ) { rows.add( row ); } Iterator<Row> iterator = rows.iterator(); Mockito.when( table.iterator() ).thenReturn( iterator ); new PatchRtfTable( rtfDocument, table ); Assert.assertFalse( iterator.hasNext() ); Assert.assertEquals( 0, rows.size() ); }
Example #8
Source File: PdfTable.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Constructs a <CODE>PdfTable</CODE>-object. * * @param table a <CODE>Table</CODE> * @param left the left border on the page * @param right the right border on the page * @param top the start position of the top of the table * @since a parameter of this method has been removed in iText 2.0.8 */ PdfTable(Table table, float left, float right, float top) { // constructs a Rectangle (the bottom value will be changed afterwards) super(left, top, right, top); this.table = table; table.complete(); // copying the attributes from class Table cloneNonPositionParameters(table); columns = table.getColumns(); positions = table.getWidths(left, right - left); // initialization of some parameters setLeft(positions[0]); setRight(positions[positions.length - 1]); headercells = new ArrayList(); cells = new ArrayList(); updateRowAdditionsInternal(); }
Example #9
Source File: PatchRtfTable.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Imports the rows and settings from the Table into this PatchRtfTable. * * @param table * The source Table */ private void importTable( Table table ) { this.rows = new ArrayList<PatchRtfRow>(); this.tableWidthPercent = table.getWidth(); this.proportionalWidths = table.getProportionalWidths(); this.cellPadding = (float) ( table.getPadding() * TWIPS_FACTOR ); this.cellSpacing = (float) ( table.getSpacing() * TWIPS_FACTOR ); this.borders = new PatchRtfBorderGroup( this.document, PatchRtfBorder.ROW_BORDER, table.getBorder(), table.getBorderWidth(), table.getBorderColor() ); this.alignment = table.getAlignment(); int i = 0; Iterator rowIterator = table.iterator(); while ( rowIterator.hasNext() ) { this.rows.add( new PatchRtfRow( this.document, this, (Row) rowIterator.next(), i ) ); // avoid out of memory exception rowIterator.remove(); i++; } for ( i = 0; i < this.rows.size(); i++ ) { this.rows.get( i ).handleCellSpanning(); this.rows.get( i ).cleanRow(); } this.headerRows = table.getLastHeaderRow(); this.cellsFitToPage = table.isCellsFitPage(); this.tableFitToPage = table.isTableFitsPage(); if ( !Float.isNaN( table.getOffset() ) ) { this.offset = (int) ( table.getOffset() * 2 ); } }
Example #10
Source File: RtfHeaderFooter.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Set the alignment of this RtfHeaderFooter. Passes the setting * on to the contained element. */ public void setAlignment(int alignment) { super.setAlignment(alignment); for(int i = 0; i < this.content.length; i++) { if(this.content[i] instanceof Paragraph) { ((Paragraph) this.content[i]).setAlignment(alignment); } else if(this.content[i] instanceof Table) { ((Table) this.content[i]).setAlignment(alignment); } else if(this.content[i] instanceof Image) { ((Image) this.content[i]).setAlignment(alignment); } } }
Example #11
Source File: RtfTable.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Imports the rows and settings from the Table into this * RtfTable. * * @param table The source Table */ private void importTable(Table table) { this.rows = new ArrayList(); this.tableWidthPercent = table.getWidth(); this.proportionalWidths = table.getProportionalWidths(); this.cellPadding = (float) (table.getPadding() * TWIPS_FACTOR); this.cellSpacing = (float) (table.getSpacing() * TWIPS_FACTOR); this.borders = new RtfBorderGroup(this.document, RtfBorder.ROW_BORDER, table.getBorder(), table.getBorderWidth(), table.getBorderColor()); this.alignment = table.getAlignment(); int i = 0; Iterator rowIterator = table.iterator(); while(rowIterator.hasNext()) { this.rows.add(new RtfRow(this.document, this, (Row) rowIterator.next(), i)); i++; } for(i = 0; i < this.rows.size(); i++) { ((RtfRow) this.rows.get(i)).handleCellSpanning(); ((RtfRow) this.rows.get(i)).cleanRow(); } this.headerRows = table.getLastHeaderRow(); this.cellsFitToPage = table.isCellsFitPage(); this.tableFitToPage = table.isTableFitsPage(); if(!Float.isNaN(table.getOffset())) { this.offset = (int) (table.getOffset() * 2); } }
Example #12
Source File: TableWithImageTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * A very simple PdfPTable example. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, PdfTestBase.getOutputStream("imageTable.pdf")); // step 3: we open the document document.open(); // step 4: we create a table and add it to the document Table table = new Table(2, 2); // 2 rows, 2 columns table.addCell(new Cell(Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg"))); table.addCell(new Cell(Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.gif"))); Cell c1 = new Cell(); c1.add(Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.gif")); table.addCell(c1); Cell c2 = new Cell(); c2.add(Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg")); table.addCell(c2); document.add(table); document.add(new Paragraph("converted to PdfPTable:")); table.setConvert2pdfptable(true); document.add(table); // step 5: we close the document document.close(); }
Example #13
Source File: PdfDocument.java From MesquiteCore with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns the bottomvalue of a <CODE>Table</CODE> if it were added to this document. * * @param table the table that may or may not be added to this document * @return a bottom value */ float bottom(Table table) { // where will the table begin? float h = (currentHeight > 0) ? indentTop() - currentHeight - 2f * leading : indentTop(); // constructing a PdfTable PdfTable tmp = getPdfTable(table, false); return tmp.bottom(); }
Example #14
Source File: LargeCellTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Demonstrates the features of the old Table class. */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(PageSize.A6); // step 2: creation of the writer-object PdfWriter.getInstance(document, PdfTestBase.getOutputStream("largecell.pdf")); // step 3: we open the document document.open(); // step 4: we create a table and add it to the document Table table = new Table(3); table.setCellsFitPage(true); String text = "long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text"; table.addCell("text"); table.addCell("text"); table.addCell("text"); table.addCell(text); table.addCell(text + text); table.addCell(text); table.addCell("text"); table.addCell("text"); table.addCell("text"); document.add(table); // step 5: we close the document document.close(); }
Example #15
Source File: MPdfWriter.java From javamelody with Apache License 2.0 | 5 votes |
/** * Effectue le rendu de la liste. * * @param table * MBasicTable * @param datatable * Table * @throws BadElementException * e */ protected void renderList(final MBasicTable table, final Table datatable) throws BadElementException { final int columnCount = table.getColumnCount(); final int rowCount = table.getRowCount(); // data rows final Font font = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL); datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); // datatable.setDefaultCellGrayFill(0); Object value; String text; int horizontalAlignment; for (int k = 0; k < rowCount; k++) { for (int i = 0; i < columnCount; i++) { value = getValueAt(table, k, i); if (value instanceof Number || value instanceof Date) { horizontalAlignment = Element.ALIGN_RIGHT; } else if (value instanceof Boolean) { horizontalAlignment = Element.ALIGN_CENTER; } else { horizontalAlignment = Element.ALIGN_LEFT; } datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignment); text = getTextAt(table, k, i); datatable.addCell(new Phrase(8, text != null ? text : "", font)); } } }
Example #16
Source File: MPdfWriter.java From javamelody with Apache License 2.0 | 5 votes |
/** * Effectue le rendu des headers. * * @param table * MBasicTable * @param datatable * Table * @throws BadElementException * e */ protected void renderHeaders(final MBasicTable table, final Table datatable) throws BadElementException { final int columnCount = table.getColumnCount(); final TableColumnModel columnModel = table.getColumnModel(); // size of columns float totalWidth = 0; for (int i = 0; i < columnCount; i++) { totalWidth += columnModel.getColumn(i).getWidth(); } final float[] headerwidths = new float[columnCount]; for (int i = 0; i < columnCount; i++) { headerwidths[i] = 100f * columnModel.getColumn(i).getWidth() / totalWidth; } datatable.setWidths(headerwidths); datatable.setWidth(100f); // table header final Font font = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // datatable.setDefaultCellGrayFill(0.75f); String text; Object value; for (int i = 0; i < columnCount; i++) { value = columnModel.getColumn(i).getHeaderValue(); text = value != null ? value.toString() : ""; datatable.addCell(new Phrase(text, font)); } // end of the table header datatable.endHeaders(); }
Example #17
Source File: PatchRtfDocument.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public RtfBasicElement[] mapElement( Element element ) throws DocumentException { ArrayList<RtfBasicElement> rtfElements = new ArrayList<RtfBasicElement>(); if ( element instanceof RtfBasicElement ) { RtfBasicElement rtfElement = (RtfBasicElement) element; rtfElement.setRtfDocument( rtfDoc ); return new RtfBasicElement[] { rtfElement }; } switch ( element.type() ) { case Element.CHUNK: Chunk chunk = (Chunk) element; if ( chunk.hasAttributes() ) { if ( chunk.getAttributes().containsKey( Chunk.IMAGE ) ) { rtfElements.add( new RtfImage( rtfDoc, chunk.getImage() ) ); } else if ( chunk.getAttributes().containsKey( Chunk.NEWPAGE ) ) { rtfElements.add( new RtfNewPage( rtfDoc ) ); } else if ( chunk.getAttributes().containsKey( Chunk.TAB ) ) { Float tabPos = (Float) ( (Object[]) chunk.getAttributes().get( Chunk.TAB ) )[1]; RtfTab tab = new RtfTab( tabPos.floatValue(), RtfTab.TAB_LEFT_ALIGN ); tab.setRtfDocument( rtfDoc ); rtfElements.add( tab ); rtfElements.add( new RtfChunk( rtfDoc, new Chunk( "\t" ) ) ); } else { rtfElements.add( new RtfChunk( rtfDoc, (Chunk) element ) ); } } else { rtfElements.add( new RtfChunk( rtfDoc, (Chunk) element ) ); } break; case Element.PHRASE: rtfElements.add( new RtfPhrase( rtfDoc, (Phrase) element ) ); break; case Element.PARAGRAPH: rtfElements.add( new RtfParagraph( rtfDoc, (Paragraph) element ) ); break; case Element.ANCHOR: rtfElements.add( new RtfAnchor( rtfDoc, (Anchor) element ) ); break; case Element.ANNOTATION: rtfElements.add( new RtfAnnotation( rtfDoc, (Annotation) element ) ); break; case Element.IMGRAW: case Element.IMGTEMPLATE: case Element.JPEG: rtfElements.add( new RtfImage( rtfDoc, (Image) element ) ); break; case Element.AUTHOR: case Element.SUBJECT: case Element.KEYWORDS: case Element.TITLE: case Element.PRODUCER: case Element.CREATIONDATE: rtfElements.add( new RtfInfoElement( rtfDoc, (Meta) element ) ); break; case Element.LIST: rtfElements.add( new RtfList( rtfDoc, (List) element ) ); // TODO: Testing break; case Element.LISTITEM: rtfElements.add( new RtfListItem( rtfDoc, (ListItem) element ) ); // TODO: Testing break; case Element.SECTION: rtfElements.add( new RtfSection( rtfDoc, (Section) element ) ); break; case Element.CHAPTER: rtfElements.add( new RtfChapter( rtfDoc, (Chapter) element ) ); break; case Element.TABLE: if ( element instanceof Table ) { rtfElements.add( new PatchRtfTable( rtfDoc, (Table) element ) ); } else { rtfElements.add( new PatchRtfTable( rtfDoc, ( (SimpleTable) element ).createTable() ) ); } break; case Element.PTABLE: if ( element instanceof PdfPTable ) { rtfElements.add( new PatchRtfTable( rtfDoc, (PdfPTable) element ) ); } else { rtfElements.add( new PatchRtfTable( rtfDoc, ( (SimpleTable) element ).createTable() ) ); } break; } return rtfElements.toArray( new RtfBasicElement[rtfElements.size()] ); }
Example #18
Source File: ExtendedTableCellTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Extended borders for Table Cells. * * */ @Test public void main() throws Exception { Document document = new Document(); RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ExtendedTableCell.rtf")); document.open(); Table table = new Table(3); // Create a simple RtfCell with a dotted border. RtfCell cellDotted = new RtfCell("Dotted border"); cellDotted.setBorders(new RtfBorderGroup(Rectangle.BOX, RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0))); // Create a simple RtfCell with an embossed border. RtfCell cellEmbossed = new RtfCell("Embossed border"); cellEmbossed.setBorders(new RtfBorderGroup(Rectangle.BOX, RtfBorder.BORDER_EMBOSS, 1, new Color(0, 0, 0))); // Create a simple RtfCell with no border. RtfCell cellNoBorder = new RtfCell("No border"); cellNoBorder.setBorders(new RtfBorderGroup()); cellNoBorder.setRowspan(2); // Create a simple RtfCell that only has a border // on the bottom side. RtfCell bottomBorder = new RtfCell("Bottom border"); bottomBorder.setBorders(new RtfBorderGroup(Rectangle.BOTTOM, RtfBorder.BORDER_SINGLE, 2, new Color(255, 0, 0))); // Create a simple RtfCell that has different borders // on the left and bottom sides. RtfCell mixedBorder = new RtfCell("Mixed border"); RtfBorderGroup mixedBorders = new RtfBorderGroup(); mixedBorders.addBorder(Rectangle.RIGHT, RtfBorder.BORDER_DOUBLE_WAVY, 2, Color.GREEN); mixedBorders.addBorder(Rectangle.BOTTOM, RtfBorder.BORDER_DOT_DASH, 1, Color.BLUE); mixedBorder.setBorders(mixedBorders); // Add the cells to the table table.addCell(cellDotted); table.addCell(cellEmbossed); table.addCell(cellNoBorder); table.addCell(bottomBorder); table.addCell(mixedBorder); document.add(table); document.close(); }
Example #19
Source File: ExtendedHeaderFooterTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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(); }
Example #20
Source File: RtfTOCandCellbordersTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Creates an RTF document with a TOC and Table with special Cellborders. * * */ @Test public void main() throws Exception { Document document = new Document(); RtfWriter2 writer2 = RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("toc.rtf")); writer2.setAutogenerateTOCEntries(true); document.open(); Paragraph para = new Paragraph(); para.add(new RtfTableOfContents("RIGHT CLICK AND HERE AND SELECT \"UPDATE FIELD\" TO UPDATE.")); document.add(para); Paragraph par = new Paragraph("This is some sample content."); Chapter chap1 = new Chapter("Chapter 1", 1); chap1.add(par); Chapter chap2 = new Chapter("Chapter 2", 2); chap2.add(par); document.add(chap1); document.add(chap2); for (int i = 0; i < 300; i++) { if (i == 158) { document.add(new RtfTOCEntry("This is line 158.")); } document.add(new Paragraph("Line " + i)); } document.add(new RtfTOCEntry("Cell border demonstration")); Table table = new Table(3); RtfCell cellDotted = new RtfCell("Dotted border"); cellDotted.setBorders(new RtfBorderGroup(Rectangle.BOX, RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0))); RtfCell cellEmbossed = new RtfCell("Embossed border"); cellEmbossed.setBorders(new RtfBorderGroup(Rectangle.BOX, RtfBorder.BORDER_EMBOSS, 1, new Color(0, 0, 0))); RtfCell cellNoBorder = new RtfCell("No border"); cellNoBorder.setBorders(new RtfBorderGroup()); table.addCell(cellDotted); table.addCell(cellEmbossed); table.addCell(cellNoBorder); document.add(table); document.close(); }
Example #21
Source File: RepeatingTableTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Shows how a table is split if it doesn't fit the page. */ @Test public void main() throws Exception { // creation of the document with a certain size and certain margins Document document = new Document(PageSize.A4.rotate(), 50, 50, 50, 50); // creation of the different writers PdfWriter.getInstance(document, PdfTestBase.getOutputStream("repeatingtable.pdf")); // we add some meta information to the document document.addAuthor("Alan Soukup"); document.addSubject("This is the result of a Test."); document.open(); Table datatable = new Table(10); int headerwidths[] = { 10, 24, 12, 12, 7, 7, 7, 7, 7, 7 }; datatable.setWidths(headerwidths); datatable.setWidth(100); datatable.setPadding(3); // the first cell spans 10 columns Cell cell = new Cell(new Phrase("Administration -System Users Report", FontFactory.getFont( FontFactory.HELVETICA, 24, Font.BOLD))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setLeading(30); cell.setColspan(10); cell.setBorder(Rectangle.NO_BORDER); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); datatable.addCell(cell); // These cells span 2 rows datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(1); datatable.addCell("User Id"); datatable.addCell("Name\nAddress"); datatable.addCell("Company"); datatable.addCell("Department"); datatable.addCell("Admin"); datatable.addCell("Data"); datatable.addCell("Expl"); datatable.addCell("Prod"); datatable.addCell("Proj"); datatable.addCell("Online"); // this is the end of the table header datatable.endHeaders(); datatable.getDefaultCell().setBorderWidth(1); for (int i = 1; i < 30; i++) { datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell("myUserId"); datatable .addCell("Somebody with a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long long name"); datatable.addCell("No Name Company"); datatable.addCell("D" + i); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell("No"); datatable.addCell("Yes"); datatable.addCell("No"); datatable.addCell("Yes"); datatable.addCell("No"); datatable.addCell("Yes"); } document.add(new Paragraph("com.lowagie.text.Table - Cells split")); document.add(datatable); document.newPage(); document.add(new Paragraph("com.lowagie.text.pdf.PdfPTable - Cells split\n\n")); datatable.setConvert2pdfptable(true); document.add(datatable); document.newPage(); document.add(new Paragraph("com.lowagie.text.Table - Cells kept together")); datatable.setConvert2pdfptable(false); datatable.setCellsFitPage(true); document.add(datatable); document.newPage(); document.add(new Paragraph("com.lowagie.text.pdf.PdfPTable - Cells kept together\n\n")); datatable.setConvert2pdfptable(true); document.add(datatable); // we close the document document.close(); }
Example #22
Source File: MPdfWriter.java From javamelody with Apache License 2.0 | 4 votes |
/** * Ecrit le pdf. * * @param table * MBasicTable * @param out * OutputStream * @throws IOException * e */ protected void writePdf(final MBasicTable table, final OutputStream out) throws IOException { try { // step 1: creation of a document-object final Rectangle pageSize = landscape ? PageSize.A4.rotate() : PageSize.A4; final Document document = new Document(pageSize, 50, 50, 50, 50); // step 2: we create a writer that listens to the document and directs a PDF-stream to out createWriter(table, document, out); // we add some meta information to the document, and we open it document.addAuthor(System.getProperty("user.name")); document.addCreator("JavaMelody"); final String title = buildTitle(table); if (title != null) { document.addTitle(title); } document.open(); // ouvre la boîte de dialogue Imprimer de Adobe Reader // if (writer instanceof PdfWriter) { // ((PdfWriter) writer).addJavaScript("this.print(true);", false); // } // table final Table datatable = new Table(table.getColumnCount()); datatable.setCellsFitPage(true); datatable.setPadding(4); datatable.setSpacing(0); // headers renderHeaders(table, datatable); // data rows renderList(table, datatable); document.add(datatable); // we close the document document.close(); } catch (final DocumentException e) { // on ne peut déclarer d'exception autre que IOException en throws throw new IOException(e); } }
Example #23
Source File: PdfWriter.java From itext2 with GNU Lesser General Public License v3.0 | 2 votes |
/** * Checks if a <CODE>Table</CODE> fits the current page of the <CODE>PdfDocument</CODE>. * * @param table the table that has to be checked * @param margin a certain margin * @return <CODE>true</CODE> if the <CODE>Table</CODE> fits the page, <CODE>false</CODE> otherwise. */ public boolean fitsPage(Table table, float margin) { return pdf.bottom(table) > pdf.indentBottom() + margin; }
Example #24
Source File: PdfWriter.java From gcs with Mozilla Public License 2.0 | 2 votes |
/** * Checks if a <CODE>Table</CODE> fits the current page of the <CODE>PdfDocument</CODE>. * * @param table the table that has to be checked * @param margin a certain margin * @return <CODE>true</CODE> if the <CODE>Table</CODE> fits the page, <CODE>false</CODE> * otherwise. */ public boolean fitsPage(Table table, float margin) { return pdf.bottom(table) > pdf.indentBottom() + margin; }
Example #25
Source File: PdfWriter.java From MesquiteCore with GNU Lesser General Public License v3.0 | 2 votes |
/** * Checks if a <CODE>Table</CODE> fits the current page of the <CODE>PdfDocument</CODE>. * * @param table the table that has to be checked * @return <CODE>true</CODE> if the <CODE>Table</CODE> fits the page, <CODE>false</CODE> otherwise. */ public boolean fitsPage(Table table) { return fitsPage(table, 0); }
Example #26
Source File: PdfWriter.java From MesquiteCore with GNU Lesser General Public License v3.0 | 2 votes |
/** * Checks if a <CODE>Table</CODE> fits the current page of the <CODE>PdfDocument</CODE>. * * @param table the table that has to be checked * @param margin a certain margin * @return <CODE>true</CODE> if the <CODE>Table</CODE> fits the page, <CODE>false</CODE> otherwise. */ public boolean fitsPage(Table table, float margin) { return pdf.bottom(table) > pdf.indentBottom() + margin; }
Example #27
Source File: PdfWriter.java From MesquiteCore with GNU Lesser General Public License v3.0 | 2 votes |
/** * Gets a pre-rendered table. * (Contributed by [email protected]) * @param table Contains the table definition. Its contents are deleted, after being pre-rendered. * @return a PdfTable */ public PdfTable getPdfTable(Table table) { return pdf.getPdfTable(table, true); }
Example #28
Source File: PdfWriter.java From MesquiteCore with GNU Lesser General Public License v3.0 | 2 votes |
/** * Sometimes it is necessary to know where the just added <CODE>Table</CODE> ends. * * For instance to avoid to add another table in a page that is ending up, because * the new table will be probably splitted just after the header (it is an * unpleasant effect, isn't it?). * * Added on September 8th, 2001 * by Francesco De Milato * [email protected] * @param table the <CODE>Table</CODE> * @return the bottom height of the just added table */ public float getTableBottom(Table table) { return pdf.bottom(table) - pdf.indentBottom(); }
Example #29
Source File: PdfWriter.java From gcs with Mozilla Public License 2.0 | 2 votes |
/** * Checks if a <CODE>Table</CODE> fits the current page of the <CODE>PdfDocument</CODE>. * * @param table the table that has to be checked * @return <CODE>true</CODE> if the <CODE>Table</CODE> fits the page, <CODE>false</CODE> * otherwise. */ public boolean fitsPage(Table table) { return fitsPage(table, 0); }
Example #30
Source File: PdfDocument.java From MesquiteCore with GNU Lesser General Public License v3.0 | 2 votes |
/** * Gets a PdfTable object * (contributed by [email protected]) * @param table a high level table object * @param supportRowAdditions * @return returns a PdfTable object * @see PdfWriter#getPdfTable(Table) */ PdfTable getPdfTable(Table table, boolean supportRowAdditions) { return new PdfTable(table, indentLeft(), indentRight(), indentTop() - currentHeight, supportRowAdditions); }