List of usage examples for com.itextpdf.text Image getInstance
public static Image getInstance(final Image image)
From source file:com.kohmiho.mpsr.export.PDFGenerator.java
private void addImage(Document document, String filename, String caption, Font font, int indentationLeft, int spacingBefore, int spacingAfter) throws BadElementException, MalformedURLException, IOException, DocumentException { if (null == filename) { addParagraph(document, null, null, String.format("[*** No Picture for %s ***]", caption), font, indentationLeft, 0, 0);//w w w .j a v a 2s . c o m return; } try { Paragraph paragraph = new Paragraph(); paragraph.setIndentationLeft(indentationLeft); paragraph.setSpacingBefore(spacingBefore); paragraph.setSpacingAfter(spacingAfter); if (null != font) paragraph.setFont(font); paragraph.setKeepTogether(true); paragraph.setAlignment(Element.ALIGN_CENTER); Image image = Image.getInstance(filename); image.scaleToFit(400, 400); paragraph.add(new Chunk(image, 0, 0, true)); paragraph.add(new Chunk("\n")); paragraph.add(caption); document.add(paragraph); } catch (Exception e) { addParagraph(document, null, null, String.format("[*** Unable to render picture for %s ***]", caption), font, indentationLeft, 0, 0); } }
From source file:com.kohmiho.mpsr.export.PDFGenerator.java
private void addImage(Document document, String filename) throws BadElementException, MalformedURLException, IOException, DocumentException { if (null == filename) { addParagraph(document, null, null, String.format("[*** No Picture for %s ***]", ""), null, 0, 0, 0); return;/* w w w .ja v a 2 s. c o m*/ } try { Image image = Image.getInstance(filename); image.scaleToFit(700, 500); image.setAlignment(Element.ALIGN_CENTER); // image.setRotationDegrees(90); document.add(image); } catch (Exception e) { addParagraph(document, null, null, String.format("[*** Unable to render picture for %s ***]", ""), null, 0, 0, 0); } }
From source file:com.kohmiho.mpsr.export.PDFGenerator.java
private void addCoverImage(Document document, String filename) throws BadElementException, MalformedURLException, IOException, DocumentException { if (null != filename) { try {/*from w w w . j av a 2 s . co m*/ Image image = Image.getInstance(filename); image.scaleToFit(300, 300); image.setAlignment(Element.ALIGN_CENTER); document.add(image); } catch (Exception e) { System.err.println("Can not load image " + filename); // e.printStackTrace(); } } }
From source file:com.kohmiho.mpsr.export.PDFGenerator.java
private Image getEmbeddedImage(ServletContext servletContext, String path) throws BadElementException, MalformedURLException, IOException { // return Image.getInstance(servletContext.getRealPath(path)); return Image.getInstance(IOUtils.toByteArray(servletContext.getResourceAsStream(path))); }
From source file:com.masscustsoft.service.ToPdf.java
License:Open Source License
private Image getImage(Map row) throws Exception { Image image = null;/*from w w w.j av a 2 s . com*/ String url = (String) row.get("url"); if (url != null) { image = Image.getInstance(url); } String externalId = (String) row.get("externalId"); if (externalId != null) { File tmp = File.createTempFile("tmp", ".image"); InputStream is = getFs().getResource(externalId); FileOutputStream os = new FileOutputStream(tmp); StreamUtil.copyStream(is, os, 0); is.close(); os.close(); image = Image.getInstance(tmp.toURL()); ThreadHelper.postponeDelete(tmp); } String img = (String) row.get("image"); if (img != null) { byte[] bytes = LightStr.getHexContent(img); image = Image.getInstance(bytes); } if (image != null) { MapUtil.setIfFloat(row, "spacingAfter", image); MapUtil.setIfFloat(row, "spacingBefore", image); MapUtil.setIfFloat(row, "scalePercent", image); MapUtil.setIfFloat(row, "scaleDegree", image); Float fitPer = MapUtil.getFloat(row, "fitPercent", null); if (fitPer != null) { Document doc = this.getDoc(); image.scaleToFit( (doc.getPageSize().getWidth() - doc.leftMargin() - doc.rightMargin()) * fitPer / 100f, (doc.getPageSize().getHeight() - doc.topMargin() - doc.bottomMargin()) * fitPer / 100f); } Float fitWidth = MapUtil.getFloat(row, "fitWidth", null); if (fitWidth != null) { Float fitHeight = MapUtil.getFloat(row, "fitHeight", fitWidth); image.scaleToFit(fitWidth, fitHeight); } image.setAlignment(getAlignment(row, "alignment")); } return image; }
From source file:com.masscustsoft.service.ToPdf.java
License:Open Source License
@Override public Image createImage(String src, final Map<String, String> attrs, final ChainedProperties chain, final DocListener document, final ImageProvider img_provider, final HashMap<String, Image> img_store, final String img_baseurl) throws DocumentException, IOException { Image img = null;//from ww w .jav a2 s . c om // getting the image using an image provider if (img_provider != null) img = img_provider.getImage(src, attrs, chain, document); // getting the image from an image store if (img == null && img_store != null) { Image tim = img_store.get(src); if (tim != null) img = Image.getInstance(tim); } if (img != null) return img; ////if src start with data: it's dataUri and parse it imme. if (src.startsWith("remote?")) { BeanFactory bf = BeanFactory.getBeanFactory(); String pp = src.substring(7); String[] ss = pp.split("\\&"); try { String id = "~", fsId = LightUtil.getRepository().getFsId(); for (String s : ss) { String[] sss = s.split("="); if (sss[0].equals("id")) id = sss[1]; if (sss[0].equals("fsId")) fsId = sss[1]; } IRepository fs = bf.getRepository(fsId); InputStream is = fs.getResource(id); ByteArrayOutputStream os = new ByteArrayOutputStream(); StreamUtil.copyStream(is, os, 0); is.close(); os.close(); img = Image.getInstance(os.toByteArray()); } catch (Exception e) { e.printStackTrace(); } } else if (src.startsWith("data:")) { int i = src.indexOf(","); byte[] bits = Base64.decode(src.substring(i + 1)); img = Image.getInstance(bits); } else { //// // introducing a base url // relative src references only if (!src.startsWith("http") && img_baseurl != null) { src = img_baseurl + src; } else if (img == null && !src.startsWith("http")) { String path = chain.getProperty(HtmlTags.IMAGEPATH); if (path == null) path = ""; src = new File(path, src).getPath(); } img = Image.getInstance(src); } if (img == null) return null; float actualFontSize = HtmlUtilities.parseLength(chain.getProperty(HtmlTags.SIZE), HtmlUtilities.DEFAULT_FONT_SIZE); if (actualFontSize <= 0f) actualFontSize = HtmlUtilities.DEFAULT_FONT_SIZE; String width = attrs.get(HtmlTags.WIDTH); float widthInPoints = HtmlUtilities.parseLength(width, actualFontSize); String height = attrs.get(HtmlTags.HEIGHT); float heightInPoints = HtmlUtilities.parseLength(height, actualFontSize); if (widthInPoints == 0 && heightInPoints == 0) { Document doc = (Document) document; widthInPoints = doc.getPageSize().getWidth(); } if (widthInPoints > 0 && heightInPoints > 0) { img.scaleAbsolute(widthInPoints, heightInPoints); } else if (widthInPoints > 0) { heightInPoints = img.getHeight() * widthInPoints / img.getWidth(); img.scaleAbsolute(widthInPoints, heightInPoints); } else if (heightInPoints > 0) { widthInPoints = img.getWidth() * heightInPoints / img.getHeight(); img.scaleAbsolute(widthInPoints, heightInPoints); } String before = chain.getProperty(HtmlTags.BEFORE); if (before != null) img.setSpacingBefore(Float.parseFloat(before)); String after = chain.getProperty(HtmlTags.AFTER); if (after != null) img.setSpacingAfter(Float.parseFloat(after)); img.setWidthPercentage(0); return img; }
From source file:com.maxl.java.amikodesk.SaveBasket.java
License:Open Source License
public void generatePdf(Author author, String filename, String type) { // A4: 8.267in x 11.692in => 595.224units x 841.824units (72units/inch) // marginLeft, marginRight, marginTop, marginBottom Document document = new Document(PageSize.A4, 50, 50, 80, 50); try {/*from w w w . ja va 2 s. co m*/ if (m_shopping_basket.size() > 0) { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); writer.setBoxSize("art", new Rectangle(50, 50, 560, 790)); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); document.open(); PdfContentByte cb = writer.getDirectContent(); document.addAuthor("ywesee GmbH"); document.addCreator("AmiKo for Windows"); document.addCreationDate(); // Logo String logoImageStr = m_prefs.get(LogoImageID, Constants.IMG_FOLDER + "empty_logo.png"); File logoFile = new File(logoImageStr); if (!logoFile.exists()) logoImageStr = Constants.IMG_FOLDER + "empty_logo.png"; Image logo = Image.getInstance(logoImageStr); logo.scalePercent(30); logo.setAlignment(Rectangle.ALIGN_RIGHT); document.add(logo); document.add(Chunk.NEWLINE); // Bestelladresse // --> String bestellAdrStr = m_prefs.get(BestellAdresseID, m_rb.getString("noaddress1")); String bestellAdrStr = getAddressAsString(BestellAdresseID); Paragraph p = new Paragraph(12); // p.setIndentationLeft(60); p.add(new Chunk(bestellAdrStr, font_norm_10)); document.add(p); document.add(Chunk.NEWLINE); // Title p = new Paragraph(m_rb.getString("order"), font_bold_16); document.add(p); // Date DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); Date date = new Date(); p = new Paragraph(m_rb.getString("date") + ": " + dateFormat.format(date), font_bold_10); p.setSpacingAfter(20); document.add(p); // document.add(Chunk.NEWLINE); // Add addresses (Lieferadresse + Rechnungsadresse) /* --> OLD String lieferAdrStr = m_prefs.get(LieferAdresseID, m_rb.getString("noaddress2")); String rechnungsAdrStr = m_prefs.get(RechnungsAdresseID, m_rb.getString("noaddress3")); */ // --> NEW String lieferAdrStr = getAddressAsString(LieferAdresseID); String rechnungsAdrStr = getAddressAsString(RechnungsAdresseID); PdfPTable addressTable = new PdfPTable(new float[] { 1, 1 }); addressTable.setWidthPercentage(100f); addressTable.getDefaultCell().setPadding(5); addressTable.setSpacingAfter(5f); addressTable.addCell(getStringCell(m_rb.getString("shipaddress"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell(getStringCell(m_rb.getString("billaddress"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell( getStringCell(lieferAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell( getStringCell(rechnungsAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); document.add(addressTable); document.add(Chunk.NEWLINE); // Add shopping basket if (type.equals("specific")) document.add(getShoppingBasketForAuthor(author, cb)); else if (type.equals("all")) document.add(getFullShoppingBasket(cb, "all")); else if (type.equals("rest")) document.add(getFullShoppingBasket(cb, "rest")); LineSeparator separator = new LineSeparator(); document.add(separator); } } catch (IOException e) { } catch (DocumentException e) { } document.close(); // System.out.println("Saved PDF to " + filename); }
From source file:com.mim.controllers.HomeCtrl.java
private void ordenReport(Document document, Lugar lugar) throws BadElementException, DocumentException, IOException { document.addTitle(current.getNumeroOrden()); // step 3//from ww w.j av a 2 s . c o m // step 4 PdfPTable table = new PdfPTable(8); //LEFT HEADER CONTENT PdfPTable leftHeaderTable = new PdfPTable(4); PdfPCell imgCell = new PdfPCell(); imgCell.setBorder(Rectangle.NO_BORDER); imgCell.setPaddingTop(14); imgCell.setColspan(1); imgCell.setFixedHeight(25); //Image img = Image.getInstance("/opt/shared/home/logo.png"); Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png"); imgCell.addElement(img); PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO")); reportTitleCell.setPaddingTop(14); reportTitleCell.setPaddingLeft(20); reportTitleCell.setColspan(3); reportTitleCell.setBorder(Rectangle.NO_BORDER); leftHeaderTable.addCell(imgCell); leftHeaderTable.addCell(reportTitleCell); PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable); leftHeaderMainCell.setColspan(4); //END CONTENT //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE PdfPTable infHeader = new PdfPTable(3); PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN")); numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER); numberOrderLabel.setColspan(1); String numeroOrden = null; if (current.getNumeroOrden() != null) { numeroOrden = current.getNumeroOrden(); } else { numeroOrden = current.getActividad(); } PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden)); numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER); numberOrderValue.setColspan(2); PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD")); prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER); prioridadLabel.setColspan(1); PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad())); prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER); prioridadValue.setColspan(2); PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA")); fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER); fechaLabel.setColspan(1); //dd-MM-yyyy SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy"); Date startDate = current.getStartDate(); if (startDate == null) { startDate = new Date(); } String fecha = format1.format(startDate); PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha)); fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER); fechaValue.setColspan(2); infHeader.addCell(numberOrderLabel); infHeader.addCell(numberOrderValue); infHeader.addCell(prioridadLabel); infHeader.addCell(prioridadValue); infHeader.addCell(fechaLabel); infHeader.addCell(fechaValue); PdfPCell cellHeaderRight = new PdfPCell(infHeader); cellHeaderRight.setColspan(4); //END HEADER PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA")); areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER); areaLabel.setVerticalAlignment(Element.ALIGN_CENTER); areaLabel.setFixedHeight(30); areaLabel.setPaddingTop(5); areaLabel.setColspan(2); PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD")); actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER); actividadLabel.setFixedHeight(30); actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER); actividadLabel.setPaddingTop(5); actividadLabel.setColspan(3); PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION")); responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER); responsableLabel.setFixedHeight(30); responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER); responsableLabel.setPaddingTop(5); responsableLabel.setColspan(3); String area; if (lugar.getNombre().contains("linea")) { area = "envasado"; } else if (lugar.getNombre().contains("otro")) { area = "Tecate 500"; } else if (lugar.getNombre().contains("PD")) { area = "concretos"; } else if (lugar.getNombre().contains("planta agua")) { area = "cerveceria"; } else { area = "elaboracion"; } PdfPCell areaValor = new PdfPCell(new Paragraph(area)); areaValor.setFixedHeight(25); areaValor.setHorizontalAlignment(Element.ALIGN_CENTER); areaValor.setColspan(2); PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad())); actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER); actividadValor.setFixedHeight(25); actividadValor.setColspan(3); PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado())); responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER); responsableValor.setFixedHeight(25); responsableValor.setColspan(3); // 2 FILAS PARA INF. EQUIPO Y LUGAR PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO")); equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER); equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER); equipoLabel.setFixedHeight(30); equipoLabel.setPaddingTop(5); equipoLabel.setColspan(4); PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR")); lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER); lugarLabel.setFixedHeight(30); lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER); lugarLabel.setPaddingTop(5); lugarLabel.setColspan(4); String numeroEquipo = null; if (equipo.getNumeroEquipo() != null) { numeroEquipo = equipo.getNumeroEquipo(); } else { numeroEquipo = "n/a"; } PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo)); equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER); equipoValor.setFixedHeight(25); equipoValor.setColspan(4); PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre())); lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER); lugarValor.setFixedHeight(25); lugarValor.setColspan(4); //END INFO EQUIPO // 4 ROW and 5 ROW PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION")); descripcionLabel.setPadding(12); descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER); descripcionLabel.setColspan(8); PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion())); descripcionValor.setPadding(10); descripcionValor.setColspan(8); //END ROWS //ROW BEFORE HISTORIAL_DETALLES PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES")); historialLabel.setPadding(12); historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER); historialLabel.setColspan(8); //END HISTORIAL table.addCell(leftHeaderMainCell); table.addCell(cellHeaderRight); table.addCell(areaLabel); table.addCell(actividadLabel); table.addCell(responsableLabel); table.addCell(areaValor); table.addCell(actividadValor); table.addCell(responsableValor); table.addCell(equipoLabel); table.addCell(lugarLabel); table.addCell(equipoValor); table.addCell(lugarValor); table.addCell(descripcionLabel); table.addCell(descripcionValor); List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden()); if (observaciones != null) { if (observaciones.size() > 0) { table.addCell(historialLabel); //LOOP HISTORIAL_DETALLES for (int i = 0; i < observaciones.size(); i++) { HistorialDetalles historial = observaciones.get(i); PdfPCell paramCell = new PdfPCell(); paramCell.setColspan(3); paramCell.addElement(new Paragraph(historial.getParametro())); paramCell.setVerticalAlignment(Element.ALIGN_CENTER); paramCell.setPaddingLeft(10); paramCell.setPaddingBottom(10); PdfPCell valueParamCell = new PdfPCell(); valueParamCell.setColspan(5); valueParamCell.setPaddingLeft(10); valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER); valueParamCell.addElement(new Paragraph(historial.getValor())); valueParamCell.setPaddingBottom(10); if (historial.getValor() != null) { if (historial.getValor().length() > 0) { table.addCell(paramCell); table.addCell(valueParamCell); } } } } } //END LOOP HISTORIAL // FIRST ROWS OF FOTOGRAPHIC REPORT PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO")); pasoLabel.setFixedHeight(20); pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER); pasoLabel.setColspan(1); PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION")); accionLabel.setFixedHeight(20); accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER); accionLabel.setColspan(3); PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES")); imagenLabel.setFixedHeight(20); imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER); imagenLabel.setColspan(4); //END ROWS PdfPTable table2 = new PdfPTable(8); //ROW BEFORE HISTORIAL_DETALLES PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO")); headerPictures.setPadding(12); headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER); headerPictures.setColspan(8); table2.addCell(headerPictures); //END HISTORIAL table2.addCell(pasoLabel); table2.addCell(accionLabel); table2.addCell(imagenLabel); //fotos loop List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden()); for (int i = 0; i < fotos.size(); i++) { Fotos foto = fotos.get(i); PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i))); pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER); pasoVal.setColspan(1); PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo())); detail.setPadding(5); detail.setBorder(Rectangle.NO_BORDER); PdfPCell accionVal = new PdfPCell(); accionVal.addElement(new Paragraph(foto.getDescripcion())); accionVal.setHorizontalAlignment(Element.ALIGN_CENTER); accionVal.setBorder(Rectangle.NO_BORDER); //accionVal.setColspan(3); PdfPTable infoTable = new PdfPTable(1); infoTable.addCell(detail); infoTable.addCell(accionVal); PdfPCell infiCell = new PdfPCell(); infiCell.setColspan(3); infiCell.addElement(infoTable); //Table collumn //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name) //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos()); String archivo = foto.getArchivo(); String[] split = archivo.split("/"); int size = split.length; final String name = split[size - 1]; System.out.println("Valor " + name); Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name); PdfPTable imagenTable = new PdfPTable(1); PdfPCell fotoCell = new PdfPCell(); fotoCell.setColspan(1); fotoCell.addElement(imgFoto); fotoCell.setFixedHeight(310); fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER); fotoCell.setBorder(Rectangle.NO_BORDER); imagenTable.addCell(fotoCell); PdfPCell imagenVal = new PdfPCell(); imagenVal.setColspan(4); imagenVal.addElement(imagenTable); table2.addCell(pasoVal); table2.addCell(infiCell); table2.addCell(imagenVal); } //end loop //table.addCell(tiempoLabel); document.add(table); document.newPage(); document.add(table2); }
From source file:com.mim.controllers.OrdenCtrl.java
private void ordenReport(Document document, Lugar lugar) throws BadElementException, DocumentException, IOException { document.addTitle(current.getNumeroOrden()); // step 3/*from ww w . j a v a2s. co m*/ // step 4 PdfPTable table = new PdfPTable(8); //LEFT HEADER CONTENT PdfPTable leftHeaderTable = new PdfPTable(4); PdfPCell imgCell = new PdfPCell(); imgCell.setBorder(Rectangle.NO_BORDER); imgCell.setPaddingTop(14); imgCell.setColspan(1); imgCell.setFixedHeight(25); //Image img = Image.getInstance("/opt/shared/home/logo.png"); Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png"); imgCell.addElement(img); PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO")); reportTitleCell.setPaddingTop(14); reportTitleCell.setPaddingLeft(20); reportTitleCell.setColspan(3); reportTitleCell.setBorder(Rectangle.NO_BORDER); leftHeaderTable.addCell(imgCell); leftHeaderTable.addCell(reportTitleCell); PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable); leftHeaderMainCell.setColspan(4); //END CONTENT //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE PdfPTable infHeader = new PdfPTable(3); PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN")); numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER); numberOrderLabel.setColspan(1); String numeroOrden = null; if (current.getNumeroOrden() != null) { numeroOrden = current.getNumeroOrden(); } else { numeroOrden = current.getActividad(); } PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden)); numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER); numberOrderValue.setColspan(2); PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD")); prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER); prioridadLabel.setColspan(1); PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad())); prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER); prioridadValue.setColspan(2); PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA")); fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER); fechaLabel.setColspan(1); //dd-MM-yyyy SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy"); Date startDate = current.getStartDate(); if (startDate == null) { startDate = new Date(); } String fecha = format1.format(startDate); PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha)); fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER); fechaValue.setColspan(2); infHeader.addCell(numberOrderLabel); infHeader.addCell(numberOrderValue); infHeader.addCell(prioridadLabel); infHeader.addCell(prioridadValue); infHeader.addCell(fechaLabel); infHeader.addCell(fechaValue); PdfPCell cellHeaderRight = new PdfPCell(infHeader); cellHeaderRight.setColspan(4); //END HEADER PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA")); areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER); areaLabel.setVerticalAlignment(Element.ALIGN_CENTER); areaLabel.setFixedHeight(30); areaLabel.setPaddingTop(5); areaLabel.setColspan(2); PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD")); actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER); actividadLabel.setFixedHeight(30); actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER); actividadLabel.setPaddingTop(5); actividadLabel.setColspan(3); PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION")); responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER); responsableLabel.setFixedHeight(30); responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER); responsableLabel.setPaddingTop(5); responsableLabel.setColspan(3); PdfPCell areaValor = new PdfPCell(new Paragraph("concretera")); areaValor.setFixedHeight(25); areaValor.setHorizontalAlignment(Element.ALIGN_CENTER); areaValor.setColspan(2); PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad())); actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER); actividadValor.setFixedHeight(25); actividadValor.setColspan(3); PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado())); responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER); responsableValor.setFixedHeight(25); responsableValor.setColspan(3); // 2 FILAS PARA INF. EQUIPO Y LUGAR PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO")); equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER); equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER); equipoLabel.setFixedHeight(30); equipoLabel.setPaddingTop(5); equipoLabel.setColspan(4); PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR")); lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER); lugarLabel.setFixedHeight(30); lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER); lugarLabel.setPaddingTop(5); lugarLabel.setColspan(4); String numeroEquipo = null; if (equipo.getNumeroEquipo() != null) { numeroEquipo = equipo.getNumeroEquipo(); } else { numeroEquipo = "n/a"; } PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo)); equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER); equipoValor.setFixedHeight(25); equipoValor.setColspan(4); PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre())); lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER); lugarValor.setFixedHeight(25); lugarValor.setColspan(4); //END INFO EQUIPO // 4 ROW and 5 ROW PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION")); descripcionLabel.setPadding(12); descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER); descripcionLabel.setColspan(8); PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion())); descripcionValor.setPadding(10); descripcionValor.setColspan(8); //END ROWS //ROW BEFORE HISTORIAL_DETALLES PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES")); historialLabel.setPadding(12); historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER); historialLabel.setColspan(8); //END HISTORIAL table.addCell(leftHeaderMainCell); table.addCell(cellHeaderRight); table.addCell(areaLabel); table.addCell(actividadLabel); table.addCell(responsableLabel); table.addCell(areaValor); table.addCell(actividadValor); table.addCell(responsableValor); table.addCell(equipoLabel); table.addCell(lugarLabel); table.addCell(equipoValor); table.addCell(lugarValor); table.addCell(descripcionLabel); table.addCell(descripcionValor); List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden()); if (observaciones != null) { if (observaciones.size() > 0) { table.addCell(historialLabel); //LOOP HISTORIAL_DETALLES for (int i = 0; i < observaciones.size(); i++) { HistorialDetalles historial = observaciones.get(i); PdfPCell paramCell = new PdfPCell(); paramCell.setColspan(3); paramCell.addElement(new Paragraph(historial.getParametro())); paramCell.setVerticalAlignment(Element.ALIGN_CENTER); paramCell.setPaddingLeft(10); paramCell.setPaddingBottom(10); PdfPCell valueParamCell = new PdfPCell(); valueParamCell.setColspan(5); valueParamCell.setPaddingLeft(10); valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER); valueParamCell.addElement(new Paragraph(historial.getValor())); valueParamCell.setPaddingBottom(10); table.addCell(paramCell); table.addCell(valueParamCell); } } } //END LOOP HISTORIAL // FIRST ROWS OF FOTOGRAPHIC REPORT PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO")); pasoLabel.setFixedHeight(20); pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER); pasoLabel.setColspan(1); PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION")); accionLabel.setFixedHeight(20); accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER); accionLabel.setColspan(3); PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES")); imagenLabel.setFixedHeight(20); imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER); imagenLabel.setColspan(4); //END ROWS PdfPTable table2 = new PdfPTable(8); //ROW BEFORE HISTORIAL_DETALLES PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO")); headerPictures.setPadding(12); headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER); headerPictures.setColspan(8); table2.addCell(headerPictures); //END HISTORIAL table2.addCell(pasoLabel); table2.addCell(accionLabel); table2.addCell(imagenLabel); //fotos loop List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden()); for (int i = 0; i < fotos.size(); i++) { Fotos foto = fotos.get(i); PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i))); pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER); pasoVal.setColspan(1); PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo())); detail.setPadding(5); detail.setBorder(Rectangle.NO_BORDER); PdfPCell accionVal = new PdfPCell(); accionVal.addElement(new Paragraph(foto.getDescripcion())); accionVal.setHorizontalAlignment(Element.ALIGN_CENTER); accionVal.setBorder(Rectangle.NO_BORDER); //accionVal.setColspan(3); PdfPTable infoTable = new PdfPTable(1); infoTable.addCell(detail); infoTable.addCell(accionVal); PdfPCell infiCell = new PdfPCell(); infiCell.setColspan(3); infiCell.addElement(infoTable); //Table collumn //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name) //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos()); String archivo = foto.getArchivo(); String[] split = archivo.split("/"); int size = split.length; final String name = split[size - 1]; System.out.println("Valor " + name); Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name); PdfPTable imagenTable = new PdfPTable(1); PdfPCell fotoCell = new PdfPCell(); fotoCell.setColspan(1); fotoCell.addElement(imgFoto); fotoCell.setFixedHeight(310); fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER); fotoCell.setBorder(Rectangle.NO_BORDER); imagenTable.addCell(fotoCell); PdfPCell imagenVal = new PdfPCell(); imagenVal.setColspan(4); imagenVal.addElement(imagenTable); table2.addCell(pasoVal); table2.addCell(infiCell); table2.addCell(imagenVal); } //end loop //table.addCell(tiempoLabel); document.add(table); document.newPage(); document.add(table2); }
From source file:com.mim.servlet.ReportGen.java
private void ordenReport(Document document, Lugar lugar) throws BadElementException, DocumentException, IOException { document.addTitle(current.getNumeroOrden()); // step 3/* w ww.j a v a2 s. c om*/ // step 4 PdfPTable table = new PdfPTable(8); //LEFT HEADER CONTENT PdfPTable leftHeaderTable = new PdfPTable(4); PdfPCell imgCell = new PdfPCell(); imgCell.setBorder(Rectangle.NO_BORDER); imgCell.setPaddingTop(14); imgCell.setColspan(1); imgCell.setFixedHeight(25); //Image img = Image.getInstance("/opt/shared/home/logo.png"); Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png"); imgCell.addElement(img); PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO")); reportTitleCell.setPaddingTop(14); reportTitleCell.setPaddingLeft(20); reportTitleCell.setColspan(3); reportTitleCell.setBorder(Rectangle.NO_BORDER); leftHeaderTable.addCell(imgCell); leftHeaderTable.addCell(reportTitleCell); PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable); leftHeaderMainCell.setColspan(4); //END CONTENT //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE PdfPTable infHeader = new PdfPTable(3); PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN")); numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER); numberOrderLabel.setColspan(1); String numeroOrden = null; if (current.getNumeroOrden() != null) { numeroOrden = current.getNumeroOrden(); } else { numeroOrden = current.getActividad(); } PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden)); numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER); numberOrderValue.setColspan(2); PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD")); prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER); prioridadLabel.setColspan(1); PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad())); prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER); prioridadValue.setColspan(2); PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA")); fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER); fechaLabel.setColspan(1); //dd-MM-yyyy SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy"); Date startDate = current.getStartDate(); if (startDate == null) { startDate = new Date(); } String fecha = format1.format(startDate); PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha)); fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER); fechaValue.setColspan(2); infHeader.addCell(numberOrderLabel); infHeader.addCell(numberOrderValue); infHeader.addCell(prioridadLabel); infHeader.addCell(prioridadValue); infHeader.addCell(fechaLabel); infHeader.addCell(fechaValue); PdfPCell cellHeaderRight = new PdfPCell(infHeader); cellHeaderRight.setColspan(4); //END HEADER PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA")); areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER); areaLabel.setVerticalAlignment(Element.ALIGN_CENTER); areaLabel.setFixedHeight(30); areaLabel.setPaddingTop(5); areaLabel.setColspan(2); PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD")); actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER); actividadLabel.setFixedHeight(30); actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER); actividadLabel.setPaddingTop(5); actividadLabel.setColspan(3); PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION")); responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER); responsableLabel.setFixedHeight(30); responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER); responsableLabel.setPaddingTop(5); responsableLabel.setColspan(3); PdfPCell areaValor = new PdfPCell(new Paragraph("concretera")); areaValor.setFixedHeight(25); areaValor.setHorizontalAlignment(Element.ALIGN_CENTER); areaValor.setColspan(2); PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad())); actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER); actividadValor.setFixedHeight(25); actividadValor.setColspan(3); PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado())); responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER); responsableValor.setFixedHeight(25); responsableValor.setColspan(3); // 2 FILAS PARA INF. EQUIPO Y LUGAR PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO")); equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER); equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER); equipoLabel.setFixedHeight(30); equipoLabel.setPaddingTop(5); equipoLabel.setColspan(4); PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR")); lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER); lugarLabel.setFixedHeight(30); lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER); lugarLabel.setPaddingTop(5); lugarLabel.setColspan(4); String numeroEquipo = null; if (equipo.getNumeroEquipo() != null) { numeroEquipo = equipo.getNumeroEquipo(); } else { numeroEquipo = "n/a"; } PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo)); equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER); equipoValor.setFixedHeight(25); equipoValor.setColspan(4); PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre())); lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER); lugarValor.setFixedHeight(25); lugarValor.setColspan(4); //END INFO EQUIPO // 4 ROW and 5 ROW PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION")); descripcionLabel.setPadding(12); descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER); descripcionLabel.setColspan(8); PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion())); descripcionValor.setPadding(10); descripcionValor.setColspan(8); //END ROWS //ROW BEFORE HISTORIAL_DETALLES PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES")); historialLabel.setPadding(12); historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER); historialLabel.setColspan(8); //END HISTORIAL table.addCell(leftHeaderMainCell); table.addCell(cellHeaderRight); table.addCell(areaLabel); table.addCell(actividadLabel); table.addCell(responsableLabel); table.addCell(areaValor); table.addCell(actividadValor); table.addCell(responsableValor); table.addCell(equipoLabel); table.addCell(lugarLabel); table.addCell(equipoValor); table.addCell(lugarValor); table.addCell(descripcionLabel); table.addCell(descripcionValor); List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden()); if (observaciones != null) { if (observaciones.size() > 0) { table.addCell(historialLabel); //LOOP HISTORIAL_DETALLES for (int i = 0; i < observaciones.size(); i++) { HistorialDetalles historial = observaciones.get(i); if (historial.getValor() != null) { if (historial.getValor().length() > 0) { PdfPCell paramCell = new PdfPCell(); paramCell.setColspan(3); paramCell.addElement(new Paragraph(historial.getParametro())); paramCell.setVerticalAlignment(Element.ALIGN_CENTER); paramCell.setPaddingLeft(10); paramCell.setPaddingBottom(10); PdfPCell valueParamCell = new PdfPCell(); valueParamCell.setColspan(5); valueParamCell.setPaddingLeft(10); valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER); valueParamCell.addElement(new Paragraph(historial.getValor())); valueParamCell.setPaddingBottom(10); table.addCell(paramCell); table.addCell(valueParamCell); } } } } } //END LOOP HISTORIAL // FIRST ROWS OF FOTOGRAPHIC REPORT PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO")); pasoLabel.setFixedHeight(20); pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER); pasoLabel.setColspan(1); PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION")); accionLabel.setFixedHeight(20); accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER); accionLabel.setColspan(3); PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES")); imagenLabel.setFixedHeight(20); imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER); imagenLabel.setColspan(4); //END ROWS PdfPTable table2 = new PdfPTable(8); //ROW BEFORE HISTORIAL_DETALLES PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO")); headerPictures.setPadding(12); headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER); headerPictures.setColspan(8); table2.addCell(headerPictures); //END HISTORIAL table2.addCell(pasoLabel); table2.addCell(accionLabel); table2.addCell(imagenLabel); //fotos loop List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden()); for (int i = 0; i < fotos.size(); i++) { Fotos foto = fotos.get(i); PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i))); pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER); pasoVal.setColspan(1); PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo())); detail.setPadding(5); detail.setBorder(Rectangle.NO_BORDER); PdfPCell accionVal = new PdfPCell(); accionVal.addElement(new Paragraph(foto.getDescripcion())); accionVal.setHorizontalAlignment(Element.ALIGN_CENTER); accionVal.setBorder(Rectangle.NO_BORDER); //accionVal.setColspan(3); PdfPTable infoTable = new PdfPTable(1); infoTable.addCell(detail); infoTable.addCell(accionVal); PdfPCell infiCell = new PdfPCell(); infiCell.setColspan(3); infiCell.addElement(infoTable); //Table collumn //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name) //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos()); String archivo = foto.getArchivo(); String[] split = archivo.split("/"); int size = split.length; final String name = split[size - 1]; System.out.println("Valor " + name); Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name); PdfPTable imagenTable = new PdfPTable(1); PdfPCell fotoCell = new PdfPCell(); fotoCell.setColspan(1); fotoCell.addElement(imgFoto); fotoCell.setFixedHeight(310); fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER); fotoCell.setBorder(Rectangle.NO_BORDER); imagenTable.addCell(fotoCell); PdfPCell imagenVal = new PdfPCell(); imagenVal.setColspan(4); imagenVal.addElement(imagenTable); table2.addCell(pasoVal); table2.addCell(infiCell); table2.addCell(imagenVal); } //end loop //table.addCell(tiempoLabel); document.add(table); document.newPage(); document.add(table2); }