List of usage examples for com.itextpdf.text.pdf PdfPTable setWidthPercentage
public void setWidthPercentage(final float widthPercentage)
From source file:org.apache.jmeter.visualizers.CreateReport.java
License:Apache License
/** * Creates a table; widths are set with setWidths(). * @return a PdfPTable/*from w ww. j a va 2 s . co m*/ * @throws DocumentException */ public PdfPTable createTable1() throws DocumentException { PdfPTable table = new PdfPTable(7); table.setWidthPercentage(570 / 5.23f); table.setWidths(new int[] { 4, 4, 3, 3, 3, 3, 5 }); PdfPCell cell = null; for (int k = 0; k < 10; k++) { if (k != 5 && k != 8 && k != 9) { cell = new PdfPCell(new Phrase(JMeterUtils.getResString(COLUMNS[k]), headerFont)); BaseColor BC = new BaseColor(164, 188, 196); cell.setBackgroundColor(BC); cell.setColspan(1); table.addCell(cell); } } for (int l = 0; l < model.getRowCount(); l++) //row count does not include table headers for (int k = 0; k < 10; k++) { if (k != 5 && k != 8 && k != 9) { cell = new PdfPCell(new Phrase(model.getValueAt(l, k).toString(), rowFont)); cell.setGrayFill(2); table.addCell(cell); } } return table; /* original basic statements PdfPTable table = new PdfPTable(3); table.setWidthPercentage(288 / 5.23f); table.setWidths(new int[]{2, 1, 1}); PdfPCell cell; cell = new PdfPCell(new Phrase("Table 1")); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase("Cell with rowspan 2")); cell.setRowspan(2); table.addCell(cell); table.addCell("row 1; cell 1"); table.addCell("row 1; cell 2"); table.addCell("row 2; cell 1"); table.addCell("row 2; cell 2"); return table; */ }
From source file:org.apache.jmeter.visualizers.CreateReport.java
License:Apache License
public PdfPTable createTable2() throws DocumentException { PdfPTable table = new PdfPTable(4); table.setWidthPercentage(570 / 5.23f); table.setWidths(new int[] { 1, 2, 1, 3 }); PdfPCell cell = null;//from ww w.j a v a 2 s . c om for (int k = 0; k < 4; k++) { { cell = new PdfPCell(new Phrase(model2.getColumnName(k), headerFont)); BaseColor BC = new BaseColor(164, 188, 196); cell.setBackgroundColor(BC); cell.setColspan(1); table.addCell(cell); } } for (int l = 0; l < model2.getRowCount(); l++) //row count does not include table headers for (int k = 0; k < 4; k++) { cell = new PdfPCell(new Phrase(model2.getValueAt(l, k).toString(), rowFont)); cell.setGrayFill(2); table.addCell(cell); } return table; }
From source file:org.bonitasoft.studio.migration.utils.PDFMigrationReportWriter.java
License:Open Source License
private void createTable(Paragraph paragrah) throws MalformedURLException, IOException, DocumentException { PdfPTable table = new PdfPTable(6); table.setHeaderRows(0);/*from w w w. j a v a2s . c o m*/ table.setWidthPercentage(95f); PdfPCell c1 = new PdfPCell(new Phrase(Messages.elementType)); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(Messages.name)); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(Messages.property)); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(Messages.information)); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(Messages.status)); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(Messages.reviewed)); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); List<Change> changes = report.getChanges(); if (viewer != null) { for (int i = 0; i < changes.size(); i++) { addTableRow(table, (Change) viewer.getElementAt(i)); } } else { for (Change change : changes) { addTableRow(table, change); } } table.setWidths(new int[] { 3, 3, 3, 5, 2, 2 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setComplete(true); paragrah.add(table); }
From source file:org.cidte.sii.negocio.PDFWriter.java
public void writePDF(ArrayList<Writable> list, String directorio, String nombre, java.awt.Image image) throws DocumentException, FileNotFoundException, BadElementException, IOException { Document doc = new Document(); PdfWriter docWriter;/*from ww w .j av a2s .c o m*/ // special font sizes Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12); // file path String path = directorio + nombre + ".pdf"; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(new File(path))); // document header attributes doc.addAuthor("sii"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("sii"); doc.addTitle(nombre); doc.setPageSize(PageSize.LETTER); // open document doc.open(); Image img = Image.getInstance(image, null); img.setAlignment(Element.ALIGN_LEFT); doc.add(img); // create a paragraph Paragraph paragraph = new Paragraph("iText is a library that allows you to create and " + "manipulate PDF documents. It enables developers looking to enhance web and other " + "applications with dynamic PDF document generation and/or manipulation."); // create PDF table with the given widths PdfPTable table = new PdfPTable(list.get(0).getNames().length); // set table width a percentage of the page width table.setWidthPercentage(100); table.setSpacingBefore(10f); // Space before table table.setSpacingAfter(10f); // Space after table // insert column headings String[] headings = list.get(0).getNames(); for (String heading : headings) { insertCell(table, heading, Element.ALIGN_CENTER, 1, bfBold12); } table.setHeaderRows(1); // insert the data for (int i = 0; i < list.size(); i++) { Writable w = list.get(i); Object[] arr = w.getAsArray(); for (int j = 0; j < arr.length; j++) { // arr[j] insertCell(table, arr[j].toString(), Element.ALIGN_LEFT, 1, bf12); } } // insert an empty row // insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12); // add the PDF table to the paragraph paragraph.add(table); // add the paragraph to the document doc.add(paragraph); // close the document doc.close(); // close the writer docWriter.close(); }
From source file:org.dspace.disseminate.CitationDocument.java
/** * Takes a DSpace {@link Bitstream} and uses its associated METADATA to * create a cover page./*www .ja v a2s .c om*/ * * @param cDoc The cover page document to add cited information to. * @param writer * @param cMeta * METADATA retrieved from the parent collection. * @throws IOException * @throws DocumentException */ private void generateCoverPage(Document cDoc, PdfWriter writer, CitationMeta cMeta) throws DocumentException { cDoc.open(); writer.setCompressionLevel(0); Item item = cMeta.getItem(); //Set up some fonts Font helv26 = FontFactory.getFont(FontFactory.HELVETICA, 26f, BaseColor.BLACK); Font helv16 = FontFactory.getFont(FontFactory.HELVETICA, 16f, BaseColor.BLACK); Font helv12 = FontFactory.getFont(FontFactory.HELVETICA, 12f, BaseColor.BLACK); Font helv12_italic = FontFactory.getFont(FontFactory.HELVETICA_OBLIQUE, 12f, BaseColor.BLACK); Font helv11_bold = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 11f, BaseColor.BLACK); Font helv9 = FontFactory.getFont(FontFactory.HELVETICA, 9f, BaseColor.BLACK); // 1 - Header: // University Name // Repository Name repository.url Paragraph university = new Paragraph("The Ohio State University", helv11_bold); cDoc.add(university); PdfPTable repositoryTable = new PdfPTable(2); repositoryTable.setWidthPercentage(100); Chunk repositoryName = new Chunk("Knowledge Bank", helv11_bold); PdfPCell nameCell = new PdfPCell(); nameCell.setBorderWidth(0); nameCell.addElement(repositoryName); Chunk repositoryURL = new Chunk("kb.osu.edu", helv11_bold); repositoryURL.setAnchor("http://kb.osu.edu"); PdfPCell urlCell = new PdfPCell(); urlCell.setHorizontalAlignment(Element.ALIGN_RIGHT); urlCell.setBorderWidth(0); urlCell.addElement(repositoryURL); repositoryTable.addCell(nameCell); repositoryTable.addCell(urlCell); repositoryTable.setSpacingAfter(5); cDoc.add(repositoryTable); // Line Separator LineSeparator lineSeparator = new LineSeparator(); cDoc.add(lineSeparator); // 2 - Bread Crumbs // Community Name Collection Name PdfPTable breadcrumbTable = new PdfPTable(2); breadcrumbTable.setWidthPercentage(100); Chunk communityName = new Chunk(getOwningCommunity(item), helv9); PdfPCell commCell = new PdfPCell(); commCell.setBorderWidth(0); commCell.addElement(communityName); Chunk collectionName = new Chunk(getOwningCollection(item), helv9); PdfPCell collCell = new PdfPCell(); collCell.setHorizontalAlignment(Element.ALIGN_RIGHT); collCell.setBorderWidth(0); collCell.addElement(collectionName); breadcrumbTable.addCell(commCell); breadcrumbTable.addCell(collCell); breadcrumbTable.setSpacingBefore(5); breadcrumbTable.setSpacingAfter(5); cDoc.add(breadcrumbTable); // Line Separator cDoc.add(lineSeparator); // 3 - Metadata // date.issued // dc.title // dc.creator; dc.creator Paragraph dateIssued = new Paragraph(getFirstMetadata(item, "dc.date.issued"), helv12); dateIssued.setSpacingBefore(20); cDoc.add(dateIssued); Paragraph title = new Paragraph(item.getName(), helv26); title.setSpacingBefore(15); cDoc.add(title); Paragraph creators = new Paragraph(getAllMetadataSeperated(item, "dc.creator"), helv16); creators.setSpacingBefore(30); creators.setSpacingAfter(20); cDoc.add(creators); // Line Separator cDoc.add(lineSeparator); // 4 - Citation // dc.identifier.citation // dc.identifier.uri Paragraph citation = new Paragraph(getFirstMetadata(item, "dc.identifier.citation"), helv12); Chunk identifierChunk = new Chunk(getFirstMetadata(item, "dc.identifier.uri"), helv12); identifierChunk.setAnchor(getFirstMetadata(item, "dc.identifier.uri")); Paragraph identifier = new Paragraph(); identifier.add(identifierChunk); cDoc.add(citation); cDoc.add(identifier); // 5 - License // Downloaded from the Knowledge Bank, The Ohio State University's institutional repository Paragraph license = new Paragraph( "Downloaded from the Knowledge Bank, The Ohio State University's institutional repository", helv12_italic); license.setSpacingBefore(10); cDoc.add(license); cDoc.close(); }
From source file:org.fossa.rolp.util.LebPageHelper.java
License:Open Source License
@Override public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(2); table.setTotalWidth(527);/*from w ww . j av a 2 s . com*/ 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); }
From source file:org.fossa.rolp.util.PdfFormatHelper.java
License:Open Source License
private static PdfPTable prebuildHeaderTable() throws DocumentException { PdfPTable table = new PdfPTable(6); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100f); table.setWidths(new float[] { 0.12f, 0.2f, 0.15f, 0.2f, 0.2f, 0.08f }); return table; }
From source file:org.fossa.rolp.util.PdfFormatHelper.java
License:Open Source License
public static PdfPTable buildFooterVersetzungsvermerkLine(String versetzungsvermerk, Font footerFont) throws DocumentException { PdfPCell labelCell = new PdfPCell(new Phrase("Versetzungsvermerk", footerFont)); labelCell.setBorder(Rectangle.BOTTOM); labelCell.setBorderWidth(1f);/*from ww w. ja va 2 s .c o m*/ PdfPCell nameCell = new PdfPCell(new Phrase(versetzungsvermerk, footerFont)); nameCell.setBorder(Rectangle.BOTTOM); nameCell.setBorderWidth(1f); PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100f); table.addCell(labelCell); table.addCell(nameCell); table.setWidths(new float[] { 0.3f, 0.7f }); return table; }
From source file:org.fossa.rolp.util.PdfFormatHelper.java
License:Open Source License
public static PdfPTable buildFooterDatumLine(String datumString, Font footerFont) throws DocumentException { PdfPCell labelCell = new PdfPCell(new Phrase("Datum", footerFont)); labelCell.setBorder(Rectangle.BOTTOM); labelCell.setBorderWidth(1f);//from ww w . j a v a 2 s .c om PdfPCell nameCell = new PdfPCell(new Phrase(datumString, footerFont)); nameCell.setBorder(Rectangle.BOTTOM); nameCell.setBorderWidth(1f); PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100f); table.addCell(labelCell); table.addCell(nameCell); table.setWidths(new float[] { 0.3f, 0.7f }); return table; }
From source file:org.fossa.rolp.util.PdfFormatHelper.java
License:Open Source License
public static PdfPTable buildFooterDienstsiegelLine(Font footerFont) throws DocumentException { PdfPCell leftCell = new PdfPCell(new Phrase("", footerFont)); leftCell.setBorder(Rectangle.NO_BORDER); leftCell.setBorderWidth(1f);/* w ww.j a v a 2 s.c om*/ PdfPCell centerCell = new PdfPCell(new Phrase("Dienstsiegel der Schule", footerFont)); centerCell.setBorder(Rectangle.NO_BORDER); centerCell.setBorderWidth(1f); centerCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rightCell = new PdfPCell(new Phrase("", footerFont)); rightCell.setBorder(Rectangle.NO_BORDER); rightCell.setBorderWidth(1f); PdfPTable table = new PdfPTable(3); table.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.setWidthPercentage(100f); table.addCell(leftCell); table.addCell(centerCell); table.addCell(rightCell); table.setWidths(new float[] { 0.3f, 0.3f, 0.3f }); return table; }