List of usage examples for com.lowagie.text Paragraph setAlignment
public void setAlignment(String alignment)
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
License:Apache License
private void printElementHtml(Element element, Object parent, int depth, Font font, int parentLevel) { String tag = element.getName(); Object av;//from ww w . j a v a 2 s.c om if (element instanceof HTMLDocument.RunElement) { HTMLDocument.RunElement re = (HTMLDocument.RunElement) element; int start = re.getStartOffset(); int end = re.getEndOffset(); try { String content = re.getDocument().getText(start, end - start); printAttributesHtml(re); av = re.getAttribute(CSS.Attribute.FONT_SIZE); String fontsize = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.FONT_FAMILY); String fontfamily = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.COLOR); String fontcolor = av == null ? null : av.toString(); if (fontcolor != null || fontsize != null || fontfamily != null) { if (fontfamily == null) fontfamily = font.getFamilyname(); float size = fontsize == null ? font.getSize() : (Float.parseFloat(fontsize) + 9); int style = font.getStyle(); Color color; if (fontcolor != null) { color = Color.decode(fontcolor); } else color = font.getColor(); font = FontFactory.getFont(fontfamily, size, style, color); } if (parent instanceof Paragraph) { ((Paragraph) parent).add(new Chunk(content, font)); } else { System.err.println("chunk with parent " + (parent == null ? "null" : parent.getClass().getName()) + ": " + content); } } catch (BadLocationException e) { e.printStackTrace(); } } else if (element instanceof HTMLDocument.BlockElement) { HTMLDocument.BlockElement be = (HTMLDocument.BlockElement) element; printAttributesHtml(be); av = be.getAttribute(javax.swing.text.html.HTML.Attribute.ALIGN); String align = av == null ? null : av.toString(); if (tag.equalsIgnoreCase("html")) { printElementChildrenHtml(element, parent, depth + 1, font, parentLevel); } else if (tag.equalsIgnoreCase("head")) { // do nothing } else if (tag.equalsIgnoreCase("body")) { printElementChildrenHtml(element, parent, depth + 1, font, parentLevel); } else if (tag.equalsIgnoreCase("p")) { if (parent instanceof Section) { Paragraph paragraph = new Paragraph(); if (align != null) { paragraph.setAlignment(align); } printElementChildrenHtml(element, paragraph, depth + 1, normalFont, parentLevel); ((Section) parent).add(paragraph); } else { System.err.println("p with parent " + (parent == null ? "null" : parent.getClass().getName())); } } else if (tag.equalsIgnoreCase("h1") || tag.equalsIgnoreCase("h2") || tag.equalsIgnoreCase("h3")) { if (parent instanceof Section) { Paragraph title = new Paragraph(); printElementChildrenHtml(element, title, depth + 1, subSectionFont, parentLevel); ((Section) parent).addSection(title, parentLevel == 0 ? 0 : (parentLevel + 1)); } else { System.err .println("list with parent " + (parent == null ? "null" : parent.getClass().getName())); } } else if (tag.equalsIgnoreCase("ul")) { if (parent instanceof Section) { com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f); printElementChildrenHtml(element, list, depth + 1, normalFont, parentLevel); ((Section) parent).add(list); } else { System.err .println("list with parent " + (parent == null ? "null" : parent.getClass().getName())); } } else if (tag.equalsIgnoreCase("ol")) { if (parent instanceof Section) { com.lowagie.text.List list = new com.lowagie.text.List(true, false, 20.0f); printElementChildrenHtml(element, list, depth + 1, normalFont, parentLevel); ((Section) parent).add(list); } else { System.err .println("list with parent " + (parent == null ? "null" : parent.getClass().getName())); } } else if (tag.equalsIgnoreCase("li")) { ListItem li = new ListItem(); li.setSpacingAfter(0.0f); printElementChildrenHtml(element, li, depth + 1, normalFont, parentLevel); ((com.lowagie.text.List) parent).add(li); } else if (tag.equalsIgnoreCase("p-implied")) { if (parent instanceof ListItem) { Paragraph paragraph = new Paragraph(); printElementChildrenHtml(element, paragraph, depth + 1, normalFont, parentLevel); ((ListItem) parent).add(paragraph); } else if (parent instanceof Cell) { Paragraph paragraph = new Paragraph(); printElementChildrenHtml(element, paragraph, depth + 1, normalFont, parentLevel); ((Cell) parent).add(paragraph); } } else if (tag.equalsIgnoreCase("table")) { try { Table table = new Table(3); table.setBorderWidth(1); table.setBorderColor(new Color(0, 128, 128)); table.setPadding(1.0f); table.setSpacing(0.5f); Cell c = new Cell("header"); c.setHeader(true); c.setColspan(3); table.addCell(c); table.endHeaders(); printElementChildrenHtml(element, table, depth + 1, normalFont, parentLevel); // TODO ((Section) parent).add(table); } catch (BadElementException e) { e.printStackTrace(); } } else if (tag.equalsIgnoreCase("tr")) { printElementChildrenHtml(element, parent, depth + 1, normalFont, parentLevel); // TODO } else if (tag.equalsIgnoreCase("td")) { Cell cell = new Cell(); printElementChildrenHtml(element, cell, depth + 1, normalFont, parentLevel); // TODO ((Table) parent).addCell(cell); } else { System.err.println("Unknown element " + element.getName()); printElementChildrenHtml(element, parent, depth + 1, normalFont, parentLevel); } } else { return; // could be BidiElement - not sure what it is } }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
License:Apache License
private Object generateElementHtml(Element element, int depth, Font font) { String tag = element.getName(); Object myself;//from w w w .j a v a 2 s .c om Object av; if (element instanceof HTMLDocument.RunElement) { HTMLDocument.RunElement re = (HTMLDocument.RunElement) element; int start = re.getStartOffset(); int end = re.getEndOffset(); try { String content = re.getDocument().getText(start, end - start); HtmlAttr htmlattr = printAttributesHtml(re); av = re.getAttribute(CSS.Attribute.FONT_SIZE); String fontsize = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.FONT_FAMILY); String fontfamily = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.COLOR); String fontcolor = av == null ? null : av.toString(); if (fontcolor != null || fontsize != null || fontfamily != null) { if (fontfamily == null) fontfamily = font.getFamilyname(); if (fontsize != null && fontsize.endsWith("pt")) fontsize = fontsize.substring(0, fontsize.indexOf("pt")); float size = fontsize == null ? font.getSize() : (Float.parseFloat(fontsize) + 8); int style = font.getStyle(); Color color; if (fontcolor != null) { color = Color.decode(fontcolor); } else color = font.getColor(); font = FontFactory.getFont(fontfamily, size, style, color); } else if (htmlattr.bold || htmlattr.italic) { String family = font.getFamilyname(); float size = font.getSize(); Color color = font.getColor(); if (htmlattr.bold && htmlattr.italic) font = FontFactory.getFont(family, size, Font.BOLDITALIC, color); else if (htmlattr.italic) font = FontFactory.getFont(family, size, Font.ITALIC, color); else if (htmlattr.bold) font = FontFactory.getFont(family, size, Font.BOLD); } myself = new Chunk(content, font); } catch (BadLocationException e) { e.printStackTrace(); myself = null; } } else if (element instanceof HTMLDocument.BlockElement) { HTMLDocument.BlockElement be = (HTMLDocument.BlockElement) element; HtmlAttr htmlattr = printAttributesHtml(be); if (htmlattr.bold) { System.out.println("+++BOLD!!!"); } av = be.getAttribute(javax.swing.text.html.HTML.Attribute.ALIGN); String align = av == null ? null : av.toString(); if (htmlattr.bold || htmlattr.italic) { String family = font.getFamilyname(); float size = font.getSize(); Color color = font.getColor(); if (htmlattr.bold && htmlattr.italic) font = FontFactory.getFont(family, size, Font.BOLDITALIC, color); else if (htmlattr.italic) font = FontFactory.getFont(family, size, Font.ITALIC, color); else if (htmlattr.bold) font = FontFactory.getFont(family, size, Font.BOLD, Color.blue); } if (tag.equalsIgnoreCase("html")) { myself = generateElementChildrenHtml(element, depth + 1, font); } else if (tag.equalsIgnoreCase("head")) { myself = null; } else if (tag.equalsIgnoreCase("body")) { myself = generateElementChildrenHtml(element, depth + 1, font); } else if (tag.equalsIgnoreCase("p") || tag.equalsIgnoreCase("p-implied")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); Paragraph paragraph = new Paragraph(); paragraph.setFirstLineIndent(0F); for (Object child : children) { if (child instanceof Chunk) { Chunk chunk = (Chunk) child; /*if (!chunk.getContent().equals("\n"))*/ paragraph.add(chunk); } else paragraph.add(child); } if (align != null) paragraph.setAlignment(align); myself = paragraph; } else if (tag.equalsIgnoreCase("h1") || tag.equalsIgnoreCase("h2") || tag.equalsIgnoreCase("h3")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, subSectionFont); Paragraph title = new Paragraph(); for (Object child : children) { title.add(child); } myself = new TempSectionPdf(title); } else if (tag.equalsIgnoreCase("ul")) { com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f); list.setIndentationLeft(25.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { list.add(child); } myself = list; } else if (tag.equalsIgnoreCase("ol")) { com.lowagie.text.List list = new com.lowagie.text.List(true, false, 20.0f); list.setIndentationLeft(25.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { list.add(child); } myself = list; } else if (tag.equalsIgnoreCase("li")) { ListItem li = new ListItem(); li.setSpacingAfter(0.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { li.add(child); } myself = li; } else if (tag.equalsIgnoreCase("table")) { List<Object> rows = generateElementChildrenHtml(element, depth + 1, normalFont); try { int ncols = 0; for (Object row : rows) { if (row instanceof List<?>) { int n = ((List<?>) row).size(); if (n > ncols) ncols = n; } } Table table = new Table(2); table.setBorderWidth(1); table.setBorderColor(new Color(0, 128, 128)); table.setPadding(1.0f); table.setSpacing(0.5f); Cell c = new Cell("header"); c.setHeader(true); c.setColspan(ncols); table.addCell(c); table.endHeaders(); for (Object row : rows) { if (row instanceof List<?>) { for (Object cell : (List<?>) row) { if (cell instanceof Cell) table.addCell((Cell) cell); } } } myself = table; } catch (BadElementException e) { e.printStackTrace(); myself = null; } } else if (tag.equalsIgnoreCase("tr")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); myself = children; } else if (tag.equalsIgnoreCase("td")) { Cell cell = new Cell(); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { cell.add(child); } myself = cell; } else if (tag.equalsIgnoreCase("div")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); Paragraph paragraph = new Paragraph(); paragraph.setFirstLineIndent(0F); for (Object child : children) { paragraph.add(child); } if (align != null) paragraph.setAlignment(align); myself = paragraph; } else { System.err.println("Unknown element " + element.getName()); myself = null; } } else { myself = null; // could be BidiElement - not sure what it is } return myself; }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
private static boolean parseContent(WikiPDFContext context, Wiki wiki, String content, Document document, PdfPCell cell, Connection db, ArrayList<Integer> wikiListTodo, ArrayList<Integer> wikiListDone, float cellWidth) throws Exception { LOG.debug("PARSING CONTENT: " + content); // Parse the wiki page int lastIndent = 0; boolean preTag = false; boolean pre = false; boolean code = false; boolean header = true; try {/*from ww w. j a va2 s .c om*/ BufferedReader in = new BufferedReader(new StringReader(content)); String line = null; ArrayList unorderedParents = null; List thisList = null; Paragraph codeParagraph = null; while ((line = in.readLine()) != null) { // Tables if (line.startsWith("|")) { // @todo Close all ordered lists, unordered lists, and paragraphs // Parse the table line = parseTable(context, wiki, line, document, db, wikiListTodo, wikiListDone, in); if (line == null) { continue; } } // Forms if (line.startsWith("[{form")) { // @todo close any lists or paragraphs // parseForm operates over all the lines that make up the form, // it will have to look forward so it returns an unparsed line parseForm(context, db, in, line, document, cell); continue; } // Handle code blocks // @todo chunk the content similar to WikiToHTMLUtils otherwise inaccurate if (line.startsWith("<pre>") || line.startsWith("<code>")) { if (!code && !pre) { if (line.startsWith("<pre>")) { preTag = true; pre = true; } else if (line.startsWith("<code>")) { code = true; } codeParagraph = new Paragraph("", codeFont); codeParagraph.setSpacingBefore(10); if (pre && line.length() > ("<pre>").length()) { int endOfLine = line.length(); if (line.endsWith("</pre>")) { endOfLine = line.indexOf("</pre>"); } // This line has some extra content that needs to be added codeParagraph.add(new Chunk( line.substring(line.indexOf("<pre>") + 5, endOfLine) + Chunk.NEWLINE)); } if (code && line.length() > ("<code>").length()) { int endOfLine = line.length(); if (line.endsWith("</code>")) { endOfLine = line.indexOf("</code>"); } // This line has some extra content that needs to be added codeParagraph.add(new Chunk( line.substring(line.indexOf("<code>") + 6, endOfLine) + Chunk.NEWLINE)); } // See if this is a single line block if (preTag && line.endsWith("</pre>")) { // This is a single line block, so finish processing it } else if (code && line.endsWith("</code>")) { // This is a single line block, so finish processing it } else { // There are more lines to process, so do that continue; } } } if (line.startsWith("</code>") || line.endsWith("</code>")) { if (code) { code = false; if (line.indexOf("</code>") > 0 && !line.startsWith("<code>")) { // This line has some extra content that needs to be added codeParagraph .add(new Chunk(line.substring(0, line.indexOf("</code>")) + Chunk.NEWLINE)); } // Draw the final content PdfPTable codeTable = new PdfPTable(1); codeTable.setWidthPercentage(100); codeTable.setSpacingBefore(10); PdfPCell codeCell = new PdfPCell(codeParagraph); codeCell.setPadding(20); codeCell.setBorderColor(new Color(100, 100, 100)); codeCell.setBackgroundColor(new Color(200, 200, 200)); // codeCell.setNoWrap(true); codeTable.addCell(codeCell); LOG.debug("document.add(codeTable)"); document.add(codeTable); continue; } } if (line.startsWith("</pre>") || line.endsWith("</pre>")) { if (pre) { preTag = false; pre = false; if (line.indexOf("</pre>") > 0 && !line.startsWith("<pre>")) { // This line has some extra content that needs to be added codeParagraph.add(new Chunk(line.substring(0, line.indexOf("</pre>")) + Chunk.NEWLINE)); } // Draw the final content PdfPTable codeTable = new PdfPTable(1); codeTable.setWidthPercentage(100); codeTable.setSpacingBefore(10); PdfPCell codeCell = new PdfPCell(codeParagraph); codeCell.setPadding(20); codeCell.setBorderColor(new Color(100, 100, 100)); codeCell.setBackgroundColor(new Color(200, 200, 200)); // codeCell.setNoWrap(true); codeTable.addCell(codeCell); LOG.debug("document.add(codeTable)"); document.add(codeTable); continue; } } if (code || preTag) { // Append the chunk codeParagraph.add(new Chunk(line + Chunk.NEWLINE)); continue; } // Section if (line.startsWith("=") && line.endsWith("=")) { // @todo close any open lists or paragraphs int hCount = parseHCount(line, "="); if (hCount > 6) { hCount = 6; } String section = line.substring(line.indexOf("=") + hCount, line.lastIndexOf("=") - hCount + 1); header = true; context.foundHeader(hCount); String headerAnchor = null; // Store the h2's with anchors for table of contents or index if (hCount == 2) { headerAnchor = StringUtils.toHtmlValue(section).replace(" ", "_"); context.getHeaderAnchors().put(headerAnchor, section); } if (hCount == 3) { Paragraph title = new Paragraph(section.trim(), section2Font); title.setSpacingBefore(10); if (cell != null) { LOG.debug("phrase.add(title)"); cell.addElement(title); } else { LOG.debug("document.add(title)"); document.add(title); } } else if (hCount > 3) { Paragraph title = new Paragraph(section.trim(), section3Font); title.setSpacingBefore(10); if (cell != null) { LOG.debug("phrase.add(title)"); cell.addElement(title); } else { LOG.debug("document.add(title)"); document.add(title); } } else { Paragraph title = new Paragraph(section.trim(), sectionFont); title.setSpacingBefore(10); if (cell != null) { LOG.debug("phrase.add(title)"); cell.addElement(title); } else { LOG.debug("document.add(title)"); document.add(title); } } continue; } if (header) { header = false; if (line.trim().equals("")) { // remove the extra space a user may leave after a header continue; } } // Determine if this is a bulleted list if (line.startsWith("*") || line.startsWith("#")) { // Initialize the list array if (unorderedParents == null) { unorderedParents = new ArrayList(); // if (phrase != null) { // LOG.debug("phrase.add(new Paragraph(Chunk.NEWLINE))"); // phrase.add(new Paragraph(Chunk.NEWLINE)); // } else { // LOG.debug("document.add(new Paragraph(Chunk.NEWLINE))"); // document.add(new Paragraph(Chunk.NEWLINE)); // } } // Get the indent level boolean ol = line.startsWith("#"); int hCount = WikiPDFUtils.parseHCount(line, ol ? "#" : "*"); // Determine a shift in the tree if (lastIndent == 0) { if (ol) { thisList = new List(ol, 20); } else { thisList = new List(ol, 10); thisList.setListSymbol( new Chunk("\u2022", FontFactory.getFont(FontFactory.HELVETICA, 12))); } thisList.setIndentationLeft(36); thisList.setIndentationRight(36); unorderedParents.add(thisList); } else { if (hCount > lastIndent) { if (ol) { thisList = new List(ol, 20); } else { thisList = new List(ol, 10); thisList.setListSymbol( new Chunk("\u2022", FontFactory.getFont(FontFactory.HELVETICA, 12))); } thisList.setIndentationLeft(36); thisList.setIndentationRight(36); ((List) unorderedParents.get(unorderedParents.size() - 1)).add(thisList); unorderedParents.add(thisList); } else if (hCount < lastIndent) { unorderedParents.remove(unorderedParents.size() - 1); thisList = (List) unorderedParents.get(unorderedParents.size() - 1); } } lastIndent = hCount; // Append the item... Paragraph thisItem = new Paragraph(); parseLine(context, line.substring(hCount).trim(), thisItem, db, wikiListTodo, cellWidth, cell); thisList.add(new ListItem(thisItem)); continue; } // List is finished, so append it to the document before working on // other paragraphs if (unorderedParents != null) { if (cell != null) { LOG.debug("phrase.add((List) unorderedParents.get(0))"); cell.addElement((List) unorderedParents.get(0)); } else { LOG.debug("document.add((List) unorderedParents.get(0))"); document.add((List) unorderedParents.get(0)); } unorderedParents = null; thisList = null; lastIndent = 0; } // Otherwise a simple paragraph Paragraph paragraph = new Paragraph(); parseLine(context, line, paragraph, db, wikiListTodo, cellWidth, cell); if (cell != null) { LOG.debug("phrase.add(paragraph)"); if (cell.getHorizontalAlignment() == Element.ALIGN_CENTER) { paragraph.setAlignment(Element.ALIGN_CENTER); } paragraph.setSpacingBefore(5); cell.addElement(paragraph); } else { LOG.debug("document.add(paragraph)"); paragraph.setSpacingBefore(5); document.add(paragraph); } } // Cleanup now that the lines are finished if (pre || code) { PdfPTable codeTable = new PdfPTable(1); codeTable.setWidthPercentage(100); codeTable.setSpacingBefore(10); PdfPCell codeCell = new PdfPCell(codeParagraph); codeCell.setPadding(20); codeCell.setBorderColor(new Color(100, 100, 100)); codeCell.setBackgroundColor(new Color(200, 200, 200)); // codeCell.setNoWrap(true); codeTable.addCell(codeCell); LOG.debug("document.add(codeTable)"); document.add(codeTable); } if (unorderedParents != null) { if (cell != null) { LOG.debug("phrase.add((List) unorderedParents.get(0))"); cell.addElement((List) unorderedParents.get(0)); } else { LOG.debug("document.add((List) unorderedParents.get(0))"); document.add((List) unorderedParents.get(0)); } } in.close(); } catch (Exception e) { LOG.error("parseContent", e); } return true; }
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 w w.j av 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 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);/* ww w . j ava2s . 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("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 ww w .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 w w w .java2s .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("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);/* ww w. ja v a2 s. co 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 www .jav 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("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); }
From source file:com.conecta.sat.utils.BuildImportTokensPDF.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=ImportTokens" + name.format(new Date()) + ".pdf"); ImportTokensPDF list = (ImportTokensPDF) map.get("list"); String nombreUsuario = (String) map.get("nombreUsuario"); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100);//w ww. j a v a 2s .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("Reporte de Tokens", 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("Nmero de empleado 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(list.getUsuario(), 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.getTokens(), 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); }