List of usage examples for com.lowagie.text.pdf PdfPTable setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
From source file:lmcpointofsalessystem.PDFOrders.java
public PDFOrders(String tblName) throws IOException { try {// w ww.j a va2 s .c om LMCPointofSalesSystem connect = new LMCPointofSalesSystem(); con = connect.con; st = connect.s; Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0); PdfWriter.getInstance(document, new FileOutputStream(tblName + ".pdf")); document.open(); Image image = Image.getInstance("src/lmcpointofsalessystem/Assets/header3.png"); document.add(image); document.setMarginMirroring(true); PdfPTable newheaderTable; newheaderTable = getDatas(tblName); newheaderTable.setHorizontalAlignment(Element.ALIGN_CENTER); document.add(newheaderTable); document.close(); } catch (FileNotFoundException ex) { Logger.getLogger(PDFEmployees.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(PDFEmployees.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:mitm.common.pdf.MessagePDFBuilder.java
License:Open Source License
private void addReplyLink(Document document, String replyURL) throws DocumentException { PdfPTable replyTable = new PdfPTable(1); replyTable.setWidthPercentage(100f); replyTable.setSplitLate(false);//from w w w. j av a 2s . c o m replyTable.setSpacingBefore(5f); replyTable.setHorizontalAlignment(Element.ALIGN_LEFT); Font linkFont = new Font(); linkFont.setStyle(Font.BOLD); linkFont.setColor(0, 0, 255); linkFont.setSize(headerFontSize); Chunk anchor = new Chunk("Reply", linkFont); anchor.setAnchor(replyURL); Phrase phrase = new Phrase(); phrase.add(anchor); PdfPCell cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); replyTable.addCell(cell); document.add(replyTable); }
From source file:mitm.common.pdf.MessagePDFBuilder.java
License:Open Source License
public void buildPDF(MimeMessage message, String replyURL, OutputStream pdfStream) throws DocumentException, MessagingException, IOException { Document document = createDocument(); PdfWriter pdfWriter = createPdfWriter(document, pdfStream); document.open();//from ww w. j ava 2s . co m String[] froms = null; try { froms = EmailAddressUtils.addressesToStrings(message.getFrom(), true /* mime decode */); } catch (MessagingException e) { logger.warn("From address is not a valid email address."); } if (froms != null) { for (String from : froms) { document.addAuthor(from); } } String subject = null; try { subject = message.getSubject(); } catch (MessagingException e) { logger.error("Error getting subject.", e); } if (subject != null) { document.addSubject(subject); document.addTitle(subject); } String[] tos = null; try { tos = EmailAddressUtils.addressesToStrings(message.getRecipients(RecipientType.TO), true /* mime decode */); } catch (MessagingException e) { logger.warn("To is not a valid email address."); } String[] ccs = null; try { ccs = EmailAddressUtils.addressesToStrings(message.getRecipients(RecipientType.CC), true /* mime decode */); } catch (MessagingException e) { logger.warn("CC is not a valid email address."); } Date sentDate = null; try { sentDate = message.getSentDate(); } catch (MessagingException e) { logger.error("Error getting sent date.", e); } Collection<Part> attachments = new LinkedList<Part>(); String body = BodyPartUtils.getPlainBodyAndAttachments(message, attachments); attachments = preprocessAttachments(attachments); if (body == null) { body = MISSING_BODY; } /* * PDF does not have tab support so we convert tabs to spaces */ body = StringReplaceUtils.replaceTabsWithSpaces(body, tabWidth); PdfPTable headerTable = new PdfPTable(2); headerTable.setHorizontalAlignment(Element.ALIGN_LEFT); headerTable.setWidthPercentage(100); headerTable.setWidths(new int[] { 1, 6 }); headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); Font headerFont = createHeaderFont(); FontSelector headerFontSelector = createHeaderFontSelector(); PdfPCell cell = new PdfPCell(new Paragraph("From:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); String decodedFroms = StringUtils.defaultString(StringUtils.join(froms, ", ")); headerTable.addCell(headerFontSelector.process(decodedFroms)); cell = new PdfPCell(new Paragraph("To:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(StringUtils.join(tos, ", ")))); cell = new PdfPCell(new Paragraph("CC:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(StringUtils.join(ccs, ", ")))); cell = new PdfPCell(new Paragraph("Subject:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(subject))); cell = new PdfPCell(new Paragraph("Date:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); headerTable.addCell(ObjectUtils.toString(sentDate)); cell = new PdfPCell(new Paragraph("Attachments:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); headerTable .addCell(headerFontSelector.process(StringUtils.defaultString(getAttachmentHeader(attachments)))); document.add(headerTable); if (replyURL != null) { addReplyLink(document, replyURL); } /* * Body table will contain the body of the message */ PdfPTable bodyTable = new PdfPTable(1); bodyTable.setWidthPercentage(100f); bodyTable.setSplitLate(false); bodyTable.setSpacingBefore(15f); bodyTable.setHorizontalAlignment(Element.ALIGN_LEFT); addBodyAndAttachments(pdfWriter, document, bodyTable, body, attachments); Phrase footer = new Phrase(FOOTER_TEXT); PdfContentByte cb = pdfWriter.getDirectContent(); ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, footer, document.right(), document.bottom(), 0); document.close(); }
From source file:mx.avanti.siract.ui.RACTBeanUI.java
public void postProcessPDF(Object document) throws IOException, DocumentException { final Document pdf = (Document) document; TreeNode[] selectedNodesPDF = selectedNodes; if (selectedNodes != null) { for (TreeNode nodo : selectedNodes) { System.out.println("*********************" + ((NodoMultiClass) nodo.getData()).getNombre()); }/*from www . j av a 2 s . com*/ } pdf.setPageSize(PageSize.A4.rotate()); pdf.open(); String nombrep = profesor.getPronombre() + " " + profesor.getProapellidoPaterno() + " " + profesor.getProapellidoMaterno(); String numEmpPro = Integer.toString(profesor.getPronumeroEmpleado()); String porAv = Float.toString(porcentajeAvance); SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy"); //Obtener el nombre del programa educativo seleccionado String nombreProgEdu = ""; int programaEducativoSeleccionado2 = Integer.parseInt(programaEducativoSeleccionado); for (int x = 0; x < programasEducativos.size(); x++) { if (programasEducativos.get(x).getPedid() == programaEducativoSeleccionado2) { nombreProgEdu = programasEducativos.get(x).getPednombre(); } } //---------------------------------------------------------------------------------- //Obtener el nombre de la unidad de aprendizaje y clave seleccionada String nombreUniApr = ""; String nombreclave = ""; int uniAprselec2 = Integer.parseInt(unidadAprendizajeSeleccionada); for (int x = 0; x < unidadesaprendisaje.size(); x++) { if (unidadesaprendisaje.get(x).getUapclave() == uniAprselec2) { nombreUniApr = unidadesaprendisaje.get(x).getUapnombre(); nombreclave = Integer.toString(unidadesaprendisaje.get(x).getUapclave()); } } //---------------------------------------------------------------------- // rutaImagen es la ruta para acceder a la imagen guardada en el folder resources del proyecto try { // Image imagenLogo = Image.getInstance("C:\\Users\\Y\\Desktop\\RACT 22-01-2015\\RACT\\build\\web\\resources\\imagenes\\logo.jpg"); Image imagenLogo = Image.getInstance(RACTBeanUI.class.getResource("imagenes/logo.jpg")); //Posicion de imagen (Horizontal, Vertiacal) imagenLogo.setAbsolutePosition(120f, 460f); //Tamao de imagen (Ancho, largo) imagenLogo.scaleAbsolute(90, 120); //imagenLogo.scaleAbsoluteWidth(100f); //imagenLogo.scaleAbsoluteHeight(150f); //imagenLogo.scaleToFit(100f, 120f); Esta es la buena //Image imagenLogo = Image.getInstance("http://ed.uabc.mx/sed/images/logo.jpg"); //imagenLogo.scaleAbsolute(70f, 90f); pdf.add(imagenLogo); } catch (Exception exception) { System.out.println("****NO SE ENCONTRO LA RUTA DE IMAGEN ESPECIFICADA"); } //Tabla con UABC y Nombre del profesor(a) PdfPTable pdfTabletitulo = new PdfPTable(2); pdfTabletitulo.getDefaultCell().setBorder(PdfPCell.NO_BORDER); PdfPTable pdfTabletitulo2 = new PdfPTable(2); pdfTabletitulo2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); Paragraph UABC = new Paragraph("Universidad Autnoma de Baja California", FontFactory.getFont(FontFactory.TIMES, 22, Font.BOLD, new Color(0, 113, 65))); UABC.setAlignment(Element.ALIGN_CENTER); Paragraph esp = new Paragraph(" "); pdf.add(UABC); pdf.add(esp); pdf.add(esp); pdf.add(esp); pdf.add(esp); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("Profesor(a): ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdfTabletitulo.addCell(new Paragraph(nombrep)); pdfTabletitulo2.addCell(new Paragraph("Num. de Empleado: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdfTabletitulo2.addCell(new Paragraph(numEmpPro)); pdfTabletitulo.setHorizontalAlignment(25); //pdfTabletitulo.setHorizontalAlignment(Element.ALIGN_CENTER); //document.add(table); float[] columnWidthsss = new float[] { 4f, 28 }; pdfTabletitulo.setWidths(columnWidthsss); pdf.add(pdfTabletitulo); float[] columnWidthss = new float[] { 10f, 38 }; pdfTabletitulo2.setWidths(columnWidthss); pdf.add(pdfTabletitulo2); pdf.add(new Phrase(" ")); //---------------------------------------------------------------------- //Tabla Cabezera PdfPTable pdftablecabezera = new PdfPTable(4); pdftablecabezera.getDefaultCell().setBorder(PdfPCell.NO_BORDER); PdfPTable pdftablecabezera2 = new PdfPTable(5); pdftablecabezera2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); pdftablecabezera.addCell(new Paragraph("Programa educativo: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera.addCell(new Paragraph("Fecha: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera.addCell(new Paragraph("Ciclo Escolar: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera.addCell(new Paragraph("Avance Global: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera.addCell(new Paragraph(nombreProgEdu)); pdftablecabezera.addCell(new Paragraph(formato.format(new Date()))); pdftablecabezera.addCell(new Paragraph(" " + cicloEscolar)); pdftablecabezera.addCell(new Paragraph(" " + porAv)); pdftablecabezera.addCell(new Paragraph(" ")); pdftablecabezera.addCell(new Paragraph(" ")); pdftablecabezera.addCell(new Paragraph(" ")); pdftablecabezera.addCell(new Paragraph(" ")); pdftablecabezera2.addCell(new Paragraph("Unidad de Aprendizaje: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera2.addCell(new Paragraph("Clave: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera2.addCell(new Paragraph("Grupo: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera2.addCell(new Paragraph("Subgrupo: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera2.addCell(new Paragraph("Tipo Grupo: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera2.addCell(new Paragraph(nombreUnidadSeleccionado)); pdftablecabezera2.addCell(new Paragraph(claveUnidadAprendizajeSeleccionada)); pdftablecabezera2.addCell(new Paragraph(" " + grupo)); pdftablecabezera2.addCell(new Paragraph(" " + subGrupo)); String tipoGrupo = ""; switch (this.tipoUnidadAprendizaje) { case "C": tipoGrupo = "Clase"; break; case "L": tipoGrupo = "Laboratorio"; break; case "T": tipoGrupo = "Taller"; break; case "P": tipoGrupo = "Practica"; break; case "CL": tipoGrupo = "Practicas Clinica"; break; } pdftablecabezera2.addCell(new Paragraph(" " + tipoGrupo)); pdftablecabezera2.addCell(new Paragraph(" ")); pdftablecabezera.setHorizontalAlignment(25); float[] columnWidths = new float[] { 38f, 10f, 14f, 18f }; pdftablecabezera.setWidths(columnWidths); pdf.add(pdftablecabezera); pdftablecabezera2.setHorizontalAlignment(25); float[] columnWidthss2 = new float[] { 38f, 10f, 8f, 11f, 14f }; pdftablecabezera2.setWidths(columnWidthss2); pdf.add(pdftablecabezera2); pdf.add(new Phrase(" ")); //---------------------------------------------------------------------- Paragraph numrep = new Paragraph("Reporte # " + numeroReporte, FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLD, new Color(0, 0, 0))); numrep.setAlignment(Element.ALIGN_CENTER); pdf.add(numrep); pdf.add(new Paragraph(" ")); //Tabla con Datos PdfPTable pdfTable = new PdfPTable(3); pdfTable.addCell(new Phrase("Nombre", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0)))); pdfTable.addCell(new Phrase("Porcentaje", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0)))); pdfTable.addCell(new Phrase("Observaciones", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0)))); //Evitar Null pointer exception por no tener nodoes en selectedNodes //Se utiliza un auxiliar de selectedNodes por que hay posibilidad de que selectedNodes se modifique durante el proceso de generacion del PDF if (selectedNodesPDF != null && selectedNodesPDF.length > 0) { //Regresar a lo basicoString int nns = selectedNodesPDF.length; String[] ns = new String[nns]; for (int x = 0; x < selectedNodesPDF.length; x++) { ns[x] = ((NodoMultiClass) selectedNodesPDF[x].getData()).getNumero() + "--" + ((NodoMultiClass) selectedNodes[x].getData()).getNombre() + "--" + ((NodoMultiClass) selectedNodes[x].getData()).getPorcentajeAvance() + "--" + ((NodoMultiClass) selectedNodes[x].getData()).getObservaciones() + " -- "; } String[] filas = new String[4]; String[] nstr = new String[3]; String[] filas2 = new String[4]; String[] nstr2 = new String[3]; for (int x = 1; x < ns.length; x++) { for (int y = 0; y < ns.length - x; y++) { //Obtengo los valores para hacer las comparaciones int[] n = new int[3]; int[] n2 = new int[3]; filas = ns[y].split("--"); nstr = filas[0].split("\\."); for (int z = 0; z < nstr.length; z++) { if (nstr == null) { n[z] = 0; } else { n[z] = Integer.parseInt(nstr[z]); } } filas2 = ns[y + 1].split("--"); nstr2 = filas2[0].split("\\."); for (int z = 0; z < nstr2.length; z++) { if (nstr2 == null) { n2[z] = 0; } else { n2[z] = Integer.parseInt(nstr2[z]); } } //-------------------------------------------------comparacion if (n[0] == n2[0]) { if (n[1] == n2[1]) { if (n[2] > n2[2]) { String aux = ns[y]; ns[y] = ns[y + 1]; ns[y + 1] = aux; } } else { if (n[1] > n2[1]) { String aux = ns[y]; ns[y] = ns[y + 1]; ns[y + 1] = aux; } } } else { if (n[0] > n2[0]) { String aux = ns[y]; ns[y] = ns[y + 1]; ns[y + 1] = aux; } } //------------------------------------------------------------- } } String[] auxNum = new String[4]; for (int x = 0; x < ns.length; x++) { filas = ns[x].split("--"); num = filas[0].split("\\."); //Auxiliar para agregar padre de tema/subtema int auxMargen = 1; //Agregar unidad a la que pertenece el tema/subtema String[] auxNum2 = auxNum; int tamanoArbol = root.getChildCount(); //AGREGAR A TEMA if (Integer.parseInt(num[0]) > tamanoArbol) { auxMargen = Integer.parseInt(num[0]) - tamanoArbol; } if (num.length >= 2 && auxNum2[0] != null && !auxNum2[0].equals(num[0])) { if (!num[1].equals("0")) { while (!num[0].equals(auxNum2[0]) && auxMargen > 0) { System.out.println("XXXXXXIteracion para encontrar padre XXXXXXX 0" + auxMargen); auxNum2 = (((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNumero()).split("\\."); //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){ if (num[0].equals(auxNum2[0])) { } else { auxMargen--; } } System.out.println("***Unidad Padre" + ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNombre()); NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()); //UTIL PARA PONER TEXTO TACHADO // Chunk strikethrough = new Chunk("Strikethrough."); // strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location // document.add(strikethrough); pdfTable.addCell(new Phrase(auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(auxNodo.getObservaciones()); } } else { if (auxNum2[0] == null && num.length >= 2) { auxNum2 = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen) .getData()).getNumero()).split("\\."); while (!num[0].equals(auxNum2[0]) && auxMargen > 0) { System.out.println("XXXXXXIteracion para encontrar padre XXXXXXX 0" + auxMargen); auxNum2 = (((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNumero()).split("\\."); //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){ if (num[0].equals(auxNum2[0])) { } else { auxMargen--; } } System.out.println("***Unidad Padre" + ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNombre()); NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()); //UTIL PARA PONER TEXTO TACHADO // Chunk strikethrough = new Chunk("Strikethrough."); // strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location // document.add(strikethrough); pdfTable.addCell(new Phrase(auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(auxNodo.getObservaciones()); } } //AGREGAR A SUBTEMA String[] auxNumeroUnidad = new String[4]; int auxMargen2 = 1; if (num.length == 3 && auxNum[1] != null && !auxNum[1].equals(num[1])) { if (!num[2].equals("0")) { while (!num[0].equals(auxNum[0]) && auxMargen >= 0) { NodoMultiClass auxNodoUnidad = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()); auxNumeroUnidad = auxNodoUnidad.getNumero().split("\\."); tamanoArbol = root.getChildren().get(Integer.parseInt(num[0])).getChildCount(); if (Integer.parseInt(num[1]) > tamanoArbol) { auxMargen2 = Integer.parseInt(num[1]) - tamanoArbol; } while (auxNumeroUnidad[0].equals(num[0]) && !num[1].equals(auxNum[1]) && auxMargen > 0) { System.out.println("XXXXXXIteracion para encontrar padre XXXXXXX 0" + auxMargen); auxNum = (((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getChildren() .get(Integer.parseInt(num[1]) - auxMargen2).getData()).getNumero()) .split("\\."); //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){ if (num[1].equals(auxNum[1])) { } else { auxMargen2--; } } // auxNum = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[1]) - auxMargen).getData()).getNumero()).split("\\."); if (num[0].equals(auxNum[0])) { } else { auxMargen--; } } System.out.println("*****Unidad Padre(SUBTEMA)" + ((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen) .getChildren().get(Integer.parseInt(num[1]) - auxMargen2).getData()) .getNombre()); NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getChildren() .get(Integer.parseInt(num[1]) - auxMargen2).getData()); //UTIL PARA PONER TEXTO TACHADO // Chunk strikethrough = new Chunk("Strikethrough."); // strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location // document.add(strikethrough); pdfTable.addCell( new Phrase(" " + auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(auxNodo.getObservaciones()); } } else { if (auxNum[0] == null && num.length == 3) { auxNum = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen) .getData()).getNumero()).split("\\."); while (!num[0].equals(auxNum[0]) && auxMargen > 0) { NodoMultiClass auxNodoUnidad = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()); auxNumeroUnidad = auxNodoUnidad.getNumero().split("\\."); tamanoArbol = root.getChildren().get(Integer.parseInt(num[0])).getChildCount(); if (Integer.parseInt(num[1]) > tamanoArbol) { auxMargen2 = Integer.parseInt(num[1]) - tamanoArbol; } while (auxNumeroUnidad[0].equals(num[0]) && !num[1].equals(auxNum[1]) && auxMargen > 0) { System.out.println("Iteracion para encontrar padre XXXXXXX 0" + auxMargen); auxNum = (((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getChildren() .get(Integer.parseInt(num[1]) - auxMargen2).getData()).getNumero()) .split("\\."); //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){ if (num[1].equals(auxNum[1])) { } else { auxMargen2--; } } // auxNum = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[1]) - auxMargen).getData()).getNumero()).split("\\."); if (num[0].equals(auxNum[0])) { } else { auxMargen--; } } System.out.println("***Unidad Padre(SUBTEMA)" + ((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen) .getChildren().get(Integer.parseInt(num[1]) - auxMargen2).getData()) .getNombre()); NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getChildren() .get(Integer.parseInt(num[1]) - auxMargen2).getData()); //UTIL PARA PONER TEXTO TACHADO // Chunk strikethrough = new Chunk("Strikethrough."); // strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location // document.add(strikethrough); pdfTable.addCell( new Phrase(" " + auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(auxNodo.getObservaciones()); } } auxNum = num; //FIN AGREGAR PADRE DE TEMA/SUBTEMA boolean banpor = true; if (num.length == 1) { pdfTable.addCell(new Phrase(filas[0] + ".- " + filas[1], FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0)))); pdfTable.addCell(new Phrase(String.valueOf(dosDecimales(Float.parseFloat(filas[2]))), FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0)))); banpor = false; } if (num.length == 2) { pdfTable.addCell(new Phrase(" " + filas[0] + ".- " + filas[1])); } if (num.length == 3) { pdfTable.addCell(new Phrase(" " + filas[0] + ".- " + filas[1], FontFactory.getFont(FontFactory.TIMES_ITALIC, 12))); pdfTable.addCell(new Phrase(String.valueOf(dosDecimales(Float.parseFloat(filas[2]))), FontFactory.getFont(FontFactory.TIMES_ITALIC, 12))); banpor = false; } if (banpor) { pdfTable.addCell(String.valueOf(dosDecimales(Float.parseFloat(filas[2])))); pdfTable.addCell(filas[3]); } else { pdfTable.addCell(filas[3]); } } } else { pdfTable.addCell("No hay nada seleccionado"); pdfTable.addCell(""); pdfTable.addCell(""); } pdfTable.setHorizontalAlignment(15); float[] columnWidths2 = new float[] { 32f, 8f, 14f }; pdfTable.setWidths(columnWidths2); pdf.add(pdfTable); //---------------------------------------------------------------------- }
From source file:net.bull.javamelody.internal.web.pdf.PdfCoreReport.java
License:Apache License
private void writeGraphDetails() throws IOException, DocumentException { if (collector.isStopped()) { return;//w ww.j ava 2s. c o m } final PdfPTable jrobinTable = new PdfPTable(1); jrobinTable.setHorizontalAlignment(Element.ALIGN_CENTER); jrobinTable.setWidthPercentage(100); jrobinTable.getDefaultCell().setBorder(0); if (largeGraphs != null) { // si les graphiques ont t prinitialiss (en Swing) alors on les utilise for (final byte[] imageData : largeGraphs.values()) { final Image image = Image.getInstance(imageData); jrobinTable.addCell(image); } } else { final Collection<JRobin> counterJRobins = collector.getDisplayedCounterJRobins(); if (counterJRobins.isEmpty()) { return; } for (final JRobin jrobin : counterJRobins) { // la hauteur de l'image est prvue pour qu'il n'y ait pas de graph seul sur une page final Image image = Image.getInstance(jrobin.graph(range, LARGE_GRAPH_WIDTH, LARGE_GRAPH_HEIGHT)); jrobinTable.addCell(image); } } newPage(); addToDocument(jrobinTable); newPage(); }
From source file:net.bull.javamelody.internal.web.pdf.PdfJavaInformationsReport.java
License:Apache License
private static PdfPTable createJavaInformationsTable() throws DocumentException { final PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100);// ww w .j a va 2s. c om table.setWidths(new int[] { 2, 8 }); table.getDefaultCell().setBorder(0); return table; }
From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java
License:Apache License
private void writeRequestRumData() throws DocumentException { final CounterRequestRumData rumData = request.getRumData(); final DecimalFormat percentFormat = I18N.createPercentFormat(); final int networkTimeMean = rumData.getNetworkTimeMean(); final int serverMean = request.getMean(); final int domProcessingMean = rumData.getDomProcessingMean(); final int pageRenderingMean = rumData.getPageRenderingMean(); final int totalTime = networkTimeMean + serverMean + domProcessingMean + pageRenderingMean; final double networkPercent = 100d * networkTimeMean / totalTime; final double serverPercent = 100d * serverMean / totalTime; final double domProcessingPercent = 100d * domProcessingMean / totalTime; final double pageRenderingPercent = 100d * pageRenderingMean / totalTime; final PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(25);/* w ww . ja va 2s . co m*/ table.getDefaultCell().setBorderWidth(0); table.addCell(new Phrase(I18N.getString("Network"), cellFont)); table.addCell(new Phrase( integerFormat.format(networkTimeMean) + " ms (" + percentFormat.format(networkPercent) + "%)", cellFont)); table.addCell(new Phrase(I18N.getString("Server"), cellFont)); table.addCell(new Phrase( integerFormat.format(serverMean) + " ms (" + percentFormat.format(serverPercent) + "%)", cellFont)); table.addCell(new Phrase(I18N.getString("DOM_processing"), cellFont)); table.addCell(new Phrase(integerFormat.format(domProcessingMean) + " ms (" + percentFormat.format(domProcessingPercent) + "%)", cellFont)); table.addCell(new Phrase(I18N.getString("Page_rendering"), cellFont)); table.addCell(new Phrase(integerFormat.format(pageRenderingMean) + " ms (" + percentFormat.format(pageRenderingPercent) + "%)", cellFont)); addToDocument(table); addToDocument(new Phrase("\n", cellFont)); }
From source file:net.bull.javamelody.internal.web.pdf.PdfRequestAndGraphDetailReport.java
License:Apache License
private void writeGraph() throws IOException, DocumentException { final JRobin jrobin = collector.getJRobin(graphName); if (jrobin != null) { final byte[] img = jrobin.graph(range, 960, 400); final Image image = Image.getInstance(img); image.scalePercent(50);//from w w w. j a v a2 s . com final PdfPTable table = new PdfPTable(1); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell("\n"); table.addCell(image); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(new Phrase(getString("graph_units"), cellFont)); addToDocument(table); } else { // just in case request is null and collector.getJRobin(graphName) is null, we must write something in the document addToDocument(new Phrase("\n", cellFont)); } }
From source file:optika.sql.java
public void eksportoNePdf(String id) { Document document = new Document() { };//from ww w . j a v a 2 s . c om try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("receta.pdf")); document.open(); document.setPageSize(PageSize.A3); Image img = Image.getInstance("receta.jpg"); img.setAbsolutePosition(450f, 10f); img.scaleToFit(600, 849); img.setAlignment(Image.LEFT | Image.ALIGN_BOTTOM | Image.ALIGN_BASELINE); img.setAbsolutePosition(0, 0); document.add(img); String[][] receta = merrReceten("select * from recetat where id=" + parseInt(id) + ";"); String[][] tabela = merrReceten("select * from tabela where recetat_id=" + parseInt(id) + ";"); int[] white = new int[tabela.length]; for (int i = 0; i < tabela.length; i++) { white[i] = 0; int bosh = 0; for (int j = 3; j < tabela[i].length; j++) { if (tabela[i][j] == tabela[i][6]) { continue; } if (!tabela[i][j].isEmpty()) { bosh = 1; } } if (bosh == 0) { white[i] = 1; } } Paragraph data = new Paragraph("Data: " + receta[0][7]); data.setSpacingBefore(38); data.setSpacingAfter(40); PdfPTable table = new PdfPTable(7); if (white[0] == 0) { table.addCell(getCellPadding("" + tabela[0][3], 1)); } else { table.addCell(getCellWhite("_", 1, 30)); } table.addCell(getCellPadding("" + tabela[0][4], 1)); table.addCell(getCellPadding("" + tabela[0][5], 1)); table.addCell(getCellPadding("", 1)); table.addCell(getCellPadding("" + tabela[0][7], 1)); table.addCell(getCellPadding("" + tabela[0][8], 1)); table.addCell(getCellPadding("" + tabela[0][9], 1)); table.setWidthPercentage(105); table.setHorizontalAlignment(-100); if (white[1] == 0) { table.addCell(getCellPadding("" + tabela[1][3], 1)); } else { table.addCell(getCellWhite("_", 1, 36)); } table.addCell(getCellPadding("" + tabela[1][4], 1)); table.addCell(getCellPadding("" + tabela[1][5], 1)); table.addCell(getCellPadding("", 1)); table.addCell(getCellPadding("" + tabela[1][7], 1)); table.addCell(getCellPadding("" + tabela[1][8], 1)); table.addCell(getCellPadding("" + tabela[1][9], 1)); table.setWidthPercentage(105); table.setHorizontalAlignment(-100); if (white[2] == 0) { if (white[1] == 0) { table.addCell(getCell("" + tabela[2][3], 1, 30)); } else { table.addCell(getCellWhite("_", 1, 23)); } } else { table.addCell(getCellWhite("_", 1, 28)); } table.addCell(getCell("" + tabela[2][4], 1, 0)); table.addCell(getCell("" + tabela[2][5], 1, 0)); table.addCell(getCell("", 1, 0)); table.addCell(getCell("" + tabela[2][7], 1, 0)); table.addCell(getCell("" + tabela[2][8], 1, 0)); table.addCell(getCell("" + tabela[2][9], 1, 0)); table.setWidthPercentage(105); table.setSpacingBefore(27); table.setHorizontalAlignment(-100); String[][] distanca = merrReceten("select * from distanca where recetat_id=" + parseInt(id) + ";"); PdfPTable largAfer = new PdfPTable(3); if (distanca[0][3].isEmpty()) { PdfPCell larg = getCellWhite("_", 2, 15); largAfer.addCell(larg); } else { PdfPCell larg = new PdfPCell(new Phrase("" + distanca[0][3])); larg.setPadding(0); larg.setHorizontalAlignment(2); larg.setBorder(PdfPCell.NO_BORDER); larg.setPaddingBottom(20); largAfer.addCell(larg); } largAfer.addCell(getCell("", PdfPCell.ALIGN_RIGHT, 25)); if (distanca[0][8].isEmpty()) { largAfer.addCell(getCellWhite("_", PdfPCell.ALIGN_RIGHT, 15)); } else { largAfer.addCell(getCell("" + distanca[0][8], PdfPCell.ALIGN_RIGHT, 25)); } largAfer.setWidthPercentage(75); largAfer.setHorizontalAlignment(350); PdfPTable od_os = new PdfPTable(5); od_os.addCell(getCell("OD= " + distanca[0][4], 0, 195)); od_os.addCell(getCell("OS= " + distanca[0][5], 2, 195)); od_os.addCell(getCell("", 0, 0)); od_os.addCell(getCell("OD= " + distanca[0][9], 0, 0)); od_os.addCell(getCell("OS= " + distanca[0][10], 1, 0)); od_os.setWidthPercentage(90); od_os.setHorizontalAlignment(150); PdfPTable visusi = new PdfPTable(2); if (distanca[0][6].isEmpty()) { PdfPCell od_pa = getCellWhite("_", 2, 17); od_pa.setPaddingRight(45); visusi.addCell(od_pa); } else { PdfPCell od_pa = getCell(distanca[0][6], 2, 17); od_pa.setPaddingRight(45); visusi.addCell(od_pa); } if (distanca[0][11].isEmpty()) { visusi.addCell(getCellWhite("_", 2, 17)); } else { visusi.addCell(getCell(distanca[0][11], 2, 17)); } if (distanca[0][7].isEmpty()) { PdfPCell os_pa = getCellWhite("_", 2, 17); os_pa.setPaddingRight(45); visusi.addCell(os_pa); } else { PdfPCell os_pa = getCell(distanca[0][7], 2, 17); os_pa.setPaddingRight(45); visusi.addCell(os_pa); } if (distanca[0][12].isEmpty()) { visusi.addCell(getCellWhite("_", 2, 17)); } else { visusi.addCell(getCell(distanca[0][12], 2, 0)); } visusi.setWidthPercentage(100); visusi.setHorizontalAlignment(50); String[][] admin = merrReceten("select * from admin where id=1;"); PdfPTable klienti = new PdfPTable(3); klienti.addCell(getCell("", 0, 0)); klienti.addCell(getCell("", 0, 0)); klienti.addCell(getCell("Emri: " + receta[0][2], 0, 0)); klienti.addCell(getCell("Celular: " + admin[0][4], 0, 0)); klienti.addCell(getCell("", 0, 0)); PdfPCell celReceta = getCell("Celular: " + receta[0][4], 0, 0); celReceta.setPaddingTop(5); klienti.addCell(celReceta); klienti.addCell(getCell("Email: " + admin[0][5], 0, 0)); klienti.addCell(getCell("", 0, 0)); PdfPCell emailReceta = getCell("Email: " + receta[0][5], 0, 0); emailReceta.setPaddingBottom(5); emailReceta.setPaddingTop(5); klienti.addCell(emailReceta); klienti.addCell(getCell("Adresa: " + admin[0][6], 0, 0)); klienti.addCell(getCell("", 0, 0)); klienti.addCell(getCell("Adresa: " + receta[0][6], 0, 0)); klienti.setSpacingBefore(50); PdfPTable kreu = new PdfPTable(1); kreu.addCell(getCell(" ", 0, 0)); document.add(kreu); document.add(klienti); document.add(data); document.add(table); document.add(largAfer); document.add(od_os); document.add(visusi); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:org.getobjects.samples.HelloPDF.PDFAction.java
License:Open Source License
/** * Add some content to the PDF. This is using iText methods to add some text * and a few tables to the given Document. * Note how you can reuse higher-level objects once they got added to the * document (iText does not keep a higher level structure but directly * generates the PDF content).// www. j a v a 2 s . c o m * * @param _itext - the iText Document object * @throws DocumentException */ void addContent(Document _itext) throws DocumentException { /* a small paragraph */ _itext.add(new Paragraph("Hello World")); /* a simple table (default width is 80%) */ PdfPTable table = new PdfPTable(3); table.setSpacingBefore(10); table.setSpacingAfter(10); PdfPCell th = new PdfPCell(new Paragraph("Title")); th.setColspan(3); table.addCell(th); for (int i = 0; i < 8; i++) { for (int j = 0; j < 3; j++) table.addCell("" + i + "/" + j); } _itext.add(table); /* readd table with full width */ table.setWidthPercentage(100); _itext.add(table); /* readd with align */ table.setWidthPercentage(60); table.setHorizontalAlignment(Element.ALIGN_LEFT); _itext.add(table); /* and make a big table to enforce a pagebreak */ for (int i = 0; i < 32; i++) { for (int j = 0; j < 3; j++) table.addCell("" + i + "/" + j); } _itext.add(table); }