List of usage examples for com.lowagie.text Element ALIGN_CENTER
int ALIGN_CENTER
To view the source code for com.lowagie.text Element ALIGN_CENTER.
Click Source Link
From source file:com.bytecode.customexporter.PDFCustomExporter.java
protected PdfPCell addFacetAlignments(UIComponent component, PdfPCell cell) { if (component instanceof HtmlOutputText) { HtmlOutputText output = (HtmlOutputText) component; if (output.getStyle() != null && output.getStyle().contains("left")) { cell.setHorizontalAlignment(Element.ALIGN_LEFT); } else if (output.getStyle() != null && output.getStyle().contains("right")) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else {/*from ww w . j a v a 2s . co m*/ cell.setHorizontalAlignment(Element.ALIGN_CENTER); } } return cell; }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
public static boolean exportToFile(WikiPDFContext context, Connection db) throws Exception { LOG.debug("exportToFile-> begin"); // Context Objects Wiki wiki = context.getWiki();//from ww w.j a v a2 s . co m Project project = context.getProject(); File file = context.getFile(); WikiExportBean exportBean = context.getExportBean(); // Determine the content to parse String content = wiki.getContent(); if (content == null) { return false; } // Create a pdf Document document = new Document(PageSize.LETTER); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); // Meta data document.addTitle(project.getTitle()); document.addSubject(wiki.getSubject()); document.addCreator("Concursive ConcourseConnect"); document.addAuthor("Wiki Contributor"); //writer.setPageEvent(new PageNumbersWatermark()); if (!exportBean.getIncludeTitle()) { boolean hasTitle = StringUtils.hasText(wiki.getSubject()); HeaderFooter pageFooter = new HeaderFooter( new Phrase(project.getTitle() + (hasTitle ? ": " + wiki.getSubject() : "") + " - page "), new Phrase("")); pageFooter.setAlignment(Element.ALIGN_CENTER); document.setFooter(pageFooter); } document.open(); if (exportBean.getIncludeTitle()) { //HeaderFooter pageHeader = new HeaderFooter(new Phrase(project.getTitle()), false); //document.setHeader(pageHeader); boolean hasTitle = (StringUtils.hasText(wiki.getSubject())); HeaderFooter pageFooter = new HeaderFooter( new Phrase(project.getTitle() + (hasTitle ? ": " + wiki.getSubject() : "") + " - page "), new Phrase("")); pageFooter.setAlignment(Element.ALIGN_CENTER); document.setFooter(pageFooter); // Draw a title page Rectangle rectangle = new Rectangle(600, 30); rectangle.setBackgroundColor(new Color(100, 100, 100)); LOG.debug("document.add(rectangle)"); document.add(rectangle); document.add(new Paragraph(project.getTitle(), titleFont)); if (!"".equals(wiki.getSubject())) { document.add(new Paragraph(wiki.getSubject(), titleFont)); } document.add(Chunk.NEWLINE); document.add(new Paragraph("Last Modified: " + wiki.getModified(), titleSmallFont)); document.newPage(); } ArrayList<Integer> wikiListDone = new ArrayList<Integer>(); appendWiki(context, context.getWiki(), document, db, wikiListDone); // Close everything document.close(); writer.close(); LOG.debug("exportToFile-> finished"); return true; }
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 ava 2 s . c o m 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.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
private static String parseTable(WikiPDFContext context, Wiki wiki, String line, Document document, Connection db, ArrayList<Integer> wikiListTodo, ArrayList<Integer> wikiListDone, BufferedReader in) throws Exception { if (line == null) { return null; }//from ww w.ja v a2s .c o m PdfPTable pdfTable = null; int columnCount = 0; int rowCount = 0; // Keep track of the table's custom styles HashMap<Integer, String> cStyle = new HashMap<Integer, String>(); while (line != null && (line.startsWith("|") || line.startsWith("!"))) { // Build a complete line String lineToParse = line; while (!line.endsWith("|")) { line = in.readLine(); if (line == null) { // there is an error in the line to process return null; } if (line.startsWith("!")) { lineToParse += CRLF + line.substring(1); } } line = lineToParse; // Determine if the row can output boolean canOutput = true; ++rowCount; String cellType = null; Scanner sc = null; if (line.startsWith("||") && line.endsWith("||")) { cellType = "th"; sc = new Scanner(line).useDelimiter("[|][|]"); // sc = new Scanner(line.substring(2, line.length() - 2)).useDelimiter("[|][|]"); } else if (line.startsWith("|")) { cellType = "td"; sc = new Scanner(line.substring(1, line.length() - 1)).useDelimiter("\\|(?=[^\\]]*(?:\\[|$))"); } if (sc != null) { if (rowCount == 1) { // Count the columns, get the specified widths too... while (sc.hasNext()) { ++columnCount; sc.next(); } // Reset the scanner now that the columns have been counted if (line.startsWith("||") && line.endsWith("||")) { sc = new Scanner(line).useDelimiter("[|][|]"); } else if (line.startsWith("|")) { sc = new Scanner(line.substring(1, line.length() - 1)) .useDelimiter("\\|(?=[^\\]]*(?:\\[|$))"); } // Start the table pdfTable = new PdfPTable(columnCount); //pdfTable.setWidthPercentage(100); pdfTable.setHorizontalAlignment(Element.ALIGN_LEFT); pdfTable.setSpacingBefore(10); pdfTable.setWidthPercentage(100); pdfTable.setKeepTogether(true); } // Determine the column span int colSpan = 1; // Determine the cell being output int cellCount = 0; while (sc.hasNext()) { String cellData = sc.next(); if (cellData.length() == 0) { ++colSpan; continue; } // Track the cell count being output ++cellCount; if (rowCount == 1) { // Parse and validate the style input LOG.debug("Checking style value: " + cellData); if (cellData.startsWith("{") && cellData.endsWith("}")) { String[] style = cellData.substring(1, cellData.length() - 1).split(":"); String attribute = style[0].trim(); String value = style[1].trim(); // Determine the width of each column and store it if ("width".equals(attribute)) { // Validate the width style if (StringUtils.hasAllowedOnly("0123456789%.", value)) { cStyle.put(cellCount, attribute + ": " + value + ";"); } } else { LOG.debug("Unsupported style: " + cellData); } canOutput = false; } } // Output the header if (canOutput) { PdfPCell cell = new PdfPCell(); cell.setPadding(10); cell.setBorderColor(new Color(100, 100, 100)); if ("th".equals(cellType)) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); } if (colSpan > 1) { cell.setColspan(colSpan); } // Output the data if (" ".equals(cellData) || "".equals(cellData)) { // Put a blank space in blank cells for output consistency cell.addElement(new Chunk(" ")); LOG.debug(" OUTPUTTING A BLANK"); } else { // Output the cell as a complete wiki float cellWidth = (100.0f / columnCount); parseContent(context, wiki, cellData, document, cell, db, wikiListTodo, wikiListDone, cellWidth); LOG.debug(" OUTPUTTING CONTENT"); } pdfTable.addCell(cell); } } } // read another line to see if it's part of the table line = in.readLine(); } if (pdfTable != null) { LOG.debug("document.add(pdfTable)"); document.add(pdfTable); // document.add(Chunk.NEWLINE); } return line; }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
protected static String parseForm(WikiPDFContext context, Connection db, BufferedReader in, String line, Document document, PdfPCell cell) throws Exception { if (line == null) { return line; }/* ww w . j a va 2s .c o m*/ CustomForm form = WikiToHTMLUtils.retrieveForm(in, line); LOG.debug("parseForm"); for (CustomFormGroup group : form) { LOG.debug(" group..."); // Start the table PdfPTable pdfTable = new PdfPTable(2); pdfTable.setHorizontalAlignment(Element.ALIGN_LEFT); pdfTable.setSpacingBefore(10); // pdfTable.setWidthPercentage(100); pdfTable.setKeepTogether(true); if (group.getDisplay() && StringUtils.hasText(group.getName())) { // output the 1st row with a colspan of 2 if (StringUtils.hasText(group.getName())) { Paragraph groupParagraph = new Paragraph(group.getName()); PdfPCell groupCell = new PdfPCell(groupParagraph); groupCell.setHorizontalAlignment(Element.ALIGN_CENTER); groupCell.setColspan(2); groupCell.setPadding(20); groupCell.setBorderColor(new Color(100, 100, 100)); groupCell.setBackgroundColor(new Color(200, 200, 200)); groupCell.setNoWrap(true); pdfTable.addCell(groupCell); } } for (CustomFormField field : group) { LOG.debug(" field..."); if (field.hasValue()) { // output the row (2 columns: label, value) Paragraph fieldLabelParagraph = new Paragraph(field.getLabel()); PdfPCell fieldLabelCell = new PdfPCell(fieldLabelParagraph); fieldLabelCell.setPadding(20); fieldLabelCell.setBorderColor(new Color(100, 100, 100)); // fieldLabelCell.setNoWrap(true); pdfTable.addCell(fieldLabelCell); Paragraph fieldValueParagraph = new Paragraph(getFieldValue(context, field)); PdfPCell fieldValueCell = new PdfPCell(fieldValueParagraph); fieldValueCell.setPadding(20); fieldValueCell.setBorderColor(new Color(100, 100, 100)); // fieldValueCell.setNoWrap(true); pdfTable.addCell(fieldValueCell); } } LOG.debug("document.add(pdfTable)"); document.add(pdfTable); } return null; }
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);/*from w ww. j ava 2s . 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);/*from w w w. j a v a 2 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("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 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("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);// ww w .ja v a2s .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("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);//www .jav a 2 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); }