List of usage examples for com.itextpdf.text.pdf PdfPTable setWidths
public void setWidths(final int relativeWidths[]) throws DocumentException
From source file:com.udec.utilidades.PdfTable.java
public PdfPTable tabla2(List<Nomina> no) throws DocumentException { //Instanciamos una tabla de 3 columnas PdfPTable tabla = new PdfPTable(4); tabla.setWidthPercentage(100);//from w ww. j a v a2 s.co m tabla.setWidths(new float[] { 1, 1, 1, 3 }); //Declaramos un objeto para manejar las celdas PdfPCell celda; celda = new PdfPCell(new Phrase("Codigo:")); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase("" + no.get(0).getEmpleadoCodigo().getCodigo())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Nombre:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getNombre())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Cedula:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getCedula())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Cargo:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getCargoCargoid().getCargo())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Dias Lab:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { dt = dtC.findBySingle2("periodoIdperiodo", no.get(0).getPeriodoIdperiodo(), "empleadoCodigo", no.get(0).getEmpleadoCodigo()); celda = new PdfPCell(new Phrase("" + dt.getDias())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Sueldo:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase("" + no.get(0).getEmpleadoCodigo().getSalario())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } return tabla; }
From source file:com.udec.utilidades.PdfTable.java
public PdfPTable firma() throws DocumentException { PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(100);/*from w w w . j a va 2 s. c o m*/ tabla.setWidths(new float[] { 2, 1, 2 }); //Declaramos un objeto para manejar las celdas PdfPCell celda; celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.BOTTOM); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.BOTTOM); tabla.addCell(celda); celda = new PdfPCell(new Phrase("JEFE ADMINISTRATIVO")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("EMPLEADO")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); return tabla; }
From source file:com.udec.utilidades.PdfTable.java
public PdfPTable tabla3(List<Nomina> no) throws DocumentException { //Instanciamos una tabla de 3 columnas PdfPTable tabla = new PdfPTable(4); tabla.setWidthPercentage(100);//ww w .ja v a 2s . c o m tabla.setWidths(new float[] { 1, 3, 1, 1 }); //Declaramos un objeto para manejar las celdas PdfPCell celda; celda = new PdfPCell(new Phrase("CODIGO")); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); tabla.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCION")); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); celda = new PdfPCell(new Phrase("VLR.DEVEN")); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); celda.setBorderWidth(1); celda.setVerticalAlignment(Element.ALIGN_TOP); tabla.addCell(celda); celda = new PdfPCell(new Phrase("VLR.DEDUC")); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); double totalDev = 0, totalDed = 0; for (Nomina nomina : no) { celda = new PdfPCell(new Phrase("" + nomina.getConceptoIdconcepto().getCodigo())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); celda = new PdfPCell(new Phrase("" + nomina.getConceptoIdconcepto().getConcepto())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (nomina.getConceptoIdconcepto().getTipo().equals("DEVENGADO")) { totalDev += nomina.getValor(); celda = new PdfPCell(new Phrase("" + nomina.getValor())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celda); } else { celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } if (nomina.getConceptoIdconcepto().getTipo().equals("DEDUCIDO")) { totalDed += nomina.getValor(); celda = new PdfPCell(new Phrase("" + nomina.getValor())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celda); } else { celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } } celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("TOTALES")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("" + totalDev)); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); celda.setBorder(Rectangle.TOP); tabla.addCell(celda); celda = new PdfPCell(new Phrase(" " + totalDed)); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); celda.setBorder(Rectangle.TOP); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("NETO A PAGAR")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase(" " + (totalDev - totalDed))); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celda); celda = new PdfPCell(new Phrase(" ")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); return tabla; }
From source file:com.vectorprint.report.itext.style.stylers.Table.java
License:Open Source License
private PdfPTable style(PdfPTable t) throws VectorPrintException { super.style(t, null); t.setWidthPercentage(getRelwidth()); try {/*from w w w . j a va2s. c om*/ float[] w = getWidths(); t.setWidths(w); t.setTotalWidth(w); t.setHeaderRows(getHeaderrows()); t.setFooterRows(getFooterrows()); } catch (DocumentException ex) { throw new VectorPrintException("number of widths differs from number of columns in table", ex); } return t; }
From source file:com.xumpy.itext.services.HeaderFooter.java
@Override public void onEndPage(PdfWriter writer, Document document) { PdfPTable header = new PdfPTable(3); try {/*from w w w .j a va 2 s. c o m*/ header.setWidths(new int[] { 24, 24, 24 }); header.setTotalWidth(527); header.setLockedWidth(true); header.getDefaultCell().setFixedHeight(20); header.getDefaultCell().setBorder(Rectangle.BOTTOM); for (PdfPCell cell : tableHeader) { cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); } header.writeSelectedRows(0, -1, 60, 803, writer.getDirectContent()); } catch (DocumentException ex) { Logger.getLogger(HeaderFooter.class.getName()).log(Level.SEVERE, null, ex); } PdfPTable footer = new PdfPTable(3); try { footer.setWidths(new int[] { 24, 24, 24 }); footer.setTotalWidth(527); footer.setLockedWidth(true); footer.getDefaultCell().setFixedHeight(20); footer.getDefaultCell().setBorder(Rectangle.BOTTOM); for (PdfPCell cell : tableFooter) { cell.setBorder(Rectangle.NO_BORDER); footer.addCell(cell); } footer.writeSelectedRows(0, -1, 60, 200, writer.getDirectContent()); } catch (DocumentException ex) { Logger.getLogger(HeaderFooter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.xumpy.itext.services.TimeSheet.java
public PdfPTable body(List<Jobs> jobs) throws DocumentException { BigDecimal totalHours = new BigDecimal(0); PdfPTable timesheets = new PdfPTable(5); timesheets.setWidths(new int[] { 25, 20, 10, 10, 48 }); SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy"); PdfPCell header1 = new PdfPCell(new Paragraph("Client")); PdfPCell header2 = new PdfPCell(new Paragraph("Date")); PdfPCell header3 = new PdfPCell(new Paragraph("Hours")); PdfPCell header4 = new PdfPCell(new Paragraph("Perc.")); PdfPCell header5 = new PdfPCell(new Paragraph("Remarks")); timesheets.addCell(header1);// w ww. j a v a 2 s .com timesheets.addCell(header2); timesheets.addCell(header3); timesheets.addCell(header4); timesheets.addCell(header5); for (Jobs job : jobs) { PdfPCell cell1 = new PdfPCell(new Paragraph(job.getJobsGroup().getName())); PdfPCell cell2 = new PdfPCell(new Paragraph(df.format(job.getJobDate()))); PdfPCell cell3 = new PdfPCell(new Paragraph(job.getWorkedHours().toString())); PdfPCell cell4 = new PdfPCell(new Paragraph(" ")); if (job.getPercentage() != null) { cell4 = new PdfPCell(new Paragraph(job.getPercentage().toString())); } PdfPCell cell5 = new PdfPCell(new Paragraph(job.getRemarks())); timesheets.addCell(cell1); timesheets.addCell(cell2); timesheets.addCell(cell3); timesheets.addCell(cell4); timesheets.addCell(cell5); totalHours = totalHours.add(job.getWorkedHours()); } PdfPCell footer1 = new PdfPCell(new Paragraph(" ")); PdfPCell footer2 = new PdfPCell(new Paragraph("Total Hours")); PdfPCell footer3 = new PdfPCell(new Paragraph(totalHours.toString())); PdfPCell footer4 = new PdfPCell(new Paragraph(" ")); PdfPCell footer5 = new PdfPCell(new Paragraph(" ")); PdfPCell footer6 = new PdfPCell(new Paragraph(" ")); PdfPCell footer7 = new PdfPCell(new Paragraph("Total Days")); PdfPCell footer8 = new PdfPCell(new Paragraph(totalHours.divide(new BigDecimal(8)).toString())); PdfPCell footer9 = new PdfPCell(new Paragraph(" ")); PdfPCell footer10 = new PdfPCell(new Paragraph(" ")); timesheets.addCell(footer1); timesheets.addCell(footer2); timesheets.addCell(footer3); timesheets.addCell(footer4); timesheets.addCell(footer5); timesheets.addCell(footer6); timesheets.addCell(footer7); timesheets.addCell(footer8); timesheets.addCell(footer9); timesheets.addCell(footer10); return timesheets; }
From source file:Control.ProcessaArq.java
public void gravaArquivoConsumoUnidades(ArrayList<Usuario> listaUsuario, String caminho) throws IOException, DocumentException { Document doc = null;//from w ww . j a v a 2 s . c o m OutputStream os = null; PdfWriter pdf = null; Paragraph p = new Paragraph(); Tratamento tempo = new Tratamento(); PdfPTable table = new PdfPTable(5); DecimalFormat df = new DecimalFormat("#####.##"); ArrayList<String> listaCidade = new ArrayList<String>(); String local = new String(); String informacao, tipo = new String(); Double soma, valorTotal, diferenca = 0.0; Usuario unidade = new Usuario(); ArrayList<Usuario> listaUnidades = new ArrayList<Usuario>(); /* if(banco.getConta().get(banco.getConta().size()-1).getDiferenca() > 0){ diferenca = banco.getConta().get(banco.getConta().size()-1).getDiferenca()/9; } else{ diferenca = 0.0; } */ for (int a = 0; a <= listaUsuario.size() - 1; a++) { if ((!listaCidade.contains(listaUsuario.get(a).getCidade()))) { listaCidade.add(listaUsuario.get(a).getCidade()); } } float[] headerwidths = { 30, 80, 35, 35, 25 }; // define a largura de cada coluna table.setWidths(headerwidths); caminho = localizaArquivo(false) + ".pdf"; try {//configuraes da pgina float fntSize, lineSpacing; fntSize = 8f; lineSpacing = 8f; doc = new Document(PageSize.A4.rotate(), 10, 10, 30, 40); os = new FileOutputStream(caminho); pdf.getInstance(doc, os); doc.open(); /* local = new String(); local = caminho +" "+ listaCidade.get(a) + ".pdf"; doc = new Document(PageSize.A4.rotate(), 10, 10, 30, 40); os = new FileOutputStream(local); pdf.getInstance(doc, os); doc.open(); */ //cabecalho da tabela table.getDefaultCell().setBorder(0); table.getDefaultCell().setBorder(0); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.getDefaultCell().setColspan(5); table.addCell(new Paragraph("CONSUMO POR UNIDADE " + banco.periodoFatura())); table.getDefaultCell().setBorder(0); table.getDefaultCell().setColspan(0); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); doc.add(table); for (int a = 0; a <= listaCidade.size() - 1; a++) { table = new PdfPTable(5); table.setWidths(headerwidths); table.getDefaultCell().setBorder(0); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.getDefaultCell().setBorder(1); table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(new Paragraph("Cidade")); table.addCell(new Paragraph("Usurio")); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(new Paragraph("Nmero")); table.addCell(new Paragraph("Tipo")); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); table.addCell(new Paragraph("Valor")); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); soma = 0.0; for (int b = 0; b <= listaUsuario.size() - 1; b++) { if (listaCidade.get(a).equals(listaUsuario.get(b).getCidade())) { //cidade informacao = new String(); informacao = listaUsuario.get(b).getCidade(); table.addCell(new Paragraph(informacao)); //Usurio informacao = new String(); informacao = listaUsuario.get(b).getNome(); table.addCell(new Paragraph(informacao)); //Nmero informacao = new String(); informacao = String.valueOf(listaUsuario.get(b).getLinha()); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(new Paragraph(informacao)); //Tipo informacao = new String(); informacao = listaUsuario.get(b).getTipo(); table.addCell(new Paragraph(informacao)); //Valor informacao = new String(); soma += listaUsuario.get(b).getValor(); informacao = "R$" + df.format(listaUsuario.get(b).getValor()); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); table.addCell(new Paragraph(informacao)); } } // Total table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); informacao = new String(); informacao = "Total apurado"; table.addCell(informacao); // tempo table.addCell(""); table.addCell(""); table.addCell(""); // valor informacao = new String(); informacao = "R$" + df.format(soma); table.addCell(informacao); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); if ((soma - diferenca) > 0) { table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); informacao = new String(); informacao = "Total a pagar"; table.addCell(informacao); // tempo table.addCell(""); table.addCell(""); table.addCell(""); // valor informacao = new String(); informacao = "R$" + df.format(soma - diferenca); table.addCell(informacao); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); } table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); table.addCell(""); unidade = new Usuario(); unidade.setCidade(listaCidade.get(a)); unidade.setValor(soma); listaUnidades.add(unidade); doc.add(table); } doc.newPage(); table.getDefaultCell().setBorder(0); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.getDefaultCell().setBorder(1); table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(new Paragraph("Cidade")); table.addCell(new Paragraph("")); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); table.addCell(new Paragraph("Valor")); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); soma = 0.0; for (int a = 0; a <= listaUnidades.size() - 1; a++) { //cidade informacao = new String(); informacao = listaUnidades.get(a).getCidade(); table.addCell(new Paragraph(informacao)); table.addCell(""); table.addCell(""); table.addCell(""); //Valor informacao = new String(); soma += listaUnidades.get(a).getValor(); informacao = "R$" + df.format(listaUnidades.get(a).getValor()); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); table.addCell(new Paragraph(informacao)); } // Total table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); informacao = new String(); informacao = "Total apurado"; table.addCell(informacao); // tempo table.addCell(""); table.addCell(""); table.addCell(""); // valor informacao = new String(); informacao = "R$" + df.format(soma); table.addCell(informacao); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); informacao = new String(); informacao = "Total a pagar"; table.addCell(informacao); // tempo table.addCell(""); table.addCell(""); table.addCell(""); // valor informacao = new String(); informacao = "R$" + df.format(soma); // informacao = "R$"+ df.format(soma-banco.getConta().get(banco.getConta().size()-1).getDiferenca()); table.addCell(informacao); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); doc.add(table); doc.close(); os.close(); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } }
From source file:Control.ProcessaArq.java
public void gravaArquivoConsumoUsuarios(ArrayList<Usuario> lista, String caminho) throws IOException, DocumentException { Document doc = null;//from www. j a v a2 s. c o m OutputStream os = null; Paragraph p = new Paragraph(); Tratamento tempo = new Tratamento(); DecimalFormat df = new DecimalFormat("#####.##"); String informacao, tipo = new String(); Double soma, valorTotal = 0.0; PdfPTable table = new PdfPTable(5); //tabela com 5 colunas float[] headerwidths = { 30, 80, 35, 35, 25 }; // define a largura de cada coluna table.setWidths(headerwidths); caminho = localizaArquivo(false) + ".pdf"; try {//configuraes da pgina float fntSize, lineSpacing; fntSize = 8f; lineSpacing = 8f; doc = new Document(PageSize.A4.rotate(), 10, 10, 30, 40); os = new FileOutputStream(caminho); PdfWriter.getInstance(doc, os); doc.open(); //cabecalho da tabela table.getDefaultCell().setBorder(0); table.getWidthPercentage(); table.getDefaultCell().setBorder(0); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.getDefaultCell().setColspan(5); table.addCell(new Paragraph("CONSUMO POR USU?RIOS ") + banco.periodoFatura()); table.getDefaultCell().setBorder(1); table.getDefaultCell().setColspan(0); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.addCell(new Paragraph("")); table.getDefaultCell().setBorder(1); table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(new Paragraph("Cidade")); table.addCell(new Paragraph("Usurio")); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(new Paragraph("Nmero")); table.addCell(new Paragraph("Tipo")); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); table.addCell(new Paragraph("Valor")); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); soma = 0.0; for (int a = 0; a <= lista.size() - 1; a++) { //cidade informacao = new String(); informacao = lista.get(a).getCidade(); // table.setTotalWidth(80); table.addCell(new Paragraph(informacao)); //Usurio informacao = new String(); informacao = lista.get(a).getNome(); // table.setTotalWidth(200); table.addCell(new Paragraph(informacao)); //Nmero informacao = new String(); informacao = String.valueOf(lista.get(a).getLinha()); // table.setTotalWidth(10); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(new Paragraph(informacao)); //Tipo informacao = new String(); informacao = lista.get(a).getTipo(); // table.setTotalWidth(10); table.addCell(new Paragraph(informacao)); //Valor informacao = new String(); soma += lista.get(a).getValor(); informacao = "R$" + df.format(lista.get(a).getValor()); // table.setTotalWidth(10); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); table.addCell(new Paragraph(informacao)); } // Total table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); informacao = new String(); informacao = "Total"; table.addCell(informacao); // tempo table.addCell(""); table.addCell(""); table.addCell(""); // valor informacao = new String(); informacao = "R$" + df.format(soma); table.addCell(informacao); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); doc.add(table); // fim da pgina } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } }
From source file:Control.ProcessaArq.java
public void gravaArquivoServicos(ArrayList<Conta> lista, String caminho) throws IOException, DocumentException { ArrayList<String> listaTipos; String local[];/*from ww w . j av a2 s . c o m*/ Document doc = null; OutputStream os = null; Paragraph p = new Paragraph(); Tratamento tempo = new Tratamento(); DecimalFormat df = new DecimalFormat("#####.##"); String informacao, tempoServico, tempoSubTotal, tempoTotal, tipo = new String(); Double soma, valorTotal = 0.0; PdfPTable table = new PdfPTable(3); //tabela com 3 colunas float[] headerwidths = { 85, 35, 25 }; // define a largura de cada coluna table.setWidths(headerwidths); caminho = localizaArquivo(false) + ".pdf"; try {//configuraes da pgina float fntSize, lineSpacing; fntSize = 10f; lineSpacing = 10f; doc = new Document(PageSize.A4.rotate(), 10, 10, 20, 10); os = new FileOutputStream(caminho); PdfWriter.getInstance(doc, os); doc.open(); tempoTotal = "00:00:00"; tempoServico = "00:00:00"; tempoSubTotal = "00:00:00"; listaTipos = new ArrayList<String>(); //cabecalho da tabela table.getDefaultCell().setBorder(0); table.getWidthPercentage(); table.getDefaultCell().setBorder(0); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.getDefaultCell().setColspan(3); table.addCell(new Paragraph(tempo.verificaNomeServico(lista) + " " + banco.periodoFatura())); table.getDefaultCell().setBorder(1); table.getDefaultCell().setColspan(0); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); for (int a = 0; a < lista.size() - 1; a++) { System.out.println(a + " - " + lista.get(a).getTipo()); if (!listaTipos.contains(lista.get(a).getTipo())) { listaTipos.add(lista.get(a).getTipo()); soma = 0.0; tipo = new String(); informacao = new String(); informacao = "" + listaTipos.get(listaTipos.size() - 1) + ""; table.getDefaultCell().setBorder(1); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.getDefaultCell().setColspan(3); table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(new Paragraph(informacao)); table.getDefaultCell().setBorder(1); table.getDefaultCell().setColspan(0); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); // contedo da tabela for (int b = 0; b <= lista.size() - 1; b++) { if (lista.get(b).getTipo().equals(listaTipos.get(listaTipos.size() - 1))) { soma += lista.get(b).getValor(); tempoServico = tempo.somaTempo(lista.get(b).getDuracao(), tempoServico); tempoSubTotal = tempo.somaTempo(tempoServico, tempoSubTotal); tempoTotal = tempo.somaTempo(tempoServico, tempoTotal); tipo = listaTipos.get(listaTipos.size() - 1); informacao = new String(); informacao = lista.get(b).getDescricaoServico(); table.setTotalWidth(80); table.addCell(new Paragraph(informacao)); informacao = new String(); informacao = tempoServico + " (" + tempo.conversaoHoraMinuto(tempoServico) + ")"; table.setTotalWidth(30); table.addCell(new Paragraph(informacao)); informacao = new String(); informacao = "R$" + df.format(lista.get(b).getValor()); table.setTotalWidth(20); table.addCell(new Paragraph(informacao)); tempoServico = "00:00:00"; // System.out.println(informacao); } } //rodap da tabela listaTipos.add(tipo); valorTotal += soma; // subtotal table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); informacao = new String(); informacao = "Sub Total:"; table.addCell(informacao); // tempo informacao = new String(); informacao = tempoSubTotal + " (" + tempo.conversaoHoraMinuto(tempoSubTotal) + ")"; table.addCell(informacao); // valor informacao = new String(); informacao = "R$" + df.format(soma); table.addCell(informacao); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); // espao entre tabelas table.getDefaultCell().setBorder(1); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.getDefaultCell().setColspan(3); table.addCell(new Paragraph("* * * * *")); table.getDefaultCell().setColspan(0); table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT); table.getDefaultCell().setBorder(0); tempoSubTotal = "00:00:00"; // System.out.println(informacao); } } // fim da pgina // valor total informacao = new String(); informacao = "Total Geral: "; table.getDefaultCell().setBorder(1); table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(informacao); table.getDefaultCell().setBorder(1); // tempo informacao = new String(); informacao = tempoTotal + " (" + tempo.conversaoHoraMinuto(tempoTotal) + ")"; table.addCell(informacao); //valor informacao = new String(); informacao = "R$" + df.format(valorTotal); table.addCell(informacao); doc.add(table); // System.out.println(informacao); } finally { if (doc != null) { //fechamento do documento doc.close(); } if (os != null) { //fechamento da stream de sada os.close(); } } }
From source file:control.ReportHandler.java
public void writeTotalPersonReport() throws DocumentException, FileNotFoundException { Document doc = new Document(PageSize.A4.rotate()); Calendar c = Calendar.getInstance(); String file = "" + c.get(Calendar.DAY_OF_MONTH) + "_" + (c.get(Calendar.MONTH) + 1) + "_" + c.get(Calendar.YEAR) + "_T_" + c.get(Calendar.HOUR_OF_DAY) + "_" + c.get(Calendar.MINUTE) + ".pdf"; PdfWriter.getInstance(doc, new FileOutputStream(new File(his.His.reportPersonsDir + "/" + file))); doc.open();/*from ww w. ja v a2s. co m*/ PdfPTable table = new PdfPTable(7); table.setWidths(new float[] { 10f, 10f, 10f, 10f, 5f, 5f, 5f }); PdfPTable totalTable = new PdfPTable(1); PdfPCell nameCell = new PdfPCell(new Phrase("Navn", columnFont)); nameCell.setBackgroundColor(BaseColor.BLACK); PdfPCell addressCell = new PdfPCell(new Phrase("Adresse", columnFont)); addressCell.setBackgroundColor(BaseColor.BLACK); PdfPCell birthCell = new PdfPCell(new Phrase("Fdselsdag", columnFont)); birthCell.setBackgroundColor(BaseColor.BLACK); PdfPCell createdCell = new PdfPCell(new Phrase("Oprettelsesdato", columnFont)); createdCell.setBackgroundColor(BaseColor.BLACK); PdfPCell hoeneCell = new PdfPCell(new Phrase("Hne", columnFont)); hoeneCell.setBackgroundColor(BaseColor.BLACK); PdfPCell reserveCell = new PdfPCell(new Phrase("Reserve", columnFont)); reserveCell.setBackgroundColor(BaseColor.BLACK); PdfPCell oneOneCell = new PdfPCell(new Phrase("1-1", columnFont)); oneOneCell.setBackgroundColor(BaseColor.BLACK); table.addCell(nameCell); table.addCell(addressCell); table.addCell(birthCell); table.addCell(createdCell); table.addCell(hoeneCell); table.addCell(reserveCell); table.addCell(oneOneCell); HashSet<Person> persons = peR.getPersons(); Iterator<Person> personsI = persons.iterator(); PdfPCell totalCell = new PdfPCell(new Phrase("Total: " + persons.size())); totalTable.addCell(totalCell); while (personsI.hasNext()) { Person p = personsI.next(); String name = p.getFirstname() + " " + p.getMiddlename() + " " + p.getLastname(); String hoene = "Nej"; if (p.isHoene()) { hoene = "Ja"; } String reserve = "Nej"; if (p.isReserve()) { reserve = "Ja"; } String oneOne = "Nej"; if (p.isOneOne()) { oneOne = "Ja"; } PdfPCell nameC = new PdfPCell(new Phrase(name)); PdfPCell addressC = new PdfPCell(new Phrase(p.getAddress())); PdfPCell birthC = new PdfPCell(new Phrase(p.getBirthdayDate())); PdfPCell createdC = new PdfPCell(new Phrase(p.getCreationDate())); PdfPCell hoeneC = new PdfPCell(new Phrase(hoene)); PdfPCell reserveC = new PdfPCell(new Phrase(reserve)); PdfPCell oneOneC = new PdfPCell(new Phrase(oneOne)); table.addCell(nameC); table.addCell(addressC); table.addCell(birthC); table.addCell(createdC); table.addCell(hoeneC); table.addCell(reserveC); table.addCell(oneOneC); } doc.add(new Phrase("Personer")); doc.add(table); doc.add(totalTable); doc.close(); }