List of usage examples for com.itextpdf.text Element ALIGN_RIGHT
int ALIGN_RIGHT
To view the source code for com.itextpdf.text Element ALIGN_RIGHT.
Click Source Link
From source file:com.asae.controllers.BeanGestionRutinas.java
public void generarPdf() { Document document = new Document(); try {// w w w .ja v a 2 s. c o m File file = File.createTempFile("rutina-", ".pdf", new File("/var/webapp/pdf")); pdfFileName = file.getName(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); Font bold = new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD); URL url = FacesContext.getCurrentInstance().getExternalContext() .getResource("/resources/img/logo-unicauca-negro.png"); Image imgLogoUnicauca = Image.getInstance(url); imgLogoUnicauca.scaleAbsolute(118f, 131f); PdfPTable tableEncabezado = new PdfPTable(2); tableEncabezado.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableEncabezado.setWidthPercentage(100); tableEncabezado.setSpacingAfter(5); PdfPCell cell1 = new PdfPCell(imgLogoUnicauca); cell1.setBorder(Rectangle.NO_BORDER); PdfPCell cell2 = new PdfPCell(new Paragraph("Vicerrectoria Administrativa")); cell2.setBorder(Rectangle.NO_BORDER); cell2.setVerticalAlignment(Element.ALIGN_BOTTOM); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); PdfPCell cell3 = new PdfPCell(new Paragraph("Universidad del Cauca", bold)); cell3.setBorder(Rectangle.NO_BORDER); PdfPCell cell4 = new PdfPCell(new Paragraph("Gimnasio y Actividad Fsica", bold)); cell4.setBorder(Rectangle.NO_BORDER); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); tableEncabezado.addCell(cell1); tableEncabezado.addCell(cell2); tableEncabezado.addCell(cell3); tableEncabezado.addCell(cell4); PdfPTable tableDatosUsuario = new PdfPTable(3); tableDatosUsuario.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableDatosUsuario.setWidthPercentage(100); tableDatosUsuario.setSpacingBefore(20); PdfPCell cell5 = new PdfPCell(new Paragraph("Nombre: " + rutinaVisualizar.getIdusuario().getFisrtname() + " " + rutinaVisualizar.getIdusuario().getSecondname() + " " + rutinaVisualizar.getIdusuario().getFirstlastname() + " " + rutinaVisualizar.getIdusuario().getSecondlastname())); cell5.setBorder(Rectangle.NO_BORDER); PdfPCell cell6 = new PdfPCell(); cell6.setBorder(Rectangle.NO_BORDER); PdfPCell cell7 = new PdfPCell(); cell7.setBorder(Rectangle.NO_BORDER); tableDatosUsuario.addCell(cell5); tableDatosUsuario.addCell(cell6); tableDatosUsuario.addCell(cell7); PdfPTable tableFechas = new PdfPTable(3); tableFechas.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableFechas.setWidthPercentage(100); tableFechas.setSpacingBefore(10); PdfPCell cell8 = new PdfPCell( new Paragraph("Fecha de inicio: " + getMyFormattedDate(rutinaVisualizar.getFechaInicio()))); cell8.setBorder(Rectangle.NO_BORDER); PdfPCell cell9 = new PdfPCell( new Paragraph("Fecha de fin: " + getMyFormattedDate(rutinaVisualizar.getFechaFin()))); cell9.setBorder(Rectangle.NO_BORDER); PdfPCell cell10 = new PdfPCell(); cell10.setBorder(Rectangle.NO_BORDER); tableFechas.addCell(cell8); tableFechas.addCell(cell9); tableFechas.addCell(cell10); PdfPTable tableMedidas = new PdfPTable(4); tableMedidas.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableMedidas.setWidthPercentage(100); tableMedidas.setSpacingBefore(10); Usuario usuAux = rutinaVisualizar.getIdusuario(); List<Evaluacion> lstEvalAux = usuAux.getEvaluacionList(); Evaluacion evalAux; double peso = 0; if (lstEvalAux.size() > 0) { evalAux = lstEvalAux.get(lstEvalAux.size() - 1); peso = evalAux.getPeso().doubleValue(); } double estatura = 0; MedidasGenerales medGenAux = usuAux.getMedidasGenerales(); if (medGenAux != null) { estatura = medGenAux.getEstatura().doubleValue(); } PdfPCell cell11 = new PdfPCell(new Paragraph("Peso: " + peso)); cell11.setBorder(Rectangle.NO_BORDER); PdfPCell cell12 = new PdfPCell(new Paragraph("Talla: " + estatura)); cell12.setBorder(Rectangle.NO_BORDER); double imc = 0; if (peso != 0 && estatura != 0) { imc = peso / Math.pow(estatura, 2); } PdfPCell cell13 = new PdfPCell(new Paragraph("I.M.C: " + imc)); cell13.setBorder(Rectangle.NO_BORDER); PdfPCell cell14 = new PdfPCell(new Paragraph("Rutina: " + rutinaVisualizar.getCodigoRutina())); cell14.setBorder(Rectangle.NO_BORDER); tableMedidas.addCell(cell11); tableMedidas.addCell(cell12); tableMedidas.addCell(cell13); tableMedidas.addCell(cell14); PdfPTable tableDias = new PdfPTable(2); tableDias.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableDias.setWidthPercentage(100); tableDias.setSpacingBefore(20); tableDias.setHorizontalAlignment(Element.ALIGN_LEFT); tableDias.setWidths(new int[] { 1, 9 }); List<Dia> lstDiasPDF = rutinaVisualizar.getDiaList(); PdfPCell cellCabezeraDia = new PdfPCell(new Paragraph("Da", bold)); PdfPCell cellCabezeraDia2 = new PdfPCell(); cellCabezeraDia2.setBorder(Rectangle.NO_BORDER); tableDias.addCell(cellCabezeraDia); tableDias.addCell(cellCabezeraDia2); for (Dia dia : lstDiasPDF) { PdfPCell cellDia = new PdfPCell(new Paragraph(dia.getNumDia().toString())); PdfPCell cellDia2 = new PdfPCell(); cellDia2.setBorder(Rectangle.NO_BORDER); List<GrupoMuscular> lstGMuscularPDF = dia.getGrupoMuscularList(); if (lstGMuscularPDF.size() > 0) { PdfPTable tableGMuscular = new PdfPTable(2); tableGMuscular.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableGMuscular.setWidthPercentage(100); tableGMuscular.setHorizontalAlignment(Element.ALIGN_LEFT); tableGMuscular.setWidths(new int[] { 1, 6 }); PdfPCell cellCabezeraGMuscular = new PdfPCell(new Paragraph("Grupo Muscular", bold)); cellCabezeraGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); PdfPCell cellCabezeraGMuscular2 = new PdfPCell(); cellCabezeraGMuscular2.setBorder(Rectangle.NO_BORDER); tableGMuscular.addCell(cellCabezeraGMuscular); tableGMuscular.addCell(cellCabezeraGMuscular2); int aux = 1; for (GrupoMuscular gMuscularFor : lstGMuscularPDF) { PdfPCell cellGMuscular = new PdfPCell( new Paragraph(gMuscularFor.getIdgrupoMuscularGeneral().getNombre())); cellGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); PdfPCell cellGMuscular2 = new PdfPCell(); cellGMuscular2.setBorder(Rectangle.NO_BORDER); List<EjercicioGm> lstEjerciciosGMuscularPDF = gMuscularFor.getEjercicioGmList(); BaseColor myColor = WebColors.getRGBColor("#CCEEFF"); if (lstEjerciciosGMuscularPDF.size() > 0) { PdfPTable tableEjercicioGMsucular = new PdfPTable(5); tableEjercicioGMsucular.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableEjercicioGMsucular.setWidthPercentage(100); tableEjercicioGMsucular.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cellCabezeraEjercicioGM = new PdfPCell(new Paragraph("Ejercicio", bold)); cellCabezeraEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM.setLeading(20f, 0f); cellCabezeraEjercicioGM.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM); PdfPCell cellCabezeraEjercicioGM2 = new PdfPCell(new Paragraph("Series", bold)); cellCabezeraEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM2.setLeading(20f, 0f); cellCabezeraEjercicioGM2.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM2); PdfPCell cellCabezeraEjercicioGM3 = new PdfPCell(new Paragraph("Repeticiones", bold)); cellCabezeraEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM3.setLeading(20f, 0f); cellCabezeraEjercicioGM3.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM3); PdfPCell cellCabezeraEjercicioGM4 = new PdfPCell(new Paragraph("Receso", bold)); cellCabezeraEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM4.setLeading(20f, 0f); cellCabezeraEjercicioGM4.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM4); PdfPCell cellCabezeraEjercicioGM5 = new PdfPCell(new Paragraph("Peso", bold)); cellCabezeraEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM5.setLeading(20f, 0f); cellCabezeraEjercicioGM5.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM5); int aux2 = 1; for (EjercicioGm ejercicioGm : lstEjerciciosGMuscularPDF) { PdfPCell cellEjercicioGM = new PdfPCell( new Paragraph(ejercicioGm.getEjercicio().getNombre())); cellEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM.setLeading(20f, 0f); PdfPCell cellEjercicioGM2 = new PdfPCell( new Paragraph(ejercicioGm.getNumeroSeries().toString())); cellEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM2.setLeading(20f, 0f); PdfPCell cellEjercicioGM3 = new PdfPCell( new Paragraph(ejercicioGm.getRepeticiones().toString())); cellEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM3.setLeading(20f, 0f); PdfPCell cellEjercicioGM4 = new PdfPCell( new Paragraph(ejercicioGm.getReceso().toString())); cellEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM4.setLeading(20f, 0f); PdfPCell cellEjercicioGM5 = new PdfPCell( new Paragraph(ejercicioGm.getPeso().toString())); cellEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM5.setLeading(20f, 0f); if (aux2 % 2 == 0) { cellEjercicioGM.setBackgroundColor(myColor); cellEjercicioGM2.setBackgroundColor(myColor); cellEjercicioGM3.setBackgroundColor(myColor); cellEjercicioGM4.setBackgroundColor(myColor); cellEjercicioGM5.setBackgroundColor(myColor); } tableEjercicioGMsucular.addCell(cellEjercicioGM); tableEjercicioGMsucular.addCell(cellEjercicioGM2); tableEjercicioGMsucular.addCell(cellEjercicioGM3); tableEjercicioGMsucular.addCell(cellEjercicioGM4); tableEjercicioGMsucular.addCell(cellEjercicioGM5); aux2++; } cellGMuscular2.addElement(tableEjercicioGMsucular); } tableGMuscular.addCell(cellGMuscular); tableGMuscular.addCell(cellGMuscular2); aux++; } cellDia2.addElement(tableGMuscular); } tableDias.addCell(cellDia); tableDias.addCell(cellDia2); } LineSeparator ls = new LineSeparator(); document.add(tableEncabezado); document.add(ls); document.add(tableDatosUsuario); document.add(tableFechas); document.add(tableMedidas); document.add(tableDias); document.close(); } catch (DocumentException | FileNotFoundException e) { e.printStackTrace(); } catch (IOException ex) { Logger.getLogger(BeanGestionRutinas.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java
License:Apache License
/** * header ? footer // w w w .j ava2 s. c o m */ public void onEndPage(PdfWriter writer, Document document) { if (titleFlag) return; Font font = new Font(bfKorean, 9); PdfPTable hTable = new PdfPTable(1); PdfPTable ftable = new PdfPTable(3); try { hTable.setWidths(new int[] { 100 }); hTable.setTotalWidth(500); hTable.setLockedWidth(true); hTable.getDefaultCell().setFixedHeight(15); hTable.getDefaultCell().setBorder(Rectangle.BOTTOM); hTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); hTable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.header.title"), font)); hTable.writeSelectedRows(0, -1, 50, 803, writer.getDirectContent()); ftable.setWidths(new int[] { 100, 100, 100 }); ftable.setTotalWidth(500); ftable.setLockedWidth(true); ftable.getDefaultCell().setBorder(Rectangle.TOP); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); ftable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.footer.left"), font)); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); if (pagingFlag) ftable.addCell(new Phrase( MessageUtil.getMessage("pdf.message.footer.center", String.valueOf(writer.getPageNumber())), font)); else ftable.addCell(""); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); ftable.addCell(new Phrase(String.valueOf(new SimpleDateFormat("yyyy/MM/dd").format(new Date())), font)); ftable.writeSelectedRows(0, -1, 50, 55, writer.getDirectContent()); } catch (Exception de) { throw new ExceptionConverter(de); } }
From source file:com.automaster.autoview.server.servlet.PdfServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {// w w w .j a va 2 s. c o m this.dataAtual = new Date(System.currentTimeMillis()); this.cnpjUn = null; String tempoDecorrido = " 0"; int codVeiculo = Integer.parseInt(request.getParameter("cod")); String placa = request.getParameter("placa"); Timestamp dataInicio = new Timestamp(Long.parseLong(request.getParameter("dataInicio"))); Timestamp dataFim = new Timestamp(Long.parseLong(request.getParameter("dataFim"))); TimeZone timeZonePadrao = TimeZone.getTimeZone(ZoneId.of("-3")); //System.out.println("Time zone : " + timeZonePadrao); ZzzPosPlacaVeiculoDAO zzzPosPlacaVeiculoDAO = new ZzzPosPlacaVeiculoDAO(); VeiculoDAO veiculoDAO = new VeiculoDAO(); TreeMap<String, String> veiculo = veiculoDAO.buscarVeiculoPorCodigo(codVeiculo); placa = veiculo.get("placa"); //System.out.println("PLACA: "+veiculo.get("placa")); ArrayList<TreeMap<String, String>> posicoes = zzzPosPlacaVeiculoDAO .buscarPosicoesPorIntervaloData(placa, dataInicio, dataFim); int codCliente = Integer.parseInt(veiculo.get("clienteCodCliente")); //System.out.println("COD CLIENTE: "+codCliente); ClienteDAO clienteDAO = null; clienteDAO = new ClienteDAO(); TreeMap<String, String> infoClienteUnidade = clienteDAO.buscarPorCodClienteSimplificado(codCliente); // Get the text that will be added to the PDF // step 1 Document document = new Document(); document.addHeader("Adriano", "AutoMaster"); document.addCreator("Adriano Vale"); document.addAuthor("Adriano Vale"); document.addCreationDate(); document.setPageSize(PageSize.A4.rotate()); // step 2 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); TableHeader event = new TableHeader(); writer.setPageEvent(event); // step 3 document.open(); // step 4 //getServletContext().getRealPath("/") String url = getServletContext().getRealPath("/"); //"D:\\Users\\Adriano\\Documents\\NetBeansProjects\\JRGWT\\web\\imagens\\logo.jpg" Image logo = Image.getInstance(url + "/imagens/logo.jpg"); logo.setAlignment(Element.ALIGN_CENTER); Paragraph titulo = new Paragraph("Relatrio de Posies", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 20, Font.BOLD)); titulo.setAlignment(Element.ALIGN_CENTER); Paragraph tituloPlaca = new Paragraph("Veculo: " + placa, new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 16, Font.BOLD)); tituloPlaca.setAlignment(Element.ALIGN_CENTER); SimpleDateFormat dataFormatadaCabecalho = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); dataFormatadaCabecalho.setTimeZone(timeZonePadrao); Date dataHoraInicio0 = new Date(Long.parseLong(request.getParameter("dataInicio"))); Date dataHoraFim0 = new Date(Long.parseLong(request.getParameter("dataFim"))); Paragraph periodo = new Paragraph( "Perodo: De: " + dataFormatadaCabecalho.format(dataHoraInicio0) + " at: " + dataFormatadaCabecalho.format(dataHoraFim0), new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 16, Font.BOLD)); periodo.setSpacingAfter(10.0f); periodo.setAlignment(Element.ALIGN_CENTER); //PdfPTable tabela = new PdfPTable(new float[]{0.11f, 0.095f, 0.06f, 0.065f, 0.085f, 0.06f, 0.04f, 0.065f, 0.055f, 0.06f, 0.24f, 0.065f}); PdfPTable tabela = new PdfPTable(new float[] { 0.07f, 0.045f, 0.045f, 0.27f }); tabela.setWidthPercentage(98.0f); tabela.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell tituloData = new PdfPCell(Phrase.getInstance("Data e Hora")); tituloData.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.addCell(tituloData); //tabela.addCell("Data e hora"); PdfPCell tituloVel = new PdfPCell(Phrase.getInstance("Velocidade")); tituloVel.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.addCell(tituloVel); PdfPCell tituloIgn = new PdfPCell(Phrase.getInstance("Ignio")); tituloIgn.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.addCell(tituloIgn); //tabela.addCell("Latitude"); //tabela.addCell("Longitude"); //tabela.addCell("Satlite"); //tabela.addCell("GPS"); //tabela.addCell("Entrada"); //tabela.addCell("Sada"); //tabela.addCell("Evento"); PdfPCell tituloEnd = new PdfPCell(Phrase.getInstance("Endereo")); tituloEnd.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.addCell(tituloEnd); //tabela.addCell("Direo"); double latAnt = 0; double lonAnt = 0; double latAtual = 0; double lonAtual = 0; double distanciaTotal = 0; double distancia = 0; event.setHeader("AutoMaster"); for (int i = 0; i < posicoes.size(); i++) { //for (int col = 0; col < posicoes.get(i).size(); col++) { if (i == 0) { distancia = 0; //System.out.println("linha 00 - PDF"); } else { //System.out.println("linha 01 - PDF"); latAnt = Double.parseDouble(posicoes.get(i - 1).get("lat")); lonAnt = Double.parseDouble(posicoes.get(i - 1).get("lon")); latAtual = Double.parseDouble(posicoes.get(i).get("lat")); lonAtual = Double.parseDouble(posicoes.get(i).get("lon")); //System.out.println("linha 02 - PDF"); if (latAnt == latAtual && lonAnt == lonAtual) { distancia = 0; } else { distancia = caculaDistanciaEntreDoisPontos(latAnt, lonAnt, latAtual, lonAtual); //System.out.println("linha 03 - PDF"); } } distanciaTotal = distanciaTotal + distancia; //System.out.println("linha 04 - PDF"); //TimeZone.setDefault(timeZoneMundial); Date dataHora0 = new Date(Long.parseLong(posicoes.get(i).get("dataHora"))); //System.out.println("dataHora0 : "+dataHora0.toString()); //TimeZone.setDefault(timeZoneCliente); //Date dataHora = new Date(dataHora0.getTime()); SimpleDateFormat dataFormatada = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); dataFormatada.setTimeZone(timeZonePadrao); //System.out.println("dataFormatada : "+dataFormatada); PdfPCell celData = new PdfPCell(Phrase.getInstance(dataFormatada.format(dataHora0))); celData.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.addCell(celData); //tabela.addCell(dataFormatada); PdfPCell celVel = new PdfPCell(Phrase.getInstance(posicoes.get(i).get("vel"))); celVel.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.addCell(celVel); PdfPCell celIgn = new PdfPCell(Phrase .getInstance(posicoes.get(i).get("ign").equalsIgnoreCase("True") ? "Ligada" : "Desligada")); celIgn.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.addCell(celIgn); //tabela.addCell(posicoes.get(i).get("lat")); //tabela.addCell(posicoes.get(i).get("lon")); //tabela.addCell(posicoes.get(i).get("sat")); //tabela.addCell(posicoes.get(i).get("gps")); //tabela.addCell(posicoes.get(i).get("entrada")); //tabela.addCell(posicoes.get(i).get("saida")); //tabela.addCell(posicoes.get(i).get("evento")); PdfPCell celEnd = new PdfPCell( Phrase.getInstance(posicoes.get(i).get("endereco") == null ? "Sem endereo" : posicoes.get(i).get("endereco"))); celEnd.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.addCell(celEnd); //tabela.addCell(posicoes.get(i).get("direcao")); //} } //System.out.println("linha 05 - PDF"); tempoDecorrido = calculaDatas(Long.parseLong(posicoes.get(0).get("dataHora")), Long.parseLong(posicoes.get(posicoes.size() - 1).get("dataHora"))); //System.out.println("linha 06 - PDF"); int index = 0; String kms = "0"; String m = ""; double metros = 0; //System.out.println("linha 07 - PDF"); if (distanciaTotal > 0) { //System.out.println("linha 08 - PDF"); BigDecimal decimalFormatado = new BigDecimal(distanciaTotal).setScale(2, RoundingMode.HALF_EVEN); //System.out.println("linha 09 - PDF"); index = String.valueOf(decimalFormatado).indexOf("."); kms = String.valueOf(decimalFormatado).substring(0, index); m = "0" + (String.valueOf(decimalFormatado).substring(index)); metros = Double.parseDouble(m) * 1000; //System.out.println("linha 10 - PDF"); } /*document.add(new Paragraph(String.format( "You have submitted the following text using the %s method:", request.getMethod()))); document.add(new Paragraph(text));*/ //System.out.println("linha 11 - PDF"); Paragraph kilometragem = new Paragraph( "Percorridos: " + kms + " KM e " + String.valueOf(metros) + " metros. Tempo: " + tempoDecorrido, new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 16, Font.BOLD)); //System.out.println("linha 12 - PDF"); periodo.setSpacingAfter(10.0f); periodo.setAlignment(Element.ALIGN_CENTER); // step 5 document.add(logo); document.add(titulo); document.add(tituloPlaca); document.add(periodo); document.add(tabela); document.add(kilometragem); String dia = new SimpleDateFormat("dd").format(dataAtual); String ano = new SimpleDateFormat("yyyy").format(dataAtual); int mes = dataAtual.getMonth(); String mesEscrito = null; switch (mes) { case 0: mesEscrito = "janeiro"; break; case 1: mesEscrito = "fevereiro"; break; case 2: mesEscrito = "maro"; break; case 3: mesEscrito = "abril"; break; case 4: mesEscrito = "maio"; break; case 5: mesEscrito = "junho"; break; case 6: mesEscrito = "julho"; break; case 7: mesEscrito = "agosto"; break; case 8: mesEscrito = "setembro"; break; case 9: mesEscrito = "outubro"; break; case 10: mesEscrito = "novembro"; break; case 11: mesEscrito = "dezembro"; break; } String textRodape = infoClienteUnidade.get("cidadeUnidade") + " , " + infoClienteUnidade.get("estadoUnidade") + " " + dia + " de " + mesEscrito + " de " + ano + "."; Paragraph localData = new Paragraph(textRodape, new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.PLAIN)); localData.setAlignment(Element.ALIGN_RIGHT); localData.setSpacingBefore(30.0f); localData.setSpacingAfter(10.0f); document.add(localData); Image assinatura = Image.getInstance(url + "/imagens/assinatura.png"); assinatura.setAlignment(Element.ALIGN_CENTER); assinatura.scaleAbsolute(185, 91); document.add(assinatura); Paragraph infoEmpresa1 = new Paragraph("AUTO MASTER LTDA", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.BOLD)); infoEmpresa1.setAlignment(Element.ALIGN_CENTER); infoEmpresa1.setSpacingAfter(1f); document.add(infoEmpresa1); Paragraph infoEmpresa2 = new Paragraph("___________________________", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.BOLD)); infoEmpresa2.setAlignment(Element.ALIGN_CENTER); document.add(infoEmpresa2); String cnpjEmpresa = formataCNPJ(infoClienteUnidade.get("cnpjUnidade")); Paragraph infoEmpresa3 = new Paragraph(cnpjEmpresa, new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.BOLD)); infoEmpresa3.setAlignment(Element.ALIGN_CENTER); document.add(infoEmpresa3); document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // setting the content type response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=Historico-" + placa + ".pdf"); // the contentlength response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (DocumentException e) { throw new IOException(e.getMessage()); } // response.setContentType("text/html;charset=UTF-8"); // try (PrintWriter out = response.getWriter()) { // /* TODO output your page here. You may use following sample code. */ // out.println("<!DOCTYPE html>"); // out.println("<html>"); // out.println("<head>"); // out.println("<title>Servlet PdfServlet</title>"); // out.println("</head>"); // out.println("<body>"); // out.println("<h1>Servlet PdfServlet at " + request.getContextPath() + "</h1>"); // out.println("</body>"); // out.println("</html>"); // } }
From source file:com.automaster.autoview.server.servlet.TableHeader.java
/** * Adds a header to every page// www . j a v a 2s .com * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage( * com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document) */ public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(3); try { table.setWidths(new int[] { 24, 24, 2 }); table.setTotalWidth(527); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.addCell(header); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(String.format("Pgina %d de", writer.getPageNumber())); PdfPCell cell = new PdfPCell(Image.getInstance(total)); cell.setBorder(Rectangle.BOTTOM); table.addCell(cell); table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent()); } catch (DocumentException de) { throw new ExceptionConverter(de); } }
From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java
License:Open Source License
private void writeDocument(Document document, File targetFile) { boolean frame = detailTabfolder.getSelectionIndex() == 1; try (FileOutputStream out = new FileOutputStream(targetFile)) { PdfWriter writer = PdfWriter.getInstance(document, out); document.open();//from www.j a v a 2 s. c om writer.setPageEvent(new PdfPageEventHelper() { int pageNo = 0; com.itextpdf.text.Font ffont = new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.HELVETICA, 9, com.itextpdf.text.Font.NORMAL, BaseColor.DARK_GRAY); @Override public void onEndPage(PdfWriter w, Document d) { PdfContentByte cb = w.getDirectContent(); Phrase footer = new Phrase(String.valueOf(++pageNo), ffont); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer, (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom(), 0); } }); String tit = NLS.bind(Messages.ExhibitionEditDialog_exhibition_name, nameField.getText()); Paragraph p = new Paragraph(tit, FontFactory.getFont(FontFactory.HELVETICA, 14, com.itextpdf.text.Font.BOLD, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(8); document.add(p); String subtitle = NLS.bind(Messages.ExhibitionEditDialog_image_list, Constants.DFDT.format(new Date()), frame ? Messages.ExhibitionEditDialog_image_sizes : Messages.ExhibitionEditDialog_frame_sizes); p = new Paragraph(subtitle, FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(14); document.add(p); p = new Paragraph(descriptionField.getText(), FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(10); document.add(p); p = new Paragraph(infoField.getText(), FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(10); document.add(p); IDbManager db = Core.getCore().getDbManager(); List<Wall> walls = current.getWall(); Wall[] sortedWalls = walls.toArray(new Wall[walls.size()]); Arrays.sort(sortedWalls, new Comparator<Wall>() { public int compare(Wall o1, Wall o2) { return o1.getLocation().compareToIgnoreCase(o2.getLocation()); } }); for (Wall wall : sortedWalls) { p = new Paragraph(wall.getLocation(), FontFactory.getFont(FontFactory.HELVETICA, 12, com.itextpdf.text.Font.BOLD, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(12); document.add(p); PdfPTable table = new PdfPTable(7); // table.setBorderWidth(1); // table.setBorderColor(new Color(224, 224, 224)); // table.setPadding(5); // table.setSpacing(0); table.setWidths(new int[] { 8, 33, 13, 13, 20, 13, 20 }); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_No, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_title, Element.ALIGN_LEFT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_xpos, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_height, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_size, Element.ALIGN_RIGHT)); table.addCell(createTableHeader(Messages.ExhibitionEditDialog_dpi, Element.ALIGN_RIGHT)); table.addCell(createTableHeader("", Element.ALIGN_LEFT)); //$NON-NLS-1$ // table.endHeaders(); List<ExhibitImpl> exhibits = new ArrayList<ExhibitImpl>(); for (String exhibitId : wall.getExhibit()) { ExhibitImpl exhibit = db.obtainById(ExhibitImpl.class, exhibitId); if (exhibit != null) exhibits.add(exhibit); } Collections.sort(exhibits, new Comparator<ExhibitImpl>() { public int compare(ExhibitImpl e1, ExhibitImpl e2) { return ((Exhibit) e1).getX() - ((Exhibit) e2).getX(); } }); int no = 1; for (ExhibitImpl exhibit : exhibits) { int tara = computeTara(frame, exhibit); table.addCell(createTableCell(String.valueOf(no++), Element.ALIGN_RIGHT)); table.addCell(createTableCell(exhibit.getTitle(), Element.ALIGN_LEFT)); af.setMaximumFractionDigits(2); af.setMinimumFractionDigits(2); String x = af.format((exhibit.getX() - tara) / 1000d); table.addCell(createTableCell(NLS.bind("{0} m", x), Element.ALIGN_RIGHT)); //$NON-NLS-1$ String y = af.format((exhibit.getY() + tara) / 1000d); table.addCell(createTableCell(NLS.bind("{0} m", y), Element.ALIGN_RIGHT)); //$NON-NLS-1$ af.setMaximumFractionDigits(1); af.setMinimumFractionDigits(1); String h = af.format((exhibit.getHeight() + 2 * tara) / 10d); int width = exhibit.getWidth(); String w = af.format((width + 2 * tara) / 10d); table.addCell(createTableCell(NLS.bind("{0} x {1} cm", w, h), Element.ALIGN_RIGHT)); //$NON-NLS-1$ AssetImpl asset = dbManager.obtainAsset(exhibit.getAsset()); if (asset != null) { int pixels = asset.getWidth(); double dpi = pixels * 25.4d / width; table.addCell(createTableCell(String.valueOf((int) dpi), Element.ALIGN_RIGHT)); } else table.addCell(""); //$NON-NLS-1$ table.addCell(createTableCell(exhibit.getSold() ? Messages.ExhibitionEditDialog_sold : "", //$NON-NLS-1$ Element.ALIGN_LEFT)); } document.add(table); } document.close(); } catch (DocumentException e) { UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_internal_error_writing_pdf, e); } catch (IOException e) { UiActivator.getDefault().logError(Messages.ExhibitionEditDialog_io_error_writing_pdf, e); } }
From source file:com.bougsid.printers.PrintMission.java
public void printMission(Mission mission) { Document document = new Document(PageSize.A4); try {/*from w w w. j a va2s .c o m*/ File downloadDir = new File(msg.getMessage("application.mission.downloaddir")); if (!downloadDir.exists()) { downloadDir.mkdir(); } System.out.println("Dir =" + downloadDir.getPath()); PdfWriter.getInstance(document, new FileOutputStream(downloadDir.getPath() + "/" + mission.getUuid() + ".pdf")); document.open(); Paragraph p = new Paragraph(); p.setSpacingAfter(60); document.add(p); //header Paragraph paragraph = new Paragraph( msg.getMessage("mission.pdf.school") + " " + mission.getIdMission() + " ", DEFAULT_FONT); Phrase phrase = new Phrase(msg.getMessage("mission.pdf.city") + " " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); paragraph.add(phrase); paragraph.setSpacingAfter(50); document.add(paragraph); //title PdfPTable table = new PdfPTable(1); table.setWidthPercentage(40); PdfPCell cell = new PdfPCell(new Phrase(msg.getMessage("mission.pdf.title"), FontFactory.getFont(FontFactory.HELVETICA, 18))); cell.setBorderWidth(1); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setSpacingAfter(40); document.add(table); //content table = new PdfPTable(2); table.setWidthPercentage(100); //line 1 cell = new PdfPCell(new Paragraph(mission.getEmploye().getCivilite().getLabel(), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFullName(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 2 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.matricule"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getMatricule(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 3 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.grade"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFonction(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); if (mission.getEntreprise() != null) { //line 4 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1_2"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 5 cell = new PdfPCell(new Paragraph(" ", DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(" - " + mission.getEntreprise().getNom(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); } //line 6 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.lieu"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); p = new Paragraph(); p.setFont(DEFAULT_FONT); for (Ville ville : mission.getVilles()) { p.add(ville.getNom() + "\n"); } cell = new PdfPCell(p); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 7 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.startdate"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph( ": " + mission.getStartDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + " Heure : " + mission.getStartDate().format(DateTimeFormatter.ofPattern("HH:mm")), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 8 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.enddate"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph( ": " + mission.getEndDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + " Heure : " + mission.getEndDate().format(DateTimeFormatter.ofPattern("HH:mm")), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 9 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.transport"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); switch (mission.getTransportType()) { case PERSONNEL: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.perso") + " " + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; case Accompagnement: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.accomp") + " " + mission.getAccompEmploye().getCivilite() + " " + mission.getAccompEmploye().getFullName() + " " + msg.getMessage("mission.pdf.accomp.voitue") + " " + mission.getAccompEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getAccompEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; case Service: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.service") + " " + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; default: { cell = new PdfPCell(new Paragraph( ": " + mission.getTransportType().getLabel() + " " + msg.getMessage("mission.pdf.taxi"), DEFAULT_FONT)); } } cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); table.setSpacingAfter(40); document.add(table); //note document.add(new Paragraph(msg.getMessage("mission.pdf.TEXT_2"), DEFAULT_FONT)); //signature if (mission.getEmploye().getGrade().getType() == GradeType.DG) { } else { Employe dir = employeService.getDG(); if (dir != null) paragraph = new Paragraph(dir.getFullName(), DEFAULT_FONT); paragraph.setAlignment(Element.ALIGN_RIGHT); paragraph.setSpacingBefore(40); document.add(paragraph); paragraph = new Paragraph(msg.getMessage("mission.pdf.DG"), DEFAULT_FONT); paragraph.setAlignment(Element.ALIGN_RIGHT); document.add(paragraph); } } catch (DocumentException ex) { ex.printStackTrace(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } document.close(); // try { // Desktop.getDesktop().open(new File("./order.pdf")); // } catch (IOException ex) { // JOptionPane.showMessageDialog(null, "Fichier gner mais ne peut pas etre ouvert vrifier le dossier"); // } }
From source file:com.chaschev.itext.CellBuilder.java
License:Apache License
public CellBuilder alignRight() { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); return this; }
From source file:com.cyberninjas.pdf.PdfEditor.java
License:Open Source License
/** * Converts an {@link Alignment} to a value recognized by iText. * * @param align the alignment type./*w w w .ja va 2s.c om*/ * @return the horizontal alignment recognized by iText. */ private int convertHorizontalAlignment(final Alignment align) { switch (align) { case LEFT: return Element.ALIGN_LEFT; case RIGHT: return Element.ALIGN_RIGHT; case CENTER: return Element.ALIGN_CENTER; default: return Element.ALIGN_UNDEFINED; } }
From source file:com.docdoku.server.extras.TitleBlockGenerator.java
License:Open Source License
protected void generateTable(Paragraph preface, ResourceBundle bundle) { // Author + date PdfPTable table = new PdfPTable(2); table.setWidthPercentage(TABLE_PERCENT_WIDTH); PdfPCell cell;/*from www . j a va 2 s .c om*/ cell = new PdfPCell(new Phrase(authorName, NORMAL_12)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(creationDate, NORMAL_12)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); preface.add(table); addEmptyLine(preface, 1); preface.add(new Paragraph(bundle.getString("iteration"), BOLD_12)); addEmptyLine(preface, 1); PdfPTable iterationTable = new PdfPTable(5); iterationTable.setWidthPercentage(TABLE_PERCENT_WIDTH); // Table header cell = new PdfPCell(new Phrase(bundle.getString("iteration.version"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("iteration.iteration"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("iteration.date"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("iteration.author"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(bundle.getString("iteration.Notes"), BOLD_12)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); iterationTable.addCell(cell); // Table body cell = new PdfPCell(new Phrase(version, NORMAL_12)); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(currentIteration, NORMAL_12)); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(iterationDate, NORMAL_12)); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(authorName, NORMAL_12)); iterationTable.addCell(cell); cell = new PdfPCell(new Phrase(revisionNote, NORMAL_12)); iterationTable.addCell(cell); preface.add(iterationTable); }
From source file:com.gadroves.gsisinve.controller.FacturarController.java
void PrintToPDF(TbFacturaVenta facturaVenta, TbCLienteFactura cLienteFactura) throws DocumentException, IOException { Font header = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font normalBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font normal = new Font(Font.FontFamily.HELVETICA, 12); String fileName = "Factura_" + facturaVenta.getId() + ".pdf"; // step 1/* www. jav a 2 s .c o m*/ Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(fileName)); // step 3 document.open(); // step 4 document.add(new Paragraph("Gadroves S.A Factura De Venta", header)); document.add(new Paragraph(" ")); document.add(new Paragraph("Factura N" + facturaVenta.getId(), normalBold)); document.add(new Chunk("Cliente: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getName(), normal)); document.add(new Paragraph()); document.add(new Chunk("Direccin: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getAddress(), normal)); document.add(new Paragraph()); document.add(new Chunk("Identificacion: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(cLienteFactura.getId(), normal)); document.add(new Paragraph()); document.add(new Chunk("Credito: ", normalBold)); document.add(new Chunk(" ")); document.add(new Chunk(Boolean.FALSE.toString(), normal)); document.add(new Paragraph()); for (int i = 0; i < 3; i++) document.add(new Paragraph(" ")); createItemsTable(document, facturaVenta); document.add(new Paragraph(" ")); Paragraph subs = new Paragraph(); subs.setAlignment(Element.ALIGN_RIGHT); subs.setIndentationRight(40); subs.add(new Chunk("Subtotal: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getSub())))); subs.add(Chunk.NEWLINE); subs.add(new Chunk( "Impuestos: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getImpuestos())))); subs.add(Chunk.NEWLINE); subs.add(new Chunk( "Total: " + String.format("%1$" + 10 + "s", String.valueOf(facturaVenta.getTotal())))); subs.add(Chunk.NEWLINE); document.add(subs); // step 5 document.close(); Desktop.getDesktop().open(new File(fileName)); }