List of usage examples for com.itextpdf.text Element ALIGN_CENTER
int ALIGN_CENTER
To view the source code for com.itextpdf.text Element ALIGN_CENTER.
Click Source Link
From source file:br.com.tcc.view.BairroView.java
/** * Evento responsvel por fechar o sistema * @param evt // ww w . j ava2s . com */ private void btnFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFecharActionPerformed Document documento = new Document(); try { OutputStream outputStream = new FileOutputStream( "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Registro Bairros.pdf"); PdfWriter.getInstance(documento, outputStream); documento.open(); Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 36, Font.BOLD); Paragraph paragrafo = new Paragraph("Relatrio da Bairro", fonte); paragrafo.setAlignment(Element.ALIGN_CENTER); documento.add(paragrafo); Paragraph paragrafoLista = new Paragraph(bairroList.toString()); documento.add(paragrafoLista); documento.close(); } catch (FileNotFoundException ex) { Logger.getLogger(MovimentoVendaView.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(MovimentoVendaView.class.getName()).log(Level.SEVERE, null, ex); } dispose(); }
From source file:br.com.tcc.view.FormaPagamentoView.java
private void btnImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirActionPerformed int row = tblRegistro.getSelectedRow(); int id = vendaRegistroList.get(row).getId(); Connection con = new ConnectionFactory().getConnection(); try {// w w w. j a va 2 s. c o m Statement stmt = con.createStatement(); ResultSet query = stmt.executeQuery( "SELECT produto.descricao, vendadetalhe.qtde, vendadetalhe.vlrUnitario, vendadetalhe.vlrTotal from vendadetalhe as vendadetalhe INNER JOIN produto as produto ON (vendadetalhe.idProduto = produto.ID) where idVendaRegistro = " + id); Document documento = new Document(); SimpleDateFormat horaformatada = new SimpleDateFormat("HH:mm:ss"); Date horaAtual = new Date(); hora = horaformatada.format(horaAtual); Date data = new Date(); // mes = ""+Data.getMonth();//0 a 11 dia = "" + data.getDate(); ano = "" + (1900 + data.getYear()); switch (data.getMonth()) { case 0: mes = "Janeiro"; break; case 1: mes = "Fevereiro"; break; case 2: mes = "Maro"; break; case 3: mes = "Abril"; break; case 4: mes = "Maio"; break; case 5: mes = "Junho"; break; case 6: mes = "Julho"; break; case 7: mes = "Agosto"; break; case 8: mes = "Setembro"; break; case 9: mes = "Outubro"; break; case 10: mes = "Novembro"; break; case 11: mes = "Dezembro"; break; } try { OutputStream outputStream = new FileOutputStream( "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Registro da venda " + txtCodigo.getText() + ".pdf"); PdfWriter.getInstance(documento, outputStream); documento.open(); Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 36, Font.BOLD); Font fonteItem = new Font(Font.FontFamily.COURIER, 28, Font.BOLD); Paragraph cabecalho = new Paragraph("AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n" + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n" + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n" + "CNPJ: 12.345.678/1011-12\n" + "-------------------------------------------\n" + dia + "/" + mes + "/" + ano + " " + hora + " COD: " + txtCodigo.getText()); cabecalho.setAlignment(Element.ALIGN_CENTER); documento.add(cabecalho); Paragraph paragrafo = new Paragraph("Relatrio da Venda", fonte); paragrafo.setAlignment(Element.ALIGN_CENTER); documento.add(paragrafo); Paragraph paragrafoCliente = new Paragraph("Cliente: " + cbxCliente.getSelectedItem().toString()); documento.add(paragrafoCliente); Paragraph paragrafoFuncionario = new Paragraph( "Funcionrio: " + cbxFuncionario.getSelectedItem().toString()); documento.add(paragrafoFuncionario); Paragraph paragrafoPagamento = new Paragraph( "Tipo de Pagamento: " + cbxTipoPagamento.getSelectedItem().toString()); documento.add(paragrafoPagamento); // Paragraph paragrafoParcela = new Paragraph("Parcelas: " + cbxParcelas.getSelectedItem().toString()); // documento.add(paragrafoParcela); // Paragraph paragrafoValor = new Paragraph("Valor R$: " + txtTotal.getText()); // documento.add(paragrafoValor); if (cbxTipoPagamento.getSelectedItem().toString().equals(" vista") || cbxTipoPagamento.getSelectedItem().toString().equals("C. Debito")) { Paragraph paragrafoValor = new Paragraph("Valor R$: " + txtCompra.getText()); documento.add(paragrafoValor); Paragraph paragrafoAVista = new Paragraph("Valor vista: " + txtTotal.getText()); documento.add(paragrafoAVista); } else { Paragraph paragrafoValor = new Paragraph("Valor R$: " + txtTotal.getText()); documento.add(paragrafoValor); int parcela = Integer.parseInt(cbxParcelas.getSelectedItem().toString()); double valorParcelas = Double.parseDouble(txtTotal.getText()); double total = valorParcelas / parcela; Paragraph paragrafoVezes = new Paragraph( cbxParcelas.getSelectedItem().toString() + " parcelas de R$: " + total); documento.add(paragrafoVezes); } Paragraph quebraLinha = new Paragraph("\n\n"); documento.add(quebraLinha); //we have two columns in our table PdfPTable LogTable = new PdfPTable(4); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Relatrio de Entrada de Estoque"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(4); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela Font fonte2 = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD, BaseColor.BLACK); Font fonteDados = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK); LogTable.addCell(header); LogTable.addCell(new Paragraph("Produto ", fonte2)); LogTable.addCell(new Paragraph("Quantidade", fonte2)); LogTable.addCell(new Paragraph("Valor Unitrio", fonte2)); LogTable.addCell(new Paragraph("Valor Total", fonte2)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("produto.descricao"); LogTable.addCell(new Paragraph(produto, fonteDados)); String quantidade = query.getString("qtde"); LogTable.addCell(new Paragraph(quantidade, fonteDados)); String vlrSugerido = query.getString("vlrUnitario"); LogTable.addCell(new Paragraph(vlrSugerido, fonteDados)); String vlrTotal = query.getString("vlrTotal"); LogTable.addCell(new Paragraph(vlrTotal, fonteDados)); } /* Attach report table to PDF */ documento.add(LogTable); // Paragraph paragrafoItemVenda = new Paragraph("Produtos da venda", fonteItem); // paragrafoItemVenda.setAlignment(Element.ALIGN_CENTER); // documento.add(paragrafoItemVenda); // Paragraph cabecalhoItemVenda = new Paragraph("Produto Qtde. Vlr Unit. Vlr Total"); // documento.add(cabecalhoItemVenda); // vendaDetalheQuery = entityManager.createQuery("from Vendadetalhe where idVendaRegistro=" + txtCodigo.getText()); // Paragraph paragrafoLista = new Paragraph(vendaDetalheQuery.getResultList().toString().substring(1, vendaDetalheQuery.getResultList().toString().length() - 1)); // documento.add(paragrafoLista); documento.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Registro da venda " + txtCodigo.getText() + ".pdf"; Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); } catch (FileNotFoundException ex) { Logger.getLogger(MovimentoVendaView.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(MovimentoVendaView.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(FormaPagamentoView.class.getName()).log(Level.SEVERE, null, ex); } } catch (SQLException ex) { Logger.getLogger(FormaPagamentoView.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:br.com.tcc.view.MovimentoEntradaView.java
private void relat(String sql) throws SQLException, DocumentException, FileNotFoundException, IOException { /* Create Connection objects */ Connection con = new ConnectionFactory().getConnection(); Statement stmt = con.createStatement(); int row = tblRegistro.getSelectedRow(); int id = entradaRegistroList.get(row).getId(); SimpleDateFormat horaformatada = new SimpleDateFormat("HH:mm:ss"); Date horaAtual = new Date(); hora = horaformatada.format(horaAtual); Date data = new Date(); // mes = ""+Data.getMonth();//0 a 11 dia = "" + data.getDate(); ano = "" + (1900 + data.getYear()); switch (data.getMonth()) { case 0://from w w w.ja v a 2s .c om mes = "Janeiro"; break; case 1: mes = "Fevereiro"; break; case 2: mes = "Maro"; break; case 3: mes = "Abril"; break; case 4: mes = "Maio"; break; case 5: mes = "Junho"; break; case 6: mes = "Julho"; break; case 7: mes = "Agosto"; break; case 8: mes = "Setembro"; break; case 9: mes = "Outubro"; break; case 10: mes = "Novembro"; break; case 11: mes = "Dezembro"; break; } /* Define the SQL query */ // sql = "SELECT cliente.nome, funcionario.nome, tipopagamento.descricao, vendaregistro.dataVenda, vendaregistro.vlrSugerido, vendaregistro.totalVenda, vendaregistro.parcela, vendaregistro.1vencimento, vendaregistro.ativo FROM vendaregistro as vendaregistro INNER JOIN cliente as cliente ON (vendaregistro.idCliente = cliente.id) \n" + //"INNER JOIN funcionario as funcionario ON (vendaregistro.idFuncionario = funcionario.id) INNER JOIN tipopagamento as tipopagamento ON (vendaregistro.idTipoPagamento = tipopagamento.id) WHERE dataVenda = CURRENT_DATE"; ResultSet query = stmt.executeQuery(sql); /* Step-2: Initialize PDF documents - logical objects */ Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Entrada " + id + ".pdf")); PDFLogReport.open(); Paragraph cabecalho = new Paragraph("AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n" + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n" + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n" + "CNPJ: 12.345.678/1011-12\n" + "-------------------------------------------\n" + dia + "/" + mes + "/" + ano + " " + hora + " COD: " + id + " \n\n"); cabecalho.setAlignment(Element.ALIGN_CENTER); PDFLogReport.add(cabecalho); //we have two columns in our table PdfPTable LogTable = new PdfPTable(4); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Relatrio de Entrada de Estoque"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(4); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela Font fonte = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD, BaseColor.BLACK); Font fonteDados = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK); LogTable.addCell(header); LogTable.addCell(new Paragraph("Produto ", fonte)); LogTable.addCell(new Paragraph("Quantidade", fonte)); LogTable.addCell(new Paragraph("Valor Unitrio", fonte)); LogTable.addCell(new Paragraph("Valor Total", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("produto.descricao"); LogTable.addCell(new Paragraph(produto, fonteDados)); String quantidade = query.getString("qtde"); LogTable.addCell(new Paragraph(quantidade, fonteDados)); String vlrSugerido = query.getString("vlrUnitario"); LogTable.addCell(new Paragraph(vlrSugerido, fonteDados)); String vlrTotal = query.getString("vlrTotal"); LogTable.addCell(new Paragraph(vlrTotal, fonteDados)); } /* Attach report table to PDF */ PDFLogReport.add(LogTable); double valor = entradaRegistroList.get(row).getVlrTotal(); Paragraph paragrafoValor = new Paragraph("Valor R$: " + valor); paragrafoValor.setAlignment(Element.ALIGN_RIGHT); PDFLogReport.add(paragrafoValor); PDFLogReport.close(); /* Close all DB related objects */ query.close(); stmt.close(); con.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Entrada " + id + ".pdf"; Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); }
From source file:br.com.tcc.view.MovimentoOrcamentoView.java
private void relat(String sql) throws IOException, DocumentException, SQLException { /* Create Connection objects */ Connection con = new ConnectionFactory().getConnection(); Statement stmt = con.createStatement(); int row = tblRegistro.getSelectedRow(); int id = orcamentoRegistroList.get(row).getId(); SimpleDateFormat horaformatada = new SimpleDateFormat("HH:mm:ss"); Date horaAtual = new Date(); hora = horaformatada.format(horaAtual); Date data = new Date(); // mes = ""+Data.getMonth();//0 a 11 dia = "" + data.getDate(); ano = "" + (1900 + data.getYear()); switch (data.getMonth()) { case 0://from w w w . ja v a2 s. c om mes = "Janeiro"; break; case 1: mes = "Fevereiro"; break; case 2: mes = "Maro"; break; case 3: mes = "Abril"; break; case 4: mes = "Maio"; break; case 5: mes = "Junho"; break; case 6: mes = "Julho"; break; case 7: mes = "Agosto"; break; case 8: mes = "Setembro"; break; case 9: mes = "Outubro"; break; case 10: mes = "Novembro"; break; case 11: mes = "Dezembro"; break; } /* Define the SQL query */ // sql = "SELECT cliente.nome, funcionario.nome, tipopagamento.descricao, vendaregistro.dataVenda, vendaregistro.vlrSugerido, vendaregistro.totalVenda, vendaregistro.parcela, vendaregistro.1vencimento, vendaregistro.ativo FROM vendaregistro as vendaregistro INNER JOIN cliente as cliente ON (vendaregistro.idCliente = cliente.id) \n" + //"INNER JOIN funcionario as funcionario ON (vendaregistro.idFuncionario = funcionario.id) INNER JOIN tipopagamento as tipopagamento ON (vendaregistro.idTipoPagamento = tipopagamento.id) WHERE dataVenda = CURRENT_DATE"; ResultSet query = stmt.executeQuery(sql); /* Step-2: Initialize PDF documents - logical objects */ Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Oramento " + id + ".pdf")); PDFLogReport.open(); Paragraph cabecalho = new Paragraph("AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n" + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n" + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n" + "CNPJ: 12.345.678/1011-12\n" + "-------------------------------------------\n" + dia + "/" + mes + "/" + ano + " " + hora + " COD: " + id + " \n\n"); cabecalho.setAlignment(Element.ALIGN_CENTER); PDFLogReport.add(cabecalho); //we have two columns in our table PdfPTable LogTable = new PdfPTable(4); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Oramento"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(4); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela Font fonte = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD, BaseColor.BLACK); Font fonteDados = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK); LogTable.addCell(header); LogTable.addCell(new Paragraph("Produto ", fonte)); LogTable.addCell(new Paragraph("Quantidade", fonte)); LogTable.addCell(new Paragraph("Valor Unitrio", fonte)); LogTable.addCell(new Paragraph("Valor Total", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("produto.descricao"); LogTable.addCell(new Paragraph(produto, fonteDados)); String quantidade = query.getString("qtde"); LogTable.addCell(new Paragraph(quantidade, fonteDados)); String vlrSugerido = query.getString("vlrUnitario"); LogTable.addCell(new Paragraph(vlrSugerido, fonteDados)); String vlrTotal = query.getString("vlrTotal"); LogTable.addCell(new Paragraph(vlrTotal, fonteDados)); } /* Attach report table to PDF */ PDFLogReport.add(LogTable); double valor = orcamentoRegistroList.get(row).getVlrTotalOrcamento(); Paragraph paragrafoValor = new Paragraph("Valor R$: " + valor); paragrafoValor.setAlignment(Element.ALIGN_RIGHT); PDFLogReport.add(paragrafoValor); PDFLogReport.close(); /* Close all DB related objects */ query.close(); stmt.close(); con.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Oramento " + id + ".pdf"; Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); }
From source file:br.com.tcc.view.MovimentoPedidoView.java
private void relat(String sql) throws SQLException, DocumentException, FileNotFoundException, IOException { /* Create Connection objects */ Connection con = new ConnectionFactory().getConnection(); Statement stmt = con.createStatement(); int row = tblRegistro.getSelectedRow(); int id = pedidoRegistroList.get(row).getId(); SimpleDateFormat horaformatada = new SimpleDateFormat("HH:mm:ss"); Date horaAtual = new Date(); hora = horaformatada.format(horaAtual); Date data = new Date(); // mes = ""+Data.getMonth();//0 a 11 dia = "" + data.getDate(); ano = "" + (1900 + data.getYear()); switch (data.getMonth()) { case 0:/*w w w . j a va2 s. c o m*/ mes = "Janeiro"; break; case 1: mes = "Fevereiro"; break; case 2: mes = "Maro"; break; case 3: mes = "Abril"; break; case 4: mes = "Maio"; break; case 5: mes = "Junho"; break; case 6: mes = "Julho"; break; case 7: mes = "Agosto"; break; case 8: mes = "Setembro"; break; case 9: mes = "Outubro"; break; case 10: mes = "Novembro"; break; case 11: mes = "Dezembro"; break; } /* Define the SQL query */ // sql = "SELECT cliente.nome, funcionario.nome, tipopagamento.descricao, vendaregistro.dataVenda, vendaregistro.vlrSugerido, vendaregistro.totalVenda, vendaregistro.parcela, vendaregistro.1vencimento, vendaregistro.ativo FROM vendaregistro as vendaregistro INNER JOIN cliente as cliente ON (vendaregistro.idCliente = cliente.id) \n" + //"INNER JOIN funcionario as funcionario ON (vendaregistro.idFuncionario = funcionario.id) INNER JOIN tipopagamento as tipopagamento ON (vendaregistro.idTipoPagamento = tipopagamento.id) WHERE dataVenda = CURRENT_DATE"; ResultSet query = stmt.executeQuery(sql); /* Step-2: Initialize PDF documents - logical objects */ Document PDFLogReport = new Document(); PdfWriter.getInstance(PDFLogReport, new FileOutputStream("C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Pedidos " + id + ".pdf")); PDFLogReport.open(); Paragraph cabecalho = new Paragraph("AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n" + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n" + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n" + "CNPJ: 12.345.678/1011-12\n" + "-------------------------------------------\n" + dia + "/" + mes + "/" + ano + " " + hora + " COD: " + id + " \n\n"); cabecalho.setAlignment(Element.ALIGN_CENTER); PDFLogReport.add(cabecalho); //we have two columns in our table PdfPTable LogTable = new PdfPTable(4); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("Lista de Pedidos"); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 2 colunas header.setColspan(4); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela Font fonte = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD, BaseColor.BLACK); Font fonteDados = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK); LogTable.addCell(header); LogTable.addCell(new Paragraph("Produto ", fonte)); LogTable.addCell(new Paragraph("Quantidade", fonte)); LogTable.addCell(new Paragraph("Valor Unitrio", fonte)); LogTable.addCell(new Paragraph("Valor Total", fonte)); //create a cell object // PdfPCell table_cell; while (query.next()) { String produto = query.getString("produto.descricao"); LogTable.addCell(new Paragraph(produto, fonteDados)); String quantidade = query.getString("qtdePedido"); LogTable.addCell(new Paragraph(quantidade, fonteDados)); String vlrSugerido = query.getString("vlrUnitario"); LogTable.addCell(new Paragraph(vlrSugerido, fonteDados)); String vlrTotal = query.getString("vlrTotal"); LogTable.addCell(new Paragraph(vlrTotal, fonteDados)); } /* Attach report table to PDF */ PDFLogReport.add(LogTable); double valor = pedidoRegistroList.get(row).getVlrPedido(); Paragraph paragrafoValor = new Paragraph("Valor R$: " + valor); paragrafoValor.setAlignment(Element.ALIGN_RIGHT); PDFLogReport.add(paragrafoValor); PDFLogReport.close(); /* Close all DB related objects */ query.close(); stmt.close(); con.close(); String file; file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Pedidos " + id + ".pdf"; Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); }
From source file:BusinessLogic.Controller.HandleCertificate.java
public void downloadCertificate(ContractDAO contrDAO, CertificateDAO certificateDAO, UserDAO usDAO, HttpServletResponse response, int idUser, int option) throws DocumentException, IOException { User user = usDAO.searchByPkID(idUser); List<Certificate> certificateObject = certificateDAO.searchUserAproved(); List<Certificate> certificateReturn = new ArrayList<Certificate>(); if (certificateObject != null) { certificateReturn.clear();/* w w w. j a v a2 s . c om*/ for (int i = 0; i < certificateObject.size(); i++) { if (certificateObject.get(i).getFkuserID().getPkID().equals(user.getPkID())) { certificateReturn.add(certificateObject.get(i)); } } } Contract contractObject = contrDAO.getUserContract(new User(user.getPkID())); Certificate cert = certificateReturn.get(option); Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); Font fuente = new Font(); fuente.setStyle(Font.BOLD); fuente.setColor(BaseColor.BLACK); fuente.setFamily(Font.FontFamily.TIMES_ROMAN.toString()); fuente.setSize(15); Paragraph header = new Paragraph("\n\n\n\n\nEL DEPARTAMENTO DE GESTION HUMANA\n" + "DE TALENTO-HUMANO LTDA\n\n\n\n\n" + "CERTIFICA QUE:\n\n\n\n\n", fuente); header.setAlignment(Element.ALIGN_CENTER); Calendar fecha = new GregorianCalendar(); int annio = fecha.get(Calendar.YEAR); int mes = fecha.get(Calendar.MONTH) + 1; int dia = fecha.get(Calendar.DAY_OF_MONTH); Paragraph endtext = new Paragraph("\n\nSe expide la presente certificacion a solicitud" + " del interesado a la fecha de : " + dia + "/" + mes + "/" + annio + "\n\n\nCordialmente\n\n\nEdwin Alexander Bohorquez\nGERENTE GENERAL DE TALENTO-HUMANO LTDA"); endtext.setAlignment(Element.ALIGN_LEFT); String typeCertificate = ""; if (cert.getType().toLowerCase().equals("laboral")) { typeCertificate = "Laboral"; document.add(header); List<String> positionlist = new ArrayList<String>(); for (Position cargo : contractObject.getPositionSet()) { positionlist.add(cargo.getName()); } Paragraph body = new Paragraph(user.getName().toUpperCase() + " " + user.getLastname().toUpperCase() + " con cedula de ciudadania No." + user.getIdentifyCard() + ", trabaja en esta empresa" + " desde " + contractObject.getStartDate() + ", desempeandose actualmente como " + positionlist + " con una asignacion mensual de $" + contractObject.getSalary() + ".Su contrato de trabajo es a termino " + contractObject.getType() + "."); body.setAlignment(Element.ALIGN_JUSTIFIED_ALL); document.add(body); document.add(endtext); } else if (cert.getType().toLowerCase().equals("nmina")) { typeCertificate = "Nomina"; Paragraph Payroll_header = new Paragraph("DEPARTAMENTO DE CONTABILIDAD\n" + "TALENTO-HUMANO LTDA\n\n" + "LIQUIDACION DE NOMINA:\n" + "Nombre del empleado : " + user.getName() + " " + user.getLastname() + "\n" + "Cedula : " + user.getIdentifyCard() + "\n\n", fuente); Payroll_header.setAlignment(Element.ALIGN_CENTER); document.add(Payroll_header); double commissions = 10000; double extra_hours = 50000; double transportation_aid = 63600; double totalAccrued = contractObject.getSalary() + commissions + extra_hours + transportation_aid; PdfPTable basetable = new PdfPTable(2); PdfPCell headertable = new PdfPCell(new Paragraph("Tabla Base", fuente)); headertable.setColspan(2); basetable.addCell(headertable); PdfPCell cell1 = new PdfPCell(new Paragraph("Salario Basico : ")); PdfPCell cell2 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary()))); PdfPCell cell3 = new PdfPCell(new Paragraph("Comisiones : ")); PdfPCell cell4 = new PdfPCell(new Paragraph(String.valueOf(commissions))); PdfPCell cell5 = new PdfPCell(new Paragraph("Horas Extras : ")); PdfPCell cell6 = new PdfPCell(new Paragraph(String.valueOf(extra_hours))); PdfPCell cell7 = new PdfPCell(new Paragraph("Auxilio de transporte : ")); PdfPCell cell8 = new PdfPCell(new Paragraph(String.valueOf(transportation_aid))); PdfPCell ce9 = new PdfPCell(new Paragraph("Total Devengado : ")); PdfPCell ce10 = new PdfPCell(new Paragraph(" $ " + String.valueOf(totalAccrued))); basetable.setWidthPercentage(100F); basetable.setHorizontalAlignment(Element.ALIGN_CENTER); basetable.addCell(cell1); basetable.addCell(cell2); basetable.addCell(cell3); basetable.addCell(cell4); basetable.addCell(cell5); basetable.addCell(cell6); basetable.addCell(cell7); basetable.addCell(cell8); basetable.addCell(ce9); basetable.addCell(ce10); document.add(basetable); PdfPTable tableliquidation = new PdfPTable(2); PdfPCell title = new PdfPCell( new Paragraph("Liquidacion. Deducciones de nomina(Conceptos a cargo del empleado) ", fuente)); title.setColspan(2); tableliquidation.addCell(title); PdfPCell cell9 = new PdfPCell(new Paragraph("Salud (4%) : ")); PdfPCell cell10 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.04))); PdfPCell cell11 = new PdfPCell(new Paragraph("Pension (4%) : ")); PdfPCell cell12 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.04))); tableliquidation.setWidthPercentage(100F); tableliquidation.setHorizontalAlignment(Element.ALIGN_CENTER); tableliquidation.addCell(cell9); tableliquidation.addCell(cell10); tableliquidation.addCell(cell11); tableliquidation.addCell(cell12); document.add(tableliquidation); PdfPTable tablesocialSecurity = new PdfPTable(2); PdfPCell title2 = new PdfPCell(new Paragraph("Seguridad Social a cargo del empleador", fuente)); title2.setColspan(2); tablesocialSecurity.addCell(title2); PdfPCell cell13 = new PdfPCell(new Paragraph("Salud (8.5%) : ")); PdfPCell cell14 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.085))); PdfPCell cell15 = new PdfPCell(new Paragraph("Pension (12%) : ")); PdfPCell cell16 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.12))); PdfPCell cell17 = new PdfPCell(new Paragraph("A.R.P : ")); PdfPCell cell18 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.00522))); tablesocialSecurity.setWidthPercentage(100F); tablesocialSecurity.setHorizontalAlignment(Element.ALIGN_CENTER); tablesocialSecurity.addCell(cell13); tablesocialSecurity.addCell(cell14); tablesocialSecurity.addCell(cell15); tablesocialSecurity.addCell(cell16); tablesocialSecurity.addCell(cell17); tablesocialSecurity.addCell(cell18); document.add(tablesocialSecurity); PdfPTable social_benefits = new PdfPTable(2); PdfPCell title3 = new PdfPCell(new Paragraph("Prestaciones Sociales", fuente)); title3.setColspan(2); social_benefits.addCell(title3); PdfPCell cell19 = new PdfPCell(new Paragraph("Prima de servicios : ")); PdfPCell cell20 = new PdfPCell(new Paragraph(String.valueOf(totalAccrued * 0.0833))); PdfPCell cell21 = new PdfPCell(new Paragraph("Cesantias : ")); PdfPCell cell22 = new PdfPCell(new Paragraph(String.valueOf(totalAccrued * 0.0833))); PdfPCell cell23 = new PdfPCell(new Paragraph("Intereses sobre las cesantias : ")); PdfPCell cell24 = new PdfPCell(new Paragraph(String.valueOf(totalAccrued * 0.0833 * 0.12))); PdfPCell cell25 = new PdfPCell(new Paragraph("Vacaciones : ")); PdfPCell cell26 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.0417))); social_benefits.setWidthPercentage(100F); social_benefits.setHorizontalAlignment(Element.ALIGN_CENTER); social_benefits.addCell(cell19); social_benefits.addCell(cell20); social_benefits.addCell(cell21); social_benefits.addCell(cell22); social_benefits.addCell(cell23); social_benefits.addCell(cell24); social_benefits.addCell(cell25); social_benefits.addCell(cell26); document.add(social_benefits); PdfPTable fiscal_contributions = new PdfPTable(2); PdfPCell title4 = new PdfPCell(new Paragraph("Aportes Parafiscales", fuente)); title4.setColspan(2); fiscal_contributions.addCell(title4); PdfPCell cell27 = new PdfPCell(new Paragraph("Cajas de compensacion familiar (4%) : ")); PdfPCell cell28 = new PdfPCell( new Paragraph(String.valueOf((contractObject.getSalary() + extra_hours + commissions) * 0.04))); PdfPCell cell29 = new PdfPCell(new Paragraph("I.CB.F (3%) : ")); PdfPCell cell30 = new PdfPCell( new Paragraph(String.valueOf((contractObject.getSalary() + extra_hours + commissions) * 0.03))); PdfPCell cell31 = new PdfPCell(new Paragraph("Sena (2%) : ")); PdfPCell cell32 = new PdfPCell( new Paragraph(String.valueOf((contractObject.getSalary() + extra_hours + commissions) * 0.02))); fiscal_contributions.setWidthPercentage(100F); fiscal_contributions.setHorizontalAlignment(Element.ALIGN_CENTER); fiscal_contributions.addCell(cell27); fiscal_contributions.addCell(cell28); fiscal_contributions.addCell(cell29); fiscal_contributions.addCell(cell30); fiscal_contributions.addCell(cell31); fiscal_contributions.addCell(cell32); document.add(fiscal_contributions); PdfPTable totalValue = new PdfPTable(2); PdfPCell title5 = new PdfPCell(new Paragraph("Neto a pagar al empleado", fuente)); title5.setColspan(2); totalValue.addCell(title5); PdfPCell cell33 = new PdfPCell(new Paragraph(" Total devengado - salud - pension")); cell33.setColspan(2); PdfPCell cell34 = new PdfPCell(new Paragraph( " $ " + String.valueOf(totalAccrued - contractObject.getSalary() * 0.08), fuente)); cell34.setColspan(2); totalValue.setWidthPercentage(100F); totalValue.setHorizontalAlignment(Element.ALIGN_CENTER); totalValue.addCell(cell33); totalValue.addCell(cell34); document.add(totalValue); document.add(endtext); } else if (cert.getType().toLowerCase().equals("salud")) { typeCertificate = "Salud"; document.add(header); Paragraph body = new Paragraph(user.getName().toUpperCase() + " " + user.getLastname().toUpperCase() + " con cedula de ciudadania No." + user.getIdentifyCard() + ", esta afiliado desde " + contractObject.getStartHealthDate() + " a la empresa de salud " + contractObject.getHealthEnterprise() + "."); body.setAlignment(Element.ALIGN_JUSTIFIED_ALL); document.add(body); document.add(endtext); } else if (cert.getType().toLowerCase().equals("pensin")) { typeCertificate = "Pension"; document.add(header); Paragraph body = new Paragraph(user.getName().toUpperCase() + " " + user.getLastname().toUpperCase() + " con cedula de ciudadania No." + user.getIdentifyCard() + ", esta afiliado a la empresa de pension " + contractObject.getPensionEnterprise() + ".La fecha de inicio de pension es " + contractObject.getStartPensionDate() + "."); body.setAlignment(Element.ALIGN_JUSTIFIED_ALL); document.add(body); document.add(endtext); } document.close(); response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); response.setContentType("application/octet-strem"); File f = new File("Certificado" + typeCertificate + ".pdf"); response.setHeader("Content-Disposition", "attachment;filename=" + f.getName()); response.setContentLength(baos.size()); System.out.println("Hasta aca crea el pdf bien"); OutputStream os = response.getOutputStream(); System.out.println("Ac'a ya deberia haber descargado"); baos.writeTo(os); os.flush(); os.close(); }
From source file:bussiness.ReportHandler.java
private void BuildHeaderPrescription(Document veterinaryPrescription, String clientName, String petName) throws DocumentException, IOException { BaseFont baseFont = BaseFont.createFont("Cookie.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED); Font font = new Font(baseFont); font.setStyle(Font.BOLDITALIC); font.setSize(35);//from w w w . java 2s. c o m Doctor doctor = SessionManager.getLoggedDoctor(); Paragraph p1 = new Paragraph("Dr. " + doctor.getName(), font); p1.setAlignment(Element.ALIGN_CENTER); veterinaryPrescription.add(p1); // veterinaryPrescription.add(new Chunk("\n")); Font font2 = new Font(); font2.setSize(20); Paragraph p2 = new Paragraph("CEDULA PROFESIONAL " + doctor.getIdentityCard(), font2); p2.setAlignment(Element.ALIGN_CENTER); veterinaryPrescription.add(p2); veterinaryPrescription.add(new Chunk("\n")); Paragraph p3 = new Paragraph("Nombre del cliente: " + clientName, font2); veterinaryPrescription.add(p3); Paragraph p4 = new Paragraph("Nombre de la mascota: " + petName, font2); veterinaryPrescription.add(p4); }
From source file:bussiness.ReportHandler.java
private void BuildFooterSaleReport(Document documento) throws DocumentException { documento.add(new Chunk("\n")); documento.add(new Chunk("\n")); documento.add(new Chunk("\n")); Paragraph p2 = new Paragraph("GRACIAS POR SU PREFERENCIA"); p2.setAlignment(Element.ALIGN_CENTER); Paragraph p3 = new Paragraph("VUELVA PRONTO"); p3.setAlignment(Element.ALIGN_CENTER); documento.add(p2);//from www . j a v a2 s . c om documento.add(p3); }
From source file:by.bsuir.group172301.matskevich.tour.util.PDFCreator.java
public static void writeChartToPDF(JFreeChart chart, int width, int height, String fileName, int col1, int col2, double perc) { PdfWriter writer = null;// www . j ava 2 s . co m Document document = new Document(); try { writer = PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Paragraph paragraph = new Paragraph(); // We add one empty line paragraph = new Paragraph("Results:"); paragraph.setAlignment(Element.ALIGN_CENTER); document.add(paragraph); paragraph = new Paragraph("Test before: " + col1); document.add(paragraph); paragraph = new Paragraph("Test after: " + col2); document.add(paragraph); paragraph = new Paragraph("Percentage: " + perc); document.add(paragraph); PdfContentByte contentByte = writer.getDirectContent(); PdfTemplate template = contentByte.createTemplate(width, height); Graphics2D graphics2d = template.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 150, 250); } catch (Exception e) { e.printStackTrace(); } document.close(); }
From source file:CadastroDeMusicas.Principal.java
public static void main(String[] args) throws Exception { ConecBanco c = new ConecBanco(con); Genero g;//w ww . j av a 2 s.co m Artista a1; Album a2; Musica m; String nome, tipo; int nota, duracao, ano; int opc; try { new Principal(); } catch (ClassNotFoundException | SQLException e) { System.out.println("No conectado."); } do { opc = Integer.parseInt(JOptionPane.showInputDialog( "Informe a OPO:\n1.Inserir\n2.Deletar\n3.Pesquisar\n4.Relatorio em Pdf\n5.Sair")); switch (opc) { case 1: nome = JOptionPane.showInputDialog("Genero: "); g = new Genero(nome); nome = JOptionPane.showInputDialog("Artista: "); a1 = new Artista(nome); nome = JOptionPane.showInputDialog("Album: "); ano = Integer.parseInt(JOptionPane.showInputDialog("Ano: ")); a2 = new Album(nome, ano); nome = JOptionPane.showInputDialog("Musica: "); nota = Integer.parseInt(JOptionPane.showInputDialog("Nota (1/10): ")); duracao = Integer.parseInt(JOptionPane.showInputDialog("Durao: ")); m = new Musica(nome, nota, duracao); c.cadastrar(g, a1, a2, m); break; case 2: System.out.println("DELETAR MUSICA: "); nome = JOptionPane.showInputDialog("Musica: "); c.deletar(nome); break; case 3: System.out.println("PESQUISAR MUSICA: "); ResultSet rs = ConecBanco.pesquisar(); if (rs != null) { try { while (rs.next()) { System.out.println("MUSICA: " + rs.getString("nome")); System.out.println("NOTA: " + rs.getString("nota")); System.out.println("DURAO: " + rs.getString("duracao")); System.out.println("ALBUM: " + rs.getString("nomeAL")); System.out.println("ANO: " + rs.getString("ano")); System.out.println("ARTISTA: " + rs.getString("nomeAR")); System.out.println("GENERO: " + rs.getString("nomeGE")); } } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } break; case 4: Document doc = null; OutputStream os = null; String add; System.out.println("LISTA DE MUSICAS: "); try { doc = new Document(PageSize.A4, -1, -1, 25, 1) { }; os = new FileOutputStream("Relatorio.pdf"); PdfWriter.getInstance((com.itextpdf.text.Document) doc, os); doc.open(); Image img = Image.getInstance("images.jpg"); img.setAlignment(Element.ALIGN_CENTER); doc.add(img); PdfPTable TB1, TB2, TB3, TB4; TB1 = new PdfPTable(2); TB2 = new PdfPTable(3); TB3 = new PdfPTable(4); TB4 = new PdfPTable(5); PdfPCell T1, T2, T3, T4, T5; T1 = new PdfPCell(new Paragraph("\nCADASTRO DE MUSICAS\n")); T1.setColspan(2); TB1.addCell(T1); T2 = new PdfPCell(new Paragraph("\nGENEROS\n")); T2.setColspan(2); TB1.addCell(T2); ResultSet res, res1, res2, res3; res = ConecBanco.relatorioGenero(); if (res != null) { try { while (res.next()) { TB1.addCell("ID: " + res.getString("id")); TB1.addCell("NOME: " + res.getString("nomeGE")); } doc.add(TB1); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } T3 = new PdfPCell(new Paragraph("\nARTISTAS\n")); T3.setColspan(3); TB2.addCell(T3); res1 = ConecBanco.relatorioArtista(); if (res1 != null) { try { while (res1.next()) { TB2.addCell("ID: " + res1.getString("id")); TB2.addCell("NOME: " + res1.getString("nomeAR")); TB2.addCell("GENERO ID: " + res1.getString("genero_id")); } doc.add(TB2); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } T4 = new PdfPCell(new Paragraph("\nALBUM\n")); T4.setColspan(4); TB3.addCell(T4); res2 = ConecBanco.relatorioAlbum(); if (res2 != null) { try { while (res2.next()) { TB3.addCell("ID: " + res2.getString("id")); TB3.addCell("NOME: " + res2.getString("nomeAL")); TB3.addCell("ANO: " + res2.getString("ano")); TB3.addCell("ARTISTA ID: " + res2.getString("artista_id")); } doc.add(TB3); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } T5 = new PdfPCell(new Paragraph("\nMUSICA\n")); T5.setColspan(5); TB4.addCell(T5); res3 = ConecBanco.relatorioMusica(); if (res3 != null) { try { while (res3.next()) { TB4.addCell("ID: " + res3.getString("id")); TB4.addCell("NOME: " + res3.getString("nome")); TB4.addCell("NOTA: " + res3.getString("nota")); TB4.addCell("DURAO: " + res3.getString("duracao")); TB4.addCell("ALBUM ID: " + res3.getString("album_id")); } doc.add(TB4); } catch (SQLException e) { System.out.println("Problema para exibir registros!"); } } else { System.out.println("A pesquisa no retornou nenhum registro!"); } } finally { if (doc != null) { doc.close(); } if (os != null) { os.close(); } } break; case 5: System.out.println("SAINDO..."); break; default: System.out.println("OPO INVALIDA!"); } } while (opc != 5); }