List of usage examples for com.lowagie.text Image getInstance
public static Image getInstance(Image image)
From source file:com.aryjr.nheengatu.pdf.PDFImage.java
License:Open Source License
public static Image createImage(final Tag htmlImage) throws BadElementException, IOException { final TagsManager gm = TagsManager.getInstance(); // TODO the image path can't be static Image img;/* w w w .j a v a 2 s. c o m*/ if (htmlImage.getPropertyValue("src").indexOf("http://") >= 0) { img = Image.getInstance(new URL(htmlImage.getPropertyValue("src"))); } else { img = Image.getInstance(htmlImage.getPropertyValue("src")); } img.setWidthPercentage(0);// TODO without it, the image dimensions // will be the same of the cell img.setAlignment(gm.getAlign()); if (htmlImage.getPropertyValue("width") != null) { img.scaleAbsoluteWidth(Integer.parseInt(htmlImage.getPropertyValue("width"))); } if (htmlImage.getPropertyValue("height") != null) { img.scaleAbsoluteHeight(Integer.parseInt(htmlImage.getPropertyValue("height"))); } return img; }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
License:Apache License
private void printGraphPdf(DocWriter writer, CanvasCommon canvas, Graph process, Rectangle page_size, String type, String filename, Chapter chapter, int chapter_number) throws Exception { Dimension graphsize = process.getGraphSize(); // we create a fontMapper and read all the fonts in the font directory DefaultFontMapper mapper = new DefaultFontMapper(); FontFactory.registerDirectories();/*from w w w . ja v a2s .c o m*/ mapper.insertDirectory("c:\\winnt\\fonts"); // mapper.insertDirectory("c:\\windows\\fonts"); // we create a template and a Graphics2D object that corresponds with it int w, h; float scale; if ((float) graphsize.width < page_size.getWidth() * 0.8 && (float) graphsize.height < page_size.getHeight() * 0.8 || type.equals(HTML)) { w = graphsize.width + 36; h = graphsize.height + 36; scale = -1f; } else { scale = page_size.getWidth() * 0.8f / (float) graphsize.width; if (scale > page_size.getHeight() * 0.8f / (float) graphsize.height) scale = page_size.getHeight() * 0.8f / (float) graphsize.height; w = (int) (graphsize.width * scale) + 36; h = (int) (graphsize.height * scale) + 36; } Image img; int zoomSave = process.zoom; process.zoom = 100; Color bgsave = canvas.getBackground(); boolean edsave = canvas.editable; canvas.editable = false; canvas.setBackground(Color.white); if (type.equals(PDF)) { PdfContentByte cb = ((PdfWriter) writer).getDirectContent(); PdfTemplate tp = cb.createTemplate(w, h); Graphics2D g2 = tp.createGraphics(w, h, mapper); if (scale > 0) g2.scale(scale, scale); tp.setWidth(w); tp.setHeight(h); canvas.paintComponent(g2); g2.dispose(); // cb.addTemplate(tp, 50, 400); img = new ImgTemplate(tp); } else { String imgfilename = filename + "." + process.getName() + "_ch" + chapter_number + ".jpg"; printImage(imgfilename, -1f, canvas, graphsize); img = Image.getInstance(imgfilename); if (scale > 0) img.scalePercent(scale * 100); } process.zoom = zoomSave; canvas.setBackground(bgsave); canvas.editable = edsave; if (img != null) chapter.add(img); }
From source file:com.compomics.pepshell.controllers.dataexport.PDFExport.java
License:Apache License
@Override public void exportImage(BufferedImage imageToExport, String filename) { File exportFile = new File(ProgramVariables.EXPORTFOLDER, filename + ".pdf"); if (append && exportFile.exists()) { } else {/*w ww . ja v a 2 s . c o m*/ File exportImageFile = new File(System.getProperty("file.temp"), filename); try { ImageIO.write(imageToExport, "png", new FileOutputStream(exportImageFile)); Image pdfImage = Image.getInstance(exportImageFile.getAbsolutePath()); Document document = new Document(new Rectangle(pdfImage.absoluteX(), pdfImage.absoluteY())); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(exportFile)); document.open(); document.newPage(); document.add(pdfImage); document.close(); } catch (DocumentException | IOException ex) { FaultBarrier.getInstance().handleException(ex); } } }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
private static boolean parseLine(WikiPDFContext context, String line, Paragraph main, Connection db, ArrayList<Integer> wikiListTodo, float cellWidth, PdfPCell cell) throws Exception { LOG.debug("PARSING LINE: " + line); // Context Objects Project project = context.getProject(); WikiExportBean exportBean = context.getExportBean(); HashMap<String, ImageInfo> imageList = context.getImageList(); String fileLibrary = context.getFileLibrary(); boolean needsCRLF = true; boolean bold = false; boolean italic = false; boolean bolditalic = false; StringBuffer subject = new StringBuffer(); StringBuffer data = new StringBuffer(); int linkL = 0; int linkR = 0; int attr = 0; int underlineAttr = 0; // parse characters for (int i = 0; i < line.length(); i++) { char c1 = line.charAt(i); String c = String.valueOf(c1); // False attr/links if (!"'".equals(c) && attr == 1) { data.append("'").append(c); attr = 0;/*from ww w. j a va2s . c o m*/ continue; } if (!"_".equals(c) && underlineAttr == 1) { data.append("_").append(c); underlineAttr = 0; continue; } if (!"[".equals(c) && linkL == 1) { data.append("[").append(c); linkL = 0; continue; } if (!"]".equals(c) && linkR == 1) { data.append("]").append(c); linkR = 0; continue; } // Links if ("[".equals(c)) { ++linkL; continue; } if ("]".equals(c)) { ++linkR; if (linkL == 2 && linkR == 2) { LOG.debug("main.add(new Chunk(data.toString()))"); main.add(new Chunk(data.toString())); data.setLength(0); // Different type of links... String link = subject.toString().trim(); if (link.startsWith("Image:") || link.startsWith("image:")) { // @note From WikiImageLink.java String image = link.substring(6); String title = null; int frame = -1; int thumbnail = -1; int left = -1; int right = -1; int center = -1; int none = -1; int imageLink = -1; int alt = -1; if (image.indexOf("|") > 0) { // the image is first image = image.substring(0, image.indexOf("|")); // any directives are next frame = link.indexOf("|frame"); thumbnail = link.indexOf("|thumb"); left = link.indexOf("|left"); right = link.indexOf("|right"); center = link.indexOf("|center"); none = link.indexOf("|none"); imageLink = link.indexOf("|link="); alt = link.indexOf("|alt="); // the optional caption is last int last = link.lastIndexOf("|"); if (last > frame && last > thumbnail && last > left && last > right && last > center && last > none && last > imageLink && last > alt) { title = link.substring(last + 1); } } //A picture, including alternate text: //[[Image:Wiki.png|The logo for this Wiki]] //You can put the image in a frame with a caption: //[[Image:Wiki.png|frame|The logo for this Wiki]] // Access some image details int width = 0; int height = 0; ImageInfo imageInfo = imageList.get(image + (thumbnail > -1 ? "-TH" : "")); if (imageInfo != null) { width = imageInfo.getWidth(); height = imageInfo.getHeight(); } // Alt String altText = null; if (alt > -1) { int startIndex = alt + 4; int endIndex = link.indexOf("|", startIndex); if (endIndex == -1) { endIndex = link.length(); } altText = link.substring(startIndex, endIndex); } // Looks like the image needs a link (which is always last) String url = null; if (imageLink > -1) { // Get the entered link int startIndex = imageLink + 6; int endIndex = link.length(); String href = link.substring(startIndex, endIndex); // Treat as a wikiLink to validate and to create a proper url WikiLink wikiLink = new WikiLink(project.getId(), (altText != null ? href + " " + altText : href)); url = wikiLink.getUrl(""); if (!url.startsWith("http://") && !url.startsWith("https://")) { // @todo Use a local link // @todo Use an external link } } // Determine if local or external image if ((image.startsWith("http://") || image.startsWith("https://"))) { // retrieve external image String imageUrl = null; try { URL imageURL = new URL(image); imageUrl = image; } catch (Exception e) { } } else { // local image try { // @todo image alignment and links Image thisImage = Image.getInstance( getImageFilename(db, fileLibrary, project, image, (thumbnail > -1))); LOG.debug("Drawing image for area: " + cellWidth); if (cellWidth > 0f) { LOG.debug(" Image is embedded in cell"); // Guess the size of the cell float cellPixels = (500f * (cellWidth / 100f)); if (cellPixels > 0f && (float) width > cellPixels) { // Shrink image to fit the cell LOG.debug(" Scaling to fit"); thisImage.scaleToFit(cellPixels, 500f); } else { // Align image to left instead of scaling it to fit thisImage.setAlignment(Image.LEFT); } LOG.debug("cell.addElement(thisImage)"); cell.addElement(thisImage); } else { LOG.debug(" Image is inline"); if (width > 500) { LOG.debug(" Scaling to fit"); thisImage.scaleToFit(500f, 500f); } LOG.debug("main.add(thisImage)"); main.add(thisImage); } // thisImage.setAlignment(); // thisImage.Alignment = Image.TEXTWRAP | Image.ALIGN_RIGHT; // main.add(thisImage); } catch (FileNotFoundException fnfe) { LOG.warn("WikiPDFUtils-> Image was not found in the FileLibrary (" + getImageFilename(db, fileLibrary, project, image, (thumbnail > -1)) + ")... will continue."); } } /* if (frame > -1 || thumbnail > -1) { sb.append("</div>"); sb.append("<div id=\"caption\" style=\"margin-bottom: 5px; margin-left: 5px; margin-right: 5px; text-align: left;\">"); } if (thumbnail > -1) { sb.append("<div style=\"float:right\"><a target=\"_blank\" href=\"ProjectManagementWiki.do?command=Img&pid=" + wiki.getProjectId() + "&subject=" + StringUtils.replace(StringUtils.jsEscape(image), "%20", "+") + "\"><img src=\"images/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"Enlarge\" border=\"0\" /></a></div>"); } if (frame > -1 || thumbnail > -1) { if (title != null) { sb.append(StringUtils.toHtml(title)); } sb.append( " </div>\n" + "</div>"); } */ /* if (none > -1) { sb.append("<br clear=\"all\">"); } */ if (i + 1 == line.length() && (right > -1 || left > -1) || none > -1) { needsCRLF = false; } } else { // This is most likely a Wiki link String title = subject.toString().trim(); if (link.indexOf("|") > 0) { link = link.substring(0, link.indexOf("|")).trim(); title = title.substring(title.indexOf("|") + 1); } if (link.indexOf("http://") > -1 || link.indexOf("https://") > -1) { String label = link; if (link.indexOf(" ") > 0) { label = link.substring(link.indexOf(" ") + 1); link = link.substring(0, link.indexOf(" ")); } Anchor anchor1 = new Anchor(label, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255))); anchor1.setReference(link); anchor1.setName("top"); main.add(anchor1); } else { // Place a wiki link if (exportBean.getFollowLinks()) { // See if target link exists before creating a link to it int linkedWikiId = -1; if (StringUtils.hasText(title) && !title.startsWith("|")) { Wiki subwiki = WikiList.queryBySubject(db, title, project.getId()); if (subwiki.getId() > -1) { linkedWikiId = subwiki.getId(); } } // Display the linked item if (linkedWikiId > -1) { // Display as an anchor Anchor linkToWiki = new Anchor(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))); linkToWiki.setReference("#" + title.toLowerCase()); LOG.debug("Link to: #" + title.toLowerCase()); main.add(linkToWiki); LOG.debug(" main.add(linkToWiki)"); // main.add(new Chunk(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))).setLocalGoto(link)); // Add this wiki to the to do list... if (!wikiListTodo.contains(linkedWikiId)) { wikiListTodo.add(linkedWikiId); } } else { // Display without the link main.add(new Chunk(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255)))); } } else { // Not following links, so display... perhaps as an external link someday main.add(new Chunk(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255)))); } } } subject.setLength(0); linkL = 0; linkR = 0; } continue; } if (!"[".equals(c) && linkL == 2 && !"]".equals(c)) { subject.append(c); continue; } // Attribute properties if ("'".equals(c)) { ++attr; continue; } if (!"'".equals(c) && attr > 1) { if (attr == 2) { if (!italic) { main.add(new Chunk(data.toString())); data.setLength(0); data.append(c); italic = true; } else { data.append(c); main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC, new Color(0, 0, 0)))); data.setLength(0); italic = false; } attr = 0; continue; } if (attr == 3) { if (!bold) { main.add(new Chunk(data.toString())); data.setLength(0); data.append(c); bold = true; } else { data.append(c); main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0, 0, 0)))); data.setLength(0); bold = false; } attr = 0; continue; } if (attr == 5) { if (!bolditalic) { main.add(new Chunk(data.toString())); data.setLength(0); data.append(c); bolditalic = true; } else { data.append(c); main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLDITALIC, new Color(0, 0, 0)))); data.setLength(0); bolditalic = false; } attr = 0; continue; } } data.append(c); } for (int x = 0; x < linkR; x++) { data.append("]"); } for (int x = 0; x < linkL; x++) { data.append("["); } if (attr == 1) { data.append("'"); } if (italic) { main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC, new Color(0, 0, 0)))); } else if (bold) { main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(0, 0, 0)))); } else if (bolditalic) { main.add(new Chunk(data.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLDITALIC, new Color(0, 0, 0)))); } else { main.add(new Chunk(data.toString())); } data.setLength(0); return needsCRLF; }
From source file:com.conecta.sat.utils.BuildAsignaSoftPDF.java
@Override protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer, HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. System.out.println("Into BuildImportTokensPDF"); hsr1.setContentType("application/pdf"); DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss"); hsr1.setHeader("Content-disposition", "attachment; filename=AsignaToken" + name.format(new Date()) + ".pdf"); AsignaSoftPDF list = (AsignaSoftPDF) map.get("list"); String nombreUsuario = (String) map.get("nombreUsuario"); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100);/* w ww . java 2 s. c o m*/ table.setSpacingBefore(10); Font font = FontFactory.getFont(FontFactory.HELVETICA); try { font.setFamily(fontName); } catch (Exception e) { font.setFamily("Verdana"); } try { ServletContext servletContext = hsr.getSession().getServletContext(); String relativeWebPath = logoPath; String absoluteDiskPath = servletContext.getRealPath(relativeWebPath); Image logo = Image.getInstance(absoluteDiskPath); // Image logo = Image.getInstance("logo.png"); System.out.println("La imagen se cargo correctamente"); logo.scaleToFit(widthLogo, heightLogo); document.add(logo); } catch (Exception e) { System.err.println("ERROR" + Excepciones.getStackTrace(e)); document.add(new Paragraph("Sin imagen " + logoPath)); } font.setSize(fontSize + 3); Paragraph titulo = new Paragraph("Asignacin de Token a cliente", font); titulo.setAlignment(Element.ALIGN_RIGHT); document.add(titulo); Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f)); document.add(CONNECT); DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a"); font.setSize(fontSize + 2); Paragraph fecha = new Paragraph("Asignacin Correcta", font); fecha.setAlignment(Element.ALIGN_CENTER); document.add(fecha); // Paragraph pNombre = new Paragraph( nombreUsuario , font); // pNombre.setAlignment(Element.ALIGN_RIGHT); // document.add(pNombre); font.setSize(fontSize); font.setColor(java.awt.Color.white); // define table header cell PdfPCell cell = new PdfPCell(); java.awt.Color color = java.awt.Color.LIGHT_GRAY; cell.setBackgroundColor(color); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Nombre empleado", font)); table.addCell(cell); cell.setPhrase(new Phrase("Fecha y Hora", font)); table.addCell(cell); cell.setPhrase(new Phrase("Cliente", font)); table.addCell(cell); cell.setPhrase(new Phrase("Token", font)); table.addCell(cell); cell.setPhrase(new Phrase("Tipo de Token", font)); table.addCell(cell); // cell.setPhrase(new Phrase("Centro Financiero", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Tipo", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Cliente nico", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Fecha de ultima modificacin", font)); // table.addCell(cell); Font font2 = FontFactory.getFont(FontFactory.HELVETICA); try { font2.setFamily(fontName); } catch (Exception e) { font2.setFamily("Verdana"); } font2.setSize(fontSize); font2.setColor(java.awt.Color.black); // write table row data // for (ImportTokensPDF pdf : list) { // ImportTokensPDF pdf; cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getNombre(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(df.format(list.getFecha()), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getCliente(), font2)); table.addCell(cell); if (list.getToken().length() >= 14) { list.setTipo("SOFTTOKEN"); } else { list.setTipo("HARDTOKEN"); } cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getToken(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getTipo(), font2)); table.addCell(cell); // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getCentro(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getTipo(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getCliente(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getLastUpdate(),font2) ); // table.addCell(cell); // } document.add(table); }
From source file:com.conecta.sat.utils.BuildAsignaTokenCenFinPDF.java
@Override protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer, HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. System.out.println("Into BuildImportTokensPDF"); hsr1.setContentType("application/pdf"); DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss"); hsr1.setHeader("Content-disposition", "attachment; filename=AsignacionTokensCentroFinanciero" + name.format(new Date()) + ".pdf"); AsignaTokenCenFinPDF list = (AsignaTokenCenFinPDF) map.get("list"); String nombreUsuario = (String) map.get("nombreUsuario"); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100);// w w w . ja v a 2 s. c o m table.setSpacingBefore(10); Font font = FontFactory.getFont(FontFactory.HELVETICA); try { font.setFamily(fontName); } catch (Exception e) { font.setFamily("Verdana"); } try { ServletContext servletContext = hsr.getSession().getServletContext(); String relativeWebPath = logoPath; String absoluteDiskPath = servletContext.getRealPath(relativeWebPath); Image logo = Image.getInstance(absoluteDiskPath); // Image logo = Image.getInstance("logo.png"); System.out.println("La imagen se cargo correctamente"); logo.scaleToFit(widthLogo, heightLogo); document.add(logo); } catch (Exception e) { System.err.println("ERROR" + Excepciones.getStackTrace(e)); document.add(new Paragraph("Sin imagen " + logoPath)); } font.setSize(fontSize + 3); Paragraph titulo = new Paragraph("Asignacin de Hard Token", font); titulo.setAlignment(Element.ALIGN_RIGHT); document.add(titulo); Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f)); document.add(CONNECT); DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a"); font.setSize(fontSize + 2); Paragraph fecha = new Paragraph("Asignacin de Tokens a Centro Financiero", font); fecha.setAlignment(Element.ALIGN_CENTER); document.add(fecha); // Paragraph pNombre = new Paragraph( nombreUsuario , font); // pNombre.setAlignment(Element.ALIGN_RIGHT); // document.add(pNombre); font.setSize(fontSize); font.setColor(java.awt.Color.white); // define table header cell PdfPCell cell = new PdfPCell(); java.awt.Color color = java.awt.Color.LIGHT_GRAY; cell.setBackgroundColor(color); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(5); // write table header // cell.setPhrase(new Phrase("Usuario que importo en token", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Fecha y Hora", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Tokens importados", font)); // table.addCell(cell); // cell.setPhrase(new Phrase("Centro Financiero", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Tipo", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Cliente nico", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Fecha de ultima modificacin", font)); // table.addCell(cell); Font font2 = FontFactory.getFont(FontFactory.HELVETICA); try { font2.setFamily(fontName); } catch (Exception e) { font2.setFamily("Verdana"); } font2.setSize(fontSize); font2.setColor(java.awt.Color.black); // write table row data // for (ImportTokensPDF pdf : list) { // ImportTokensPDF pdf; cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase("Nombre empleado", font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getNombre(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase("Fecha de Asignacin", font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(df.format(list.getFecha()), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase("Centro Financiero asignado", font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getCentroFinanciero(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase("Tokens asignados", font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getTokens(), font2)); table.addCell(cell); document.add(table); }
From source file:com.conecta.sat.utils.BuildBitacoraPDF.java
@Override protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer, HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. hsr1.setContentType("application/pdf"); DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss"); hsr1.setHeader("Content-disposition", "attachment; filename=Bitacora" + name.format(new Date()) + ".pdf"); List<BitacoraPDF> list = (List<BitacoraPDF>) map.get("listBitacora"); String nombreUsuario = (String) map.get("nombreUsuario"); PdfPTable table = new PdfPTable(columnas); table.setWidthPercentage(100);//from w ww .j a v a2 s . c o m table.setSpacingBefore(10); Font font = FontFactory.getFont(FontFactory.HELVETICA); try { font.setFamily(fontName); } catch (Exception e) { font.setFamily("Verdana"); } try { ServletContext servletContext = hsr.getSession().getServletContext(); String relativeWebPath = logoPath; String absoluteDiskPath = servletContext.getRealPath(relativeWebPath); Image logo = Image.getInstance(absoluteDiskPath); // Image logo = Image.getInstance("logo.png"); System.out.println("La imagen se cargo correctamente"); logo.scaleToFit(widthLogo, heightLogo); document.add(logo); } catch (Exception e) { System.err.println("ERROR" + Excepciones.getStackTrace(e)); document.add(new Paragraph("Sin imagen " + logoPath)); } font.setSize(fontSize + 3); Paragraph titulo = new Paragraph("Bitcora de Actividades", font); titulo.setAlignment(Element.ALIGN_RIGHT); document.add(titulo); Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f)); document.add(CONNECT); DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a"); font.setSize(fontSize + 2); Paragraph fecha = new Paragraph(df.format(new Date()), font); fecha.setAlignment(Element.ALIGN_RIGHT); document.add(fecha); Paragraph pNombre = new Paragraph(nombreUsuario, font); pNombre.setAlignment(Element.ALIGN_RIGHT); document.add(pNombre); font.setSize(fontSize); font.setColor(java.awt.Color.white); // define table header cell PdfPCell cell = new PdfPCell(); java.awt.Color color = java.awt.Color.LIGHT_GRAY; cell.setBackgroundColor(color); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Nombre de usuario", font)); table.addCell(cell); cell.setPhrase(new Phrase("Bitcora", font)); table.addCell(cell); cell.setPhrase(new Phrase("ltima fecha de Modificaciones", font)); table.addCell(cell); Font font2 = FontFactory.getFont(FontFactory.HELVETICA); try { font2.setFamily(fontName); } catch (Exception e) { font2.setFamily("Verdana"); } font2.setSize(fontSize); font2.setColor(java.awt.Color.black); // write table row data df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (BitacoraPDF bitacora : list) { cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(bitacora.getNombre(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(bitacora.getMensaje(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(bitacora.getFecha(), font2)); table.addCell(cell); cell = new PdfPCell(); } document.add(table); }
From source file:com.conecta.sat.utils.BuildDesactivarSoftPDF.java
@Override protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer, HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. System.out.println("Into BuildImportTokensPDF"); hsr1.setContentType("application/pdf"); DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss"); hsr1.setHeader("Content-disposition", "attachment; filename=DesactivarToken" + name.format(new Date()) + ".pdf"); AsignaSoftPDF list = (AsignaSoftPDF) map.get("list"); String nombreUsuario = (String) map.get("nombreUsuario"); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100);//from www.j a v a 2 s. c o m table.setSpacingBefore(10); Font font = FontFactory.getFont(FontFactory.HELVETICA); try { font.setFamily(fontName); } catch (Exception e) { font.setFamily("Verdana"); } try { ServletContext servletContext = hsr.getSession().getServletContext(); String relativeWebPath = logoPath; String absoluteDiskPath = servletContext.getRealPath(relativeWebPath); Image logo = Image.getInstance(absoluteDiskPath); // Image logo = Image.getInstance("logo.png"); System.out.println("La imagen se cargo correctamente"); logo.scaleToFit(widthLogo, heightLogo); document.add(logo); } catch (Exception e) { System.err.println("ERROR" + Excepciones.getStackTrace(e)); document.add(new Paragraph("Sin imagen " + logoPath)); } font.setSize(fontSize + 3); Paragraph titulo = new Paragraph("Desactivacin de Token a cliente", font); titulo.setAlignment(Element.ALIGN_RIGHT); document.add(titulo); Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f)); document.add(CONNECT); DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a"); font.setSize(fontSize + 2); Paragraph fecha = new Paragraph("Cambio de Status Correcto", font); fecha.setAlignment(Element.ALIGN_CENTER); document.add(fecha); // Paragraph pNombre = new Paragraph( nombreUsuario , font); // pNombre.setAlignment(Element.ALIGN_RIGHT); // document.add(pNombre); font.setSize(fontSize); font.setColor(java.awt.Color.white); // define table header cell PdfPCell cell = new PdfPCell(); java.awt.Color color = java.awt.Color.LIGHT_GRAY; cell.setBackgroundColor(color); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Nombre empleado", font)); table.addCell(cell); cell.setPhrase(new Phrase("Fecha y Hora", font)); table.addCell(cell); cell.setPhrase(new Phrase("Cliente", font)); table.addCell(cell); cell.setPhrase(new Phrase("Token", font)); table.addCell(cell); cell.setPhrase(new Phrase("Tipo de Token", font)); table.addCell(cell); // cell.setPhrase(new Phrase("Centro Financiero", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Tipo", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Cliente nico", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Fecha de ultima modificacin", font)); // table.addCell(cell); if (list.getToken().length() < 8) { list.setTipo("SoftToken"); } else { list.setTipo("HardToken"); } Font font2 = FontFactory.getFont(FontFactory.HELVETICA); try { font2.setFamily(fontName); } catch (Exception e) { font2.setFamily("Verdana"); } font2.setSize(fontSize); font2.setColor(java.awt.Color.black); // write table row data // for (ImportTokensPDF pdf : list) { // ImportTokensPDF pdf; cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getNombre(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(df.format(list.getFecha()), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getCliente(), font2)); table.addCell(cell); if (list.getToken().length() > 8) { list.setTipo("SOFTTOKEN"); } else { list.setTipo("HARDTOKEN"); } cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getToken(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getTipo(), font2)); table.addCell(cell); // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getCentro(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getTipo(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getCliente(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getLastUpdate(),font2) ); // table.addCell(cell); // } document.add(table); }
From source file:com.conecta.sat.utils.BuildDesasignaSoftPDF.java
@Override protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer, HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. System.out.println("Into BuildImportTokensPDF"); hsr1.setContentType("application/pdf"); DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss"); hsr1.setHeader("Content-disposition", "attachment; filename=CancelarToken" + name.format(new Date()) + ".pdf"); AsignaSoftPDF list = (AsignaSoftPDF) map.get("list"); String nombreUsuario = (String) map.get("nombreUsuario"); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100);/*from w ww . ja v a2s .c o m*/ table.setSpacingBefore(10); Font font = FontFactory.getFont(FontFactory.HELVETICA); try { font.setFamily(fontName); } catch (Exception e) { font.setFamily("Verdana"); } try { ServletContext servletContext = hsr.getSession().getServletContext(); String relativeWebPath = logoPath; String absoluteDiskPath = servletContext.getRealPath(relativeWebPath); Image logo = Image.getInstance(absoluteDiskPath); // Image logo = Image.getInstance("logo.png"); System.out.println("La imagen se cargo correctamente"); logo.scaleToFit(widthLogo, heightLogo); document.add(logo); } catch (Exception e) { System.err.println("ERROR" + Excepciones.getStackTrace(e)); document.add(new Paragraph("Sin imagen " + logoPath)); } font.setSize(fontSize + 3); Paragraph titulo = new Paragraph("Cancelacin de Token a cliente", font); titulo.setAlignment(Element.ALIGN_RIGHT); document.add(titulo); Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f)); document.add(CONNECT); DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a"); font.setSize(fontSize + 2); Paragraph fecha = new Paragraph("Cancelacin Correcta", font); fecha.setAlignment(Element.ALIGN_CENTER); document.add(fecha); // Paragraph pNombre = new Paragraph( nombreUsuario , font); // pNombre.setAlignment(Element.ALIGN_RIGHT); // document.add(pNombre); font.setSize(fontSize); font.setColor(java.awt.Color.white); // define table header cell PdfPCell cell = new PdfPCell(); java.awt.Color color = java.awt.Color.LIGHT_GRAY; cell.setBackgroundColor(color); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Nombre empleado", font)); table.addCell(cell); cell.setPhrase(new Phrase("Fecha y Hora", font)); table.addCell(cell); cell.setPhrase(new Phrase("Cliente", font)); table.addCell(cell); cell.setPhrase(new Phrase("Token", font)); table.addCell(cell); cell.setPhrase(new Phrase("Tipo de Token", font)); table.addCell(cell); // cell.setPhrase(new Phrase("Centro Financiero", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Tipo", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Cliente nico", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Fecha de ultima modificacin", font)); // table.addCell(cell); if (list.getToken().length() < 8) { list.setTipo("SoftToken"); } else { list.setTipo("HardToken"); } Font font2 = FontFactory.getFont(FontFactory.HELVETICA); try { font2.setFamily(fontName); } catch (Exception e) { font2.setFamily("Verdana"); } font2.setSize(fontSize); font2.setColor(java.awt.Color.black); // write table row data // for (ImportTokensPDF pdf : list) { // ImportTokensPDF pdf; cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getNombre(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(df.format(list.getFecha()), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getCliente(), font2)); table.addCell(cell); if (list.getToken().length() == 14) { list.setTipo("SOFTTOKEN"); } else { list.setTipo("HARDTOKEN"); } cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getToken(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getTipo(), font2)); table.addCell(cell); // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getCentro(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getTipo(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getCliente(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getLastUpdate(),font2) ); // table.addCell(cell); // } document.add(table); }
From source file:com.conecta.sat.utils.BuildDesasignaTokenCenFinPDF.java
@Override protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer, HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. System.out.println("Into BuildImportTokensPDF"); hsr1.setContentType("application/pdf"); DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss"); hsr1.setHeader("Content-disposition", "attachment; filename=DesasignacionTokensCentroFinanciero" + name.format(new Date()) + ".pdf"); DesasignaTokenCenFinPDF list = (DesasignaTokenCenFinPDF) map.get("list"); String nombreUsuario = (String) map.get("nombreUsuario"); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100);//from w ww. j ava 2 s . c om table.setSpacingBefore(10); Font font = FontFactory.getFont(FontFactory.HELVETICA); try { font.setFamily(fontName); } catch (Exception e) { font.setFamily("Verdana"); } try { ServletContext servletContext = hsr.getSession().getServletContext(); String relativeWebPath = logoPath; String absoluteDiskPath = servletContext.getRealPath(relativeWebPath); Image logo = Image.getInstance(absoluteDiskPath); // Image logo = Image.getInstance("logo.png"); System.out.println("La imagen se cargo correctamente"); logo.scaleToFit(widthLogo, heightLogo); document.add(logo); } catch (Exception e) { System.err.println("ERROR" + Excepciones.getStackTrace(e)); document.add(new Paragraph("Sin imagen " + logoPath)); } font.setSize(fontSize + 3); Paragraph titulo = new Paragraph("Desasignacin de Hard Token", font); titulo.setAlignment(Element.ALIGN_RIGHT); document.add(titulo); Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f)); document.add(CONNECT); DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a"); font.setSize(fontSize + 2); Paragraph fecha = new Paragraph("Desasignacin de Tokens a Centro Financiero", font); fecha.setAlignment(Element.ALIGN_CENTER); document.add(fecha); // Paragraph pNombre = new Paragraph( nombreUsuario , font); // pNombre.setAlignment(Element.ALIGN_RIGHT); // document.add(pNombre); font.setSize(fontSize); font.setColor(java.awt.Color.white); // define table header cell PdfPCell cell = new PdfPCell(); java.awt.Color color = java.awt.Color.LIGHT_GRAY; cell.setBackgroundColor(color); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(5); // write table header // cell.setPhrase(new Phrase("Usuario que importo en token", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Fecha y Hora", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Tokens importados", font)); // table.addCell(cell); // cell.setPhrase(new Phrase("Centro Financiero", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Tipo", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Cliente nico", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Fecha de ultima modificacin", font)); // table.addCell(cell); Font font2 = FontFactory.getFont(FontFactory.HELVETICA); try { font2.setFamily(fontName); } catch (Exception e) { font2.setFamily("Verdana"); } font2.setSize(fontSize); font2.setColor(java.awt.Color.black); // write table row data // for (ImportTokensPDF pdf : list) { // ImportTokensPDF pdf; cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase("Nombre empleado", font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getNombre(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase("Fecha de Desasignacin", font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(df.format(list.getFecha()), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase("Tokens desasignados", font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getTokens(), font2)); table.addCell(cell); document.add(table); }