List of usage examples for com.itextpdf.text.pdf PdfPCell setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
From source file:net.yuvideo.voipRacuni.classes.PrintPageListing.java
public void createListing() { document.open();// w ww . j av a 2 s. co m PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); //HEADERS PdfPCell cell = new PdfPCell(new Phrase("IZVETAJ-LISTING", fontBold)); cell.setColspan(5); cell.setBorder(0); table.addCell(cell); //HEADER KORISNIK String korisnik; if (user.isFirma()) { korisnik = user.getNazivFirme(); } else { korisnik = user.getIme(); } cell = new PdfPCell( new Phrase(String.format("%s - %s - %s", korisnik, user.getBrojTelefona(), this.period), font)); cell.setColspan(5); cell.setBorder(0); table.addCell(cell); //HEADER TABLE PdfPCell cellH1 = new PdfPCell(new Phrase("br.", fontBold)); cellH1.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cellH1).setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cellH2 = new PdfPCell(new Phrase("Pozivani broj", fontBold)); cellH2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cellH2).setHorizontalAlignment(1); PdfPCell cellH3 = new PdfPCell(new Phrase("Destinacija", fontBold)); cellH3.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cellH3).setHorizontalAlignment(1); PdfPCell cellH4 = new PdfPCell(new Phrase("Vreme", fontBold)); cellH4.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cellH4).setHorizontalAlignment(1); PdfPCell cellH5 = new PdfPCell(new Phrase("Trajanje poziva", fontBold)); cellH5.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cellH5).setHorizontalAlignment(1); PdfPCell cellIzvestaj; int ukupno = 0; for (izvestajPotrosnje izvestaj : listing) { //potrosnja ukupno //Redni broj cellIzvestaj = new PdfPCell(new Phrase(String.valueOf(izvestaj.br), font)); cellIzvestaj.setHorizontalAlignment(1); cellIzvestaj.setVerticalAlignment(5); table.addCell(cellIzvestaj); //Pozivani broj cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getSource(), font)); cellIzvestaj.setHorizontalAlignment(1); cellIzvestaj.setVerticalAlignment(5); table.addCell(cellIzvestaj); //Destinacija cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getDestination(), font)); cellIzvestaj.setHorizontalAlignment(1); cellIzvestaj.setVerticalAlignment(5); table.addCell(cellIzvestaj); //Vreme cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getDatumPoziva(), font)); cellIzvestaj.setHorizontalAlignment(1); cellIzvestaj.setVerticalAlignment(5); table.addCell(cellIzvestaj); //trajanje poziva cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getTrajanje(), font)); cellIzvestaj.setHorizontalAlignment(1); cellIzvestaj.setVerticalAlignment(5); table.addCell(cellIzvestaj); ukupno = izvestaj.getUkupno_poziv(); } PdfPCell footer = new PdfPCell(new Phrase( String.format("Ukupno: %s", LocalTime.MIN.plusSeconds(ukupno).toString()), fontLargeBold)); footer.setColspan(5); footer.setHorizontalAlignment(2); footer.setBorder(0); table.addCell(footer); try { document.add(table); } catch (DocumentException ex) { Logger.getLogger(PrintPageListing.class.getName()).log(Level.SEVERE, null, ex); } document.close(); }
From source file:nl.avans.C3.BusinessLogic.InvoiceService.java
private void insertCell(PdfPTable table, String text, int align, int colspan, Font font) { //create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); //set the cell alignment cell.setHorizontalAlignment(align); //set the cell column span in case you want to merge two or more cells cell.setColspan(colspan);/*from w ww . ja va2 s.c o m*/ //in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } //add the call to the table table.addCell(cell); }
From source file:nl.ctmm.trait.proteomics.qcviewer.utils.ReportPDFExporter.java
License:Apache License
/** * Create the metrics values table for given report unit. This table will be added to the PDF document. * * @param allMetricsMap map of all QC metrics - keys and description. * @param reportUnit Report unit for which to create the metrics values table. * @return PDF table containing metrics values of the report unit. *//*ww w . j a v a 2s . co m*/ private static PdfPTable createMetricsValuesTable(final Map<String, String> allMetricsMap, final ReportUnit reportUnit) { /* * TODO: Column size, font size and spacing of the metrics value table. */ // Create columns names. final String columnNames[] = { Constants.METRICS_ID_COLUMN_NAME, Constants.DESCRIPTION_COLUMN_NAME, Constants.VALUE_COLUMN_NAME, Constants.METRICS_ID_COLUMN_NAME, Constants.DESCRIPTION_COLUMN_NAME, Constants.VALUE_COLUMN_NAME, }; //Creation of table object. final PdfPTable table = new PdfPTable(columnNames.length); try { table.setSpacingBefore(TABLE_SPACING); //Set the table width. table.setTotalWidth(COLUMN_WIDTHS); table.setLockedWidth(true); //Add table header. for (int i = 0; i < TOTAL_COLUMNS; ++i) { final PdfPCell headerCell = new PdfPCell(new Phrase(columnNames[i], Constants.TABLE_HEADER_FONT)); headerCell.setBackgroundColor(BaseColor.RED); headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(headerCell); } //Read metricsValues corresponding to reportUnit. final Map<String, String> metricsValues = reportUnit.getMetricsValues(); //TODO: Split allMetricsMap in two parts such that sorted rows are properly added in the table. //Get all keys final Object[] keyArray = allMetricsMap.keySet().toArray(); //get all values final Object[] valueArray = allMetricsMap.values().toArray(); //Calculate halfSize final int halfSize = keyArray.length / 2; for (int i = 0; i < halfSize; ++i) { addMetric(keyArray[i].toString(), valueArray[i].toString(), metricsValues, table); addMetric(keyArray[i + halfSize].toString(), valueArray[i + halfSize].toString(), metricsValues, table); } } catch (final DocumentException e) { //DocumentException signals that an error has occurred in a Document. logger.log(Level.SEVERE, String.format(PDF_TABLE_EXCEPTION_MESSAGE, reportUnit.getMsrunName()), e); } return table; }
From source file:nl.ctmm.trait.proteomics.qcviewer.utils.ReportPDFExporter.java
License:Apache License
/** * Add a metric to the pdf table./*from ww w . j ava 2 s .c om*/ * * @param key the metric key. * @param description the metric description. * @param metricsValues the metric values. * @param table the pdf table. */ private static void addMetric(final String key, final String description, final Map<String, String> metricsValues, final PdfPTable table) { final String value = (metricsValues != null) ? metricsValues.get(key) : Constants.NOT_AVAILABLE_STRING; // Populate content in table cell. table.addCell(new Phrase(key, Constants.TABLE_CONTENT_FONT)); table.addCell(new Phrase(description, Constants.TABLE_CONTENT_FONT)); final PdfPCell valueCell = new PdfPCell(new Phrase(value, Constants.TABLE_CONTENT_FONT)); valueCell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(valueCell); }
From source file:nl.infosys.hartigehap.barSystem.domain.Bon.java
/** * create the table for the PDF//w w w.ja v a 2 s. c o m * * @return table */ private Paragraph table() { Paragraph par = new Paragraph(); PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); PdfPCell cell; Font fontbold = FontFactory.getFont("Times-Roman", 13, Font.BOLD); Font normal = FontFactory.getFont("Times-Roman", 13); table.addCell(new Phrase("Product:", fontbold)); table.addCell(new Phrase("Prijs:", fontbold)); table.addCell(new Phrase("Aantal:", fontbold)); table.addCell(new Phrase("Totaalprijs:", fontbold)); for (ImmutableProduct product : bestelling.getProducten()) { table.addCell(new Phrase(product.getNaam(), normal)); table.addCell(new Phrase(product.getPrijsFormat(), normal)); table.addCell(new Phrase(String.valueOf(product.getAantal()), normal)); cell = new PdfPCell(new Phrase(product.getTotaalPrijsFormat(), normal)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); cell.setPaddingBottom(5); table.addCell(cell); } cell = new PdfPCell(new Phrase("Excl. BTW", fontbold)); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getPrijsExclBtwFormat(), fontbold)); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase("BTW 21%", fontbold)); cell.setBorder(0); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getBtwBedragFormat(), fontbold)); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("Incl. BTW", fontbold)); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getTotaalPrijsFormat(), fontbold)); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.TOP); table.addCell(cell); par.add(table); return par; }
From source file:nl.infosys.hartigehap.barSystem.presentation.BonGui.java
private Paragraph table() { Paragraph par = new Paragraph(); PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100);//from w ww.jav a 2s . c o m table.getDefaultCell().setBorder(0); PdfPCell cell; Font fontbold = FontFactory.getFont("Times-Roman", 13, Font.BOLD); Font normal = FontFactory.getFont("Times-Roman", 13); table.addCell(new Phrase("Product:", fontbold)); table.addCell(new Phrase("Prijs:", fontbold)); table.addCell(new Phrase("Aantal:", fontbold)); table.addCell(new Phrase("Totaalprijs:", fontbold)); for (ImmutableProduct product : bestelling.getProducten()) { table.addCell(new Phrase(product.getNaam(), normal)); table.addCell(new Phrase(product.getPrijsFormat(), normal)); table.addCell(new Phrase(String.valueOf(product.getAantal()), normal)); cell = new PdfPCell(new Phrase(product.getTotaalPrijsFormat(), normal)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); cell.setPaddingBottom(5); table.addCell(cell); } cell = new PdfPCell(new Phrase("Excl. BTW", fontbold)); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getPrijsExclBtwFormat(), fontbold)); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase("BTW 21%", fontbold)); cell.setBorder(0); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getBtwBedragFormat(), fontbold)); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("Incl. BTW", fontbold)); cell.setBorder(Rectangle.TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(bestelling.getTotaalPrijsFormat(), fontbold)); cell.setColspan(3); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.TOP); table.addCell(cell); par.add(table); return par; }
From source file:nwk.com.br.documents.OrcamentoPdf.java
private PdfPTable dadosCliente(Orcamento orcamento) throws Exception { cliente = clientedao.select(orcamento.getIdCliente()); PdfPTable dadosCliente = new PdfPTable(new float[] { 0.35f, 0.35f, 0.3f }); dadosCliente.setWidthPercentage(90.0f);//seta o tamanho da tabela em relaao ao documento dadosCliente.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);//alinha os dados a esquerda dadosCliente.getDefaultCell().setBorder(0);//retira a borda //Cria uma cedula da tabela que pegara tres colunas PdfPCell nomeCli = new PdfPCell(new Paragraph("Nome: " + cliente.getNome(), f)); nomeCli.setColspan(3);//from w ww . j a v a2 s. com nomeCli.setHorizontalAlignment(Element.ALIGN_LEFT); nomeCli.setBorder(0); dadosCliente.addCell(nomeCli); //formatao do celular e do telefone String celular = new String(); String telefone = new String(); celular = "(" + cliente.getCelular().substring(0, 2) + ") " + cliente.getCelular().substring(2); telefone = "(" + cliente.getTelefone().substring(0, 2) + ") " + cliente.getCelular().substring(2); //adciona os demais dados do cliente a tabela dadosCliente.addCell("E-mail: " + cliente.getEmail()); dadosCliente.addCell("Telefone: " + telefone); dadosCliente.addCell("Celular: " + celular); dadosCliente.addCell("Rua: " + cliente.getRua() + ", " + cliente.getNumero()); dadosCliente.addCell("Bairro: " + cliente.getBairro()); dadosCliente.addCell("Complemento: " + cliente.getComplemento()); dadosCliente.addCell(cliente.getCidade() + "/" + cliente.getEstado()); dadosCliente.addCell(cliente.getCep()); return dadosCliente; }
From source file:nwk.com.br.documents.OrcamentoPdf.java
private PdfPTable dadosPagamento(Orcamento orcamento) throws Exception { Font fontTotal = new Font(Font.FontFamily.TIMES_ROMAN, 16); PdfPTable dPagamento = new PdfPTable(new float[] { 0.5f, 0.2f, 0.3f }); dPagamento.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento dPagamento.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); dPagamento.getDefaultCell().setBorder(0); //celula com espao em branco e com o Total PdfPCell spc = new PdfPCell(new Paragraph(" ")); PdfPCell total = new PdfPCell(new Paragraph("TOTAL: R$" + orcamento.getTotal(), fontTotal)); //alinha a celula total a esquerda total.setHorizontalAlignment(Element.ALIGN_RIGHT); spc.setColspan(3);//from w w w . jav a 2 s . co m total.setBorder(0); spc.setBorder(0); if (orcamento.getFormaPagamento().equals("0")) { dPagamento.addCell(new Paragraph("Forma de Pagamento: A vista - Dinheiro", f)); } else if (orcamento.getFormaPagamento().equals("1")) { dPagamento.addCell(new Paragraph("Forma de Pagamento: A vista - Carto", f)); } else if (orcamento.getFormaPagamento().equals("2")) { dPagamento.addCell(new Paragraph("Forma de Pagamento: Parcelado", f)); } dPagamento.addCell(new Paragraph("Desconto: R$" + orcamento.getDesconto(), f)); dPagamento.addCell(total); return dPagamento; }
From source file:nwk.com.br.documents.OrcamentoPdf.java
private PdfPTable dadosRodape(Orcamento orcamento) throws Exception { //tabela que pega com 100% do tamanho do arquivo, alinhada no centro com tres colunas e sem bordas PdfPTable rodape = new PdfPTable(new float[] { 0.5f, 0.2f, 0.3f }); rodape.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento rodape.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); rodape.getDefaultCell().setBorder(0); PdfPCell obs = new PdfPCell(new Paragraph("\n\n Observaes:\n" + orcamento.getObservacoes(), f)); PdfPCell ass = new PdfPCell(new Paragraph("\n\n_________________________\nAssinatura", f)); Font fonteAviso = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLDITALIC); PdfPCell spc = new PdfPCell(new Paragraph(" ")); PdfPCell aviso = new PdfPCell(new Paragraph( "AGRADEEMOS A PREFERNCIA\nORAMENTO VALIDO SOMENTE PARA O DIA DE SUA CRIAO!", fonteAviso)); aviso.setHorizontalAlignment(Element.ALIGN_CENTER); obs.setHorizontalAlignment(Element.ALIGN_LEFT); ass.setHorizontalAlignment(Element.ALIGN_CENTER); obs.setBorder(0);/*from www .j a v a 2s .c o m*/ ass.setBorder(0); spc.setBorder(0); aviso.setBorder(0); spc.setColspan(3); aviso.setColspan(3); rodape.addCell(obs); rodape.addCell(new Paragraph(" ")); rodape.addCell(ass); rodape.addCell(spc); rodape.addCell(spc); rodape.addCell(spc); rodape.addCell(spc); rodape.addCell(aviso); //rodape.setExtendLastRow(true); //cria uma nova celula que recebe a tabela anterior PdfPCell otherCell = new PdfPCell(rodape); otherCell.setBorder(0); otherCell.setVerticalAlignment(Element.ALIGN_BOTTOM); otherCell.setHorizontalAlignment(Element.ALIGN_CENTER); //cria uma nova tabela que recebe a celula otherCell PdfPTable rodape2 = new PdfPTable(new float[] { 1.0f }); rodape2.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento rodape2.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); rodape2.getDefaultCell().setBorder(0); //estende a tabela at o fim da pagina, como o alinhamento horizontal dela bottom, ela fica toda no rodape rodape2.addCell(otherCell); rodape2.setExtendLastRow(true); return rodape2; }
From source file:om.edu.squ.squportal.portlet.tsurvey.dao.pdf.TeachingSurveyPdfImpl.java
License:Open Source License
/** * //from w ww . j a v a 2s . c o m * method name : getPdfCell * @param content * @param rowSpan * @param colSpan * @return * TeachingSurveyPdfImpl * return type : PdfPCell * * purpose : * * Date : Feb 22, 2016 12:52:28 PM */ private PdfPCell getPdfCell(String content, int rowSpan, int colSpan, Font font, String txtAlign) { PdfPCell cell = new PdfPCell(new Phrase(content, font)); if (rowSpan == 0 && colSpan != 0) { cell.setColspan(colSpan); } if (rowSpan != 0 && colSpan == 0) { cell.setRowspan(rowSpan); } if (txtAlign.equals(Constants.CENTER)) cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (null == txtAlign || txtAlign.equals(Constants.LEFT)) cell.setHorizontalAlignment(Element.ALIGN_LEFT); if (txtAlign.equals(Constants.RIGHT)) cell.setHorizontalAlignment(Element.ALIGN_RIGHT); return cell; }