List of usage examples for com.itextpdf.text.pdf PdfPCell setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
From source file:com.alokomkar.aliensonearth.report.AbstractPdfReport.java
public void addTableColumns(String[] cols, PdfPTable table) { if (cols != null) { for (String colName : cols) { PdfPCell cell = new PdfPCell(new Phrase(colName, smallerBoldFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(0.8f);//from w ww . ja v a2 s. com table.addCell(cell); } } }
From source file:com.asae.controllers.BeanGestionRutinas.java
public void generarPdf() { Document document = new Document(); try {/*from w w w . j av a 2 s. co 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.ashish.medicine.admin.invoice.InvoiceAction.java
private void createTable(Document document) throws DocumentException, MalformedURLException, IOException { PdfPTable table = new PdfPTable(8); table.setWidths(new int[] { 5, 10, 30, 15, 15, 15, 25, 20 }); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); // addLogo(table); String[] headerTitle = { "Sl", "Qty", "Medicine Name", "Mfg Date", "Batch", "Exp Date", "Schedule", "Price" }; Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.BOLD); for (String header : headerTitle) { Phrase p = new Phrase(header, headerFont); PdfPCell c1 = new PdfPCell(p); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setLeading(0f, 1.5f);// w w w. j a v a2 s . com c1.setBackgroundColor(BaseColor.GRAY); table.addCell(c1); } Font contentFont = new Font(Font.FontFamily.TIMES_ROMAN, 9f); MedicineUtility mUtil = new MedicineUtility(); // table.setSpacingAfter(20); double vat = 0.0; double discount = 0.0; int count = 1; double totalAmt = 0.0; if (totalRecords != null && totalRecords.size() > 0) { for (InvoiceBean iBean : totalRecords) { // replaceDoctor = iBean.getDoctorName(); // replaceCustomer = iBean.getCustomerName(); // replaceCustAddr1 = iBean.getCustomerAddr1(); // replaceBillNo = iBean.getBillNo(); // replaceBillDate = iBean.getPurchaseDate(); vat = iBean.getVat(); discount = iBean.getDiscount(); PdfPCell c = new PdfPCell(new Phrase(count++ + "", contentFont)); table.addCell(c); c = new PdfPCell(new Phrase(iBean.getSoldoutStock() + "", contentFont)); table.addCell(c); table.addCell(new PdfPCell(new Phrase(iBean.getMedicineName(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getMfgDate(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getBatchName(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getExpDate(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getSchedule(), contentFont))); totalAmt = totalAmt + (iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice()); table.addCell(new PdfPCell(new Phrase( mUtil.getFormattedAmount((iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice())), contentFont))); } } double grandTotal = 0.0; // Total PdfPCell c1 = new PdfPCell(new Phrase("Total")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(totalAmt))); c1.setColspan(1); table.addCell(c1); // Vat c1 = new PdfPCell(new Phrase("Vat(" + vat + "%)")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); double vatAmt = totalAmt * vat / 100; c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(vatAmt))); c1.setColspan(1); table.addCell(c1); // Discount c1 = new PdfPCell(new Phrase("Discount(" + discount + "%)")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); double discountAmt = totalAmt * discount / 100; c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(discountAmt))); c1.setColspan(1); table.addCell(c1); // Grand Total c1 = new PdfPCell(new Phrase("Grand Total")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); grandTotal = (totalAmt + vatAmt - discountAmt); c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(grandTotal))); c1.setColspan(1); table.addCell(c1); document.add(table); }
From source file:com.automaster.autoview.server.servlet.PdfServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from w ww.j a v a2 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.automated_attendence.servlets.PublishAttendance.java
public void createPdf(String filename, int loop, String course, String dept, String year_id, String semester_id, int totalClass) throws DocumentException, IOException { // step 1/*www . ja v a 2s .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("Hello World!")); // step 5 document.addHeader("name", "yeamin"); document.addTitle("Attendence"); document.add(new Paragraph(String.format( " ResultSheet of Course id %s,Department %s,Year ID %s,Semester ID %s :", course, dept, year_id, semester_id))); document.add(new Paragraph( String.format("\n Total Class : %d ", totalClass))); document.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(2); PdfPCell c1; c1 = new PdfPCell(new Phrase("Reg no")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Attendence")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 1; i <= loop; ++i) { //table.addCell(i+""); //table.addCell(i*i+""); table.addCell(student_reg_arrary[i]); // System.err.println(student_reg_arrary[i]); table.addCell(student_present_day[i]); // System.err.println(student_present_day[i]); } //document.addAuthor("me"); document.add(table); document.close(); }
From source file:com.base2.kagura.core.ExportHandler.java
License:Apache License
/** * Takes the output and transforms it into a PDF file. * @param out Output stream./*from www . j av a 2 s .c o m*/ * @param rows Rows of data from reporting-core * @param columns Columns to list on report */ public void generatePdf(OutputStream out, List<Map<String, Object>> rows, List<ColumnDef> columns) { try { Document document = new Document(); PdfWriter.getInstance(document, out); if (columns == null) { if (rows.size() > 0) return; columns = new ArrayList<ColumnDef>(CollectionUtils.collect(rows.get(0).keySet(), new Transformer() { @Override public Object transform(final Object input) { return new ColumnDef() { { setName((String) input); } }; } })); } if (columns.size() > 14) document.setPageSize(PageSize.A1); else if (columns.size() > 10) document.setPageSize(PageSize.A2); else if (columns.size() > 7) document.setPageSize(PageSize.A3); else document.setPageSize(PageSize.A4); document.open(); Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL, BaseColor.BLACK); Font headerFont = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD, BaseColor.BLACK); int size = columns.size(); PdfPTable table = new PdfPTable(size); for (ColumnDef column : columns) { PdfPCell c1 = new PdfPCell(new Phrase(column.getName(), headerFont)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); } table.setHeaderRows(1); if (rows != null) for (Map<String, Object> row : rows) { for (ColumnDef column : columns) { table.addCell(new Phrase(String.valueOf(row.get(column.getName())), font)); } } document.add(table); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.bdaum.zoom.email.internal.job.PdfJob.java
License:Open Source License
private void printPage(Document document, int pageNo, MultiStatus status, IProgressMonitor monitor) throws DocumentException, IOException { if (pageNo > 1) document.newPage();//from ww w . j ava2 s .co m document.setPageCount(pageNo); final Display display = Display.getDefault(); int pageItem = 0; if (!layout.getTitle().isEmpty()) { String title = PageProcessor.computeTitle(layout.getTitle(), fileName, now, assets.size(), pageNo, pages, collection, meta); Paragraph p = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, titleSize, Font.BOLD, BaseColor.DARK_GRAY)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(layout.getSubtitle().isEmpty() ? titleLead + upperWaste : titleLead); document.add(p); } if (!layout.getSubtitle().isEmpty()) { String subtitle = PageProcessor.computeTitle(layout.getSubtitle(), fileName, now, assets.size(), pageNo, pages, collection, meta); Paragraph p = new Paragraph(subtitle, FontFactory.getFont(FontFactory.HELVETICA, subtitleSize, Font.NORMAL, BaseColor.DARK_GRAY)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(subtitleLead + upperWaste); document.add(p); } IVolumeManager vm = Core.getCore().getVolumeManager(); PdfPTable table = new PdfPTable(layout.getColumns()); try (Assetbox box = new Assetbox(null, status, false)) { for (int i = 0; i < rows; i++) { int ni = i * layout.getColumns(); for (int j = 0; j < layout.getColumns(); j++) { int a = (pageNo - 1) * imagesPerPage + ni + j; PdfPCell cell; if (a >= assets.size() || monitor.isCanceled()) cell = new PdfPCell(); else { final int dpi = quality == Constants.SCREEN_QUALITY ? SCREENDPI : PRINTERDPI; final int pixelWidth = (int) (imageWidth * dpi / 72); final int pixelHeight = (int) (imageHeight * dpi / 72); Asset asset = assets.get(a); zimage = new ZImage(ImageUtilities.loadThumbnail(display, asset.getJpegThumbnail(), cms, SWT.IMAGE_JPEG, true), null); org.eclipse.swt.graphics.Rectangle bounds = zimage.getBounds(); URI uri = vm.findExistingFile(asset, false); if (uri != null) { boolean r = asset.getRotation() % 180 != 0; double w = r ? asset.getHeight() : asset.getWidth(); double h = r ? asset.getWidth() : asset.getHeight(); double scale = w == 0 || h == 0 ? 1d : Math.min(pixelWidth / w, pixelHeight / h); scale = (scale <= 0.5d) ? 0.5d : 1d; File file = box.obtainFile(uri); if (file != null) try { ZImage hzimage = CoreActivator.getDefault().getHighresImageLoader().loadImage( null, status, file, asset.getRotation(), asset.getFocalLengthIn35MmFilm(), null, scale, Double.MAX_VALUE, true, ImageConstants.SRGB, null, unsharpMask, null, fileWatcher, opId, null); if (hzimage != null) { zimage.dispose(); zimage = hzimage; } } catch (UnsupportedOperationException e) { // do nothing } } display.syncExec(() -> { int kl = (keyLine > 0) ? (int) Math.max(1, (keyLine * dpi / 144)) : 0; org.eclipse.swt.graphics.Rectangle ibounds = zimage.getBounds(); double factor = Math.min((double) pixelWidth / ibounds.width, (double) pixelHeight / ibounds.height); int lw = pixelWidth + 2 * kl; int lh = pixelHeight + 2 * kl; Image newImage = new Image(display, lw, lh); GC gc = new GC(newImage); try { gc.setAntialias(SWT.ON); gc.setInterpolation(SWT.HIGH); gc.setAdvanced(true); gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); gc.fillRectangle(0, 0, lw, lh); int width = (int) (ibounds.width * factor + 2 * kl); int height = (int) (ibounds.height * factor + 2 * kl); int xoff = (lw - width) / 2; int yoff = (lh - height) / 2; if (kl > 0) { gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_GRAY)); gc.fillRectangle(xoff, yoff, width, height); } zimage.draw(gc, 0, 0, ibounds.width, ibounds.height, xoff + kl, yoff + kl, width - 2 * kl, height - 2 * kl, ZImage.CROPPED, pixelWidth, pixelHeight, false); } finally { gc.dispose(); zimage.dispose(); zimage = new ZImage(newImage, null); } }); bounds = zimage.getBounds(); File jpegFile = ImageActivator.getDefault().createTempFile("PdfImg", ".jpg"); //$NON-NLS-1$//$NON-NLS-2$ tempFiles.add(jpegFile); try (FileOutputStream out = new FileOutputStream(jpegFile)) { zimage.saveToStream(monitor, true, ZImage.UNCROPPED, SWT.DEFAULT, SWT.DEFAULT, out, SWT.IMAGE_JPEG, jpegQuality); } zimage.dispose(); com.itextpdf.text.Image pdfImage = com.itextpdf.text.Image.getInstance(jpegFile.getPath()); double factor = Math.min(imageWidth / bounds.width, imageHeight / bounds.height); pdfImage.setInterpolation(true); pdfImage.scaleToFit((float) (bounds.width * factor), (float) (bounds.height * factor)); cell = new PdfPCell(pdfImage, false); cell.setHorizontalAlignment(Element.ALIGN_CENTER); monitor.worked(1); } cell.setFixedHeight((float) imageHeight); cell.setBorderWidth(0); table.addCell(cell); } renderCaptions(pageNo, seqNo, pageItem, table, ni, layout.getCaption1()); renderCaptions(pageNo, seqNo, pageItem, table, ni, layout.getCaption2()); pageItem += layout.getColumns(); seqNo += layout.getColumns(); if (verticalGap > 0 && i < rows - 1) for (int j = 0; j < layout.getColumns(); j++) { PdfPCell cell = new PdfPCell(); cell.setFixedHeight(verticalGap); cell.setBorderWidth(0); table.addCell(cell); } } table.setWidthPercentage(100f); document.add(table); if (!layout.getFooter().isEmpty()) { String footer = PageProcessor.computeTitle(layout.getFooter(), fileName, now, assets.size(), pageNo, pages, collection, meta); Paragraph p = new Paragraph(footer, FontFactory.getFont(FontFactory.HELVETICA, subtitleSize, Font.NORMAL, BaseColor.DARK_GRAY)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingBefore(upperWaste / 2 + footerLead); document.add(p); } } }
From source file:com.bdaum.zoom.email.internal.job.PdfJob.java
License:Open Source License
private void renderCaptions(int pageNo, int seqNo, int pageItem, PdfPTable table, int ni, String caption) { if (!caption.isEmpty()) { for (int j = 0; j < layout.getColumns(); j++) { int a = (pageNo - 1) * imagesPerPage + ni + j; PdfPCell cell; if (a >= assets.size()) cell = new PdfPCell(); else { String cc = PageProcessor.computeCaption(caption, Constants.PI_ALL, assets.get(a), collection, seqNo + j + 1, pageItem + j + 1); Paragraph p = new Paragraph(cc, FontFactory.getFont(FontFactory.HELVETICA, fontSize, Font.NORMAL, BaseColor.DARK_GRAY)); p.setSpacingBefore(0);// w w w. j a v a 2s. c o m cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } cell.setBorderWidth(0); table.addCell(cell); } } }
From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java
License:Open Source License
private static PdfPCell createTableHeader(String header, int alignment) { PdfPCell cell = new PdfPCell(new Paragraph(header, FontFactory.getFont(FontFactory.HELVETICA, 10, com.itextpdf.text.Font.BOLD, BaseColor.BLACK))); cell.setBorderColor(new BaseColor(224, 224, 224)); cell.setBorderWidth(1);//from w w w .j a va2s. c o m cell.setPadding(5); cell.setHorizontalAlignment(alignment); return cell; }
From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java
License:Open Source License
private static PdfPCell createTableCell(String value, int alignment) { PdfPCell cell = new PdfPCell(new Paragraph(value, FontFactory.getFont(FontFactory.HELVETICA, 9, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK))); cell.setBorderColor(new BaseColor(224, 224, 224)); cell.setBorderWidth(1);/*from ww w .j a va 2 s .co m*/ cell.setPadding(5); cell.setHorizontalAlignment(alignment); return cell; }