List of usage examples for com.itextpdf.text.pdf PdfPTable PdfPTable
public PdfPTable(final PdfPTable table)
PdfPTable
. From source file:com.dandymadeproductions.ajqvue.io.PDFDataTableDumpThread.java
License:Open Source License
public void run() { // Class Method Instances String title;//from w ww .ja v a 2s . c o m Font titleFont; Font rowHeaderFont; Font tableDataFont; BaseFont rowHeaderBaseFont; PdfPTable pdfTable; PdfPCell titleCell; PdfPCell rowHeaderCell; PdfPCell bodyCell; Document pdfDocument; PdfWriter pdfWriter; ByteArrayOutputStream byteArrayOutputStream; int columnCount, rowNumber; int[] columnWidths; int totalWidth; Rectangle pageSize; ProgressBar dumpProgressBar; HashMap<String, String> summaryListTableNameTypes; DataExportProperties pdfDataExportOptions; String currentTableFieldName; String currentType, currentString; // Setup columnCount = summaryListTable.getColumnCount(); rowNumber = summaryListTable.getRowCount(); columnWidths = new int[columnCount]; pdfTable = new PdfPTable(columnCount); pdfTable.setWidthPercentage(100); pdfTable.getDefaultCell().setPaddingBottom(4); pdfTable.getDefaultCell().setBorderWidth(1); summaryListTableNameTypes = new HashMap<String, String>(); pdfDataExportOptions = DBTablesPanel.getDataExportProperties(); titleFont = new Font(pdfDataExportOptions.getFont()); titleFont.setStyle(Font.BOLD); titleFont.setSize((float) pdfDataExportOptions.getTitleFontSize()); titleFont.setColor(new BaseColor(pdfDataExportOptions.getTitleColor().getRGB())); rowHeaderFont = new Font(pdfDataExportOptions.getFont()); rowHeaderFont.setStyle(Font.BOLD); rowHeaderFont.setSize((float) pdfDataExportOptions.getHeaderFontSize()); rowHeaderFont.setColor(new BaseColor(pdfDataExportOptions.getHeaderColor().getRGB())); rowHeaderBaseFont = rowHeaderFont.getCalculatedBaseFont(false); tableDataFont = pdfDataExportOptions.getFont(); // Constructing progress bar. dumpProgressBar = new ProgressBar(exportedTable + " Dump"); dumpProgressBar.setTaskLength(rowNumber); dumpProgressBar.pack(); dumpProgressBar.center(); dumpProgressBar.setVisible(true); // Create a Title if Optioned. title = pdfDataExportOptions.getTitle(); if (!title.equals("")) { if (title.equals("EXPORTED TABLE")) title = exportedTable; titleCell = new PdfPCell(new Phrase(title, titleFont)); titleCell.setBorder(0); titleCell.setPadding(10); titleCell.setColspan(summaryListTable.getColumnCount()); titleCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); pdfTable.addCell(titleCell); pdfTable.setHeaderRows(2); } else pdfTable.setHeaderRows(1); // Create Row Header. for (int i = 0; i < columnCount; i++) { currentTableFieldName = summaryListTable.getColumnName(i); rowHeaderCell = new PdfPCell(new Phrase(currentTableFieldName, rowHeaderFont)); rowHeaderCell.setBorderWidth(pdfDataExportOptions.getHeaderBorderSize()); rowHeaderCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); rowHeaderCell.setBorderColor(new BaseColor(pdfDataExportOptions.getHeaderBorderColor().getRGB())); pdfTable.addCell(rowHeaderCell); columnWidths[i] = Math.min(50000, Math.max(columnWidths[i], rowHeaderBaseFont.getWidth(currentTableFieldName + " "))); if (tableColumnTypeNameHashMap != null) summaryListTableNameTypes.put(Integer.toString(i), tableColumnTypeNameHashMap.get(currentTableFieldName)); else summaryListTableNameTypes.put(Integer.toString(i), "String"); } // Create the Body of Data. int i = 0; while ((i < rowNumber) && !dumpProgressBar.isCanceled()) { dumpProgressBar.setCurrentValue(i); // Collecting rows of data & formatting date & timestamps // as needed according to the Export Properties. if (summaryListTable.getValueAt(i, 0) != null) { for (int j = 0; j < summaryListTable.getColumnCount(); j++) { currentString = summaryListTable.getValueAt(i, j) + ""; currentString = currentString.replaceAll("\n", ""); currentString = currentString.replaceAll("\r", ""); currentType = summaryListTableNameTypes.get(Integer.toString(j)); // Format Date & Timestamp Fields as Needed. if ((currentType != null) && (currentType.equals("DATE") || currentType.equals("DATETIME") || currentType.indexOf("TIMESTAMP") != -1)) { if (!currentString.toLowerCase(Locale.ENGLISH).equals("null")) { int firstSpace; String time; // Dates fall through DateTime and Timestamps try // to get the time separated before formatting // the date. if (currentString.indexOf(" ") != -1) { firstSpace = currentString.indexOf(" "); time = currentString.substring(firstSpace); currentString = currentString.substring(0, firstSpace); } else time = ""; currentString = Utils.convertViewDateString_To_DBDateString(currentString, DBTablesPanel.getGeneralDBProperties().getViewDateFormat()); currentString = Utils.convertDBDateString_To_ViewDateString(currentString, pdfDataExportOptions.getPDFDateFormat()) + time; } } bodyCell = new PdfPCell(new Phrase(currentString, tableDataFont)); bodyCell.setPaddingBottom(4); if (currentType != null) { // Set Numeric Fields Alignment. if (currentType.indexOf("BIT") != -1 || currentType.indexOf("BOOL") != -1 || currentType.indexOf("NUM") != -1 || currentType.indexOf("INT") != -1 || currentType.indexOf("FLOAT") != -1 || currentType.indexOf("DOUBLE") != -1 || currentType.equals("REAL") || currentType.equals("DECIMAL") || currentType.indexOf("COUNTER") != -1 || currentType.equals("BYTE") || currentType.equals("CURRENCY")) { bodyCell.setHorizontalAlignment(pdfDataExportOptions.getNumberAlignment()); bodyCell.setPaddingRight(4); } // Set Date/Time Field Alignment. if (currentType.indexOf("DATE") != -1 || currentType.indexOf("TIME") != -1 || currentType.indexOf("YEAR") != -1) bodyCell.setHorizontalAlignment(pdfDataExportOptions.getDateAlignment()); } pdfTable.addCell(bodyCell); columnWidths[j] = Math.min(50000, Math.max(columnWidths[j], BASE_FONT.getWidth(currentString + " "))); } } i++; } dumpProgressBar.dispose(); // Check to see if any data was in the summary // table to even be saved. if (pdfTable.size() <= pdfTable.getHeaderRows()) return; // Create a document of the PDF formatted data // to be saved to the given output file. try { // Sizing & Layout totalWidth = 0; for (int width : columnWidths) totalWidth += width; if (pdfDataExportOptions.getPageLayout() == PDFExportPreferencesPanel.LAYOUT_PORTRAIT) pageSize = PageSize.A4; else { pageSize = PageSize.A4.rotate(); pageSize.setRight(pageSize.getRight() * Math.max(1f, totalWidth / 53000f)); pageSize.setTop(pageSize.getTop() * Math.max(1f, totalWidth / 53000f)); } pdfTable.setWidths(columnWidths); // Document pdfDocument = new Document(pageSize); byteArrayOutputStream = new ByteArrayOutputStream(); pdfWriter = PdfWriter.getInstance(pdfDocument, byteArrayOutputStream); pdfDocument.open(); pdfTemplate = pdfWriter.getDirectContent().createTemplate(100, 100); pdfTemplate.setBoundingBox(new com.itextpdf.text.Rectangle(-20, -20, 100, 100)); pdfWriter.setPageEvent(this); pdfDocument.add(pdfTable); pdfDocument.close(); // Outputting WriteDataFile.mainWriteDataString(fileName, byteArrayOutputStream.toByteArray(), false); } catch (DocumentException de) { if (Ajqvue.getDebug()) { System.out.println("Failed to Create Document Needed to Output Data. \n" + de.toString()); } } }
From source file:com.dandymadeproductions.myjsqlview.io.PDFDataTableDumpThread.java
License:Open Source License
public void run() { // Class Method Instances String title;/*from w w w .jav a 2 s .c o m*/ PdfPTable pdfTable; PdfPCell titleCell, rowHeaderCell, bodyCell; Document pdfDocument; PdfWriter pdfWriter; ByteArrayOutputStream byteArrayOutputStream; int columnCount, rowNumber; int[] columnWidths; int totalWidth; Rectangle pageSize; MyJSQLView_ProgressBar dumpProgressBar; HashMap<String, String> summaryListTableNameTypes; String currentTableFieldName; String currentType, currentString; // Setup columnCount = summaryListTable.getColumnCount(); rowNumber = summaryListTable.getRowCount(); columnWidths = new int[columnCount]; pdfTable = new PdfPTable(columnCount); pdfTable.setWidthPercentage(100); pdfTable.getDefaultCell().setPaddingBottom(4); pdfTable.getDefaultCell().setBorderWidth(1); summaryListTableNameTypes = new HashMap<String, String>(); pdfDataExportOptions = DBTablesPanel.getDataExportProperties(); titleFont = new Font(pdfDataExportOptions.getFont()); titleFont.setStyle(Font.BOLD); titleFont.setSize((float) pdfDataExportOptions.getTitleFontSize()); titleFont.setColor(new BaseColor(pdfDataExportOptions.getTitleColor().getRGB())); rowHeaderFont = new Font(pdfDataExportOptions.getFont()); rowHeaderFont.setStyle(Font.BOLD); rowHeaderFont.setSize((float) pdfDataExportOptions.getHeaderFontSize()); rowHeaderFont.setColor(new BaseColor(pdfDataExportOptions.getHeaderColor().getRGB())); rowHeaderBaseFont = rowHeaderFont.getCalculatedBaseFont(false); tableDataFont = pdfDataExportOptions.getFont(); // Constructing progress bar. rowNumber = summaryListTable.getRowCount(); dumpProgressBar = new MyJSQLView_ProgressBar(exportedTable + " Dump"); dumpProgressBar.setTaskLength(rowNumber); dumpProgressBar.pack(); dumpProgressBar.center(); dumpProgressBar.setVisible(true); // Create a Title if Optioned. title = pdfDataExportOptions.getTitle(); if (!title.equals("")) { if (title.equals("EXPORTED TABLE")) title = exportedTable; titleCell = new PdfPCell(new Phrase(title, titleFont)); titleCell.setBorder(0); titleCell.setPadding(10); titleCell.setColspan(summaryListTable.getColumnCount()); titleCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); pdfTable.addCell(titleCell); pdfTable.setHeaderRows(2); } else pdfTable.setHeaderRows(1); // Create Row Header. for (int i = 0; i < columnCount; i++) { currentTableFieldName = summaryListTable.getColumnName(i); rowHeaderCell = new PdfPCell(new Phrase(currentTableFieldName, rowHeaderFont)); rowHeaderCell.setBorderWidth(pdfDataExportOptions.getHeaderBorderSize()); rowHeaderCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); rowHeaderCell.setBorderColor(new BaseColor(pdfDataExportOptions.getHeaderBorderColor().getRGB())); pdfTable.addCell(rowHeaderCell); columnWidths[i] = Math.min(50000, Math.max(columnWidths[i], rowHeaderBaseFont.getWidth(currentTableFieldName + " "))); if (tableColumnTypeHashMap != null) summaryListTableNameTypes.put(Integer.toString(i), tableColumnTypeHashMap.get(currentTableFieldName)); else summaryListTableNameTypes.put(Integer.toString(i), "String"); } // Create the Body of Data. int i = 0; while ((i < rowNumber) && !dumpProgressBar.isCanceled()) { dumpProgressBar.setCurrentValue(i); // Collecting rows of data & formatting date & timestamps // as needed according to the Export Properties. if (summaryListTable.getValueAt(i, 0) != null) { for (int j = 0; j < summaryListTable.getColumnCount(); j++) { currentString = summaryListTable.getValueAt(i, j) + ""; currentString = currentString.replaceAll("\n", ""); currentString = currentString.replaceAll("\r", ""); currentType = summaryListTableNameTypes.get(Integer.toString(j)); // Format Date & Timestamp Fields as Needed. if ((currentType != null) && (currentType.equals("DATE") || currentType.equals("DATETIME") || currentType.indexOf("TIMESTAMP") != -1)) { if (!currentString.toLowerCase().equals("null")) { int firstSpace; String time; // Dates fall through DateTime and Timestamps try // to get the time separated before formatting // the date. if (currentString.indexOf(" ") != -1) { firstSpace = currentString.indexOf(" "); time = currentString.substring(firstSpace); currentString = currentString.substring(0, firstSpace); } else time = ""; currentString = MyJSQLView_Utils.convertViewDateString_To_DBDateString(currentString, DBTablesPanel.getGeneralDBProperties().getViewDateFormat()); currentString = MyJSQLView_Utils.convertDBDateString_To_ViewDateString(currentString, pdfDataExportOptions.getPDFDateFormat()) + time; } } bodyCell = new PdfPCell(new Phrase(currentString, tableDataFont)); bodyCell.setPaddingBottom(4); if (currentType != null) { // Set Numeric Fields Alignment. if (currentType.indexOf("BIT") != -1 || currentType.indexOf("BOOL") != -1 || currentType.indexOf("NUM") != -1 || currentType.indexOf("INT") != -1 || currentType.indexOf("FLOAT") != -1 || currentType.indexOf("DOUBLE") != -1 || currentType.equals("REAL") || currentType.equals("DECIMAL") || currentType.indexOf("COUNTER") != -1 || currentType.equals("BYTE") || currentType.equals("CURRENCY")) { bodyCell.setHorizontalAlignment(pdfDataExportOptions.getNumberAlignment()); bodyCell.setPaddingRight(4); } // Set Date/Time Field Alignment. if (currentType.indexOf("DATE") != -1 || currentType.indexOf("TIME") != -1 || currentType.indexOf("YEAR") != -1) bodyCell.setHorizontalAlignment(pdfDataExportOptions.getDateAlignment()); } pdfTable.addCell(bodyCell); columnWidths[j] = Math.min(50000, Math.max(columnWidths[j], BASE_FONT.getWidth(currentString + " "))); } } i++; } dumpProgressBar.dispose(); // Check to see if any data was in the summary // table to even be saved. if (pdfTable.size() <= pdfTable.getHeaderRows()) return; // Create a document of the PDF formatted data // to be saved to the given output file. try { // Sizing & Layout totalWidth = 0; for (int width : columnWidths) totalWidth += width; if (pdfDataExportOptions.getPageLayout() == PDFExportPreferencesPanel.LAYOUT_PORTRAIT) pageSize = PageSize.A4; else { pageSize = PageSize.A4.rotate(); pageSize.setRight(pageSize.getRight() * Math.max(1f, totalWidth / 53000f)); pageSize.setTop(pageSize.getTop() * Math.max(1f, totalWidth / 53000f)); } pdfTable.setWidths(columnWidths); // Document pdfDocument = new Document(pageSize); byteArrayOutputStream = new ByteArrayOutputStream(); pdfWriter = PdfWriter.getInstance(pdfDocument, byteArrayOutputStream); pdfDocument.open(); pdfTemplate = pdfWriter.getDirectContent().createTemplate(100, 100); pdfTemplate.setBoundingBox(new com.itextpdf.text.Rectangle(-20, -20, 100, 100)); pdfWriter.setPageEvent(this); pdfDocument.add(pdfTable); pdfDocument.close(); // Outputting WriteDataFile.mainWriteDataString(fileName, byteArrayOutputStream.toByteArray(), false); } catch (DocumentException de) { if (MyJSQLView.getDebug()) { System.out.println("Failed to Create Document Needed to Output Data. \n" + de.toString()); } } }
From source file:com.deadormi.servlet.CreaPdfServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w ww . j a v a 2s .c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = request.getQueryString(); Integer gruppo_id = Integer.parseInt(url.substring(url.indexOf("=") + 1, url.length())); List<Utente> iscritti = null; List<Post> posts = null; Gruppo gruppo = null; Utente utente = null; String imageUrl = null; String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); try { iscritti = UtenteController.getUserByGroupId(request, gruppo_id); gruppo = GruppoController.getGruppoById(request, gruppo_id); } catch (SQLException ex) { log.error(ex); } // step 1: creation of a document-object Document document = new Document(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); String incipit = "Report del " + CurrentDate.getCurrentDate() + "\n"; Paragraph pIncipit = new Paragraph(incipit, FontFactory.getFont(FontFactory.HELVETICA, 14, BaseColor.BLACK)); pIncipit.setAlignment(Element.ALIGN_CENTER); pIncipit.setSpacingAfter(10); document.add(pIncipit); String title = "Gruppo " + gruppo.getNome(); Paragraph pTitle = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 18, BaseColor.BLUE)); pTitle.setAlignment(Element.ALIGN_CENTER); pTitle.setSpacingAfter(40); document.add(pTitle); PdfPCell labelNome = new PdfPCell(new Paragraph("Nome utente")); PdfPCell labelNumPost = new PdfPCell(new Paragraph("Num. post")); PdfPCell labelData = new PdfPCell(new Paragraph("Data ultimo post")); labelNome.setBorder(Rectangle.NO_BORDER); labelNumPost.setBorder(Rectangle.NO_BORDER); labelData.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < iscritti.size(); i++) { utente = iscritti.get(i); try { posts = PostController.getPostByGruppoIdAndUserId(request, gruppo_id, utente.getId_utente()); } catch (SQLException ex) { Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex); } if (utente.getNome_avatar() != null) { imageUrl = baseUrl + request.getContextPath() + AVATAR_RESOURCE_PATH + "/" + utente.getId_utente() + "_" + utente.getNome_avatar(); ; } else { imageUrl = baseUrl + request.getContextPath() + "/res/images/user_avatar.png"; } Image image = Image.getInstance(new URL(imageUrl)); image.scaleToFit(50, 50); PdfPTable table = new PdfPTable(3); PdfPCell cellAvatar = new PdfPCell(image); cellAvatar.setHorizontalAlignment(Element.ALIGN_CENTER); cellAvatar.setBorder(Rectangle.NO_BORDER); cellAvatar.setRowspan(3); PdfPCell cellNome = new PdfPCell(new Paragraph(utente.getUsername() + "")); cellNome.setBorder(Rectangle.NO_BORDER); PdfPCell cellNumPost = new PdfPCell(new Paragraph(posts.size() + "")); cellNumPost.setBorder(Rectangle.NO_BORDER); //L'ultimo sempre il piu recente siccome la query ORDER BY data_creazione PdfPCell cellData; if (posts.size() != 0) { cellData = new PdfPCell(new Paragraph(posts.get(posts.size() - 1).getData_creazione())); } else { cellData = new PdfPCell(new Paragraph("N/A")); } cellData.setBorder(Rectangle.NO_BORDER); PdfPCell cellVoidBottom = new PdfPCell(new Paragraph(" ")); cellVoidBottom.setBorder(Rectangle.BOTTOM); cellVoidBottom.setPaddingBottom(10); cellVoidBottom.setColspan(3); PdfPCell cellVoidTop = new PdfPCell(new Paragraph(" ")); cellVoidTop.setBorder(Rectangle.NO_BORDER); cellVoidTop.setPaddingTop(10); cellVoidTop.setColspan(3); table.addCell(cellVoidTop); table.addCell(cellAvatar); table.addCell(labelNome); table.addCell(cellNome); table.addCell(labelNumPost); table.addCell(cellNumPost); table.addCell(labelData); table.addCell(cellData); table.addCell(cellVoidBottom); document.add(table); } document.close(); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "inline; filename=ahahah.pdf"); OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (DocumentException ex) { Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.debashubham.dumpy.ChainageCalcActivity.java
private void createTable(Section subCatPart) throws DocumentException { PdfPTable entry_table = new PdfPTable(10); entry_table.setWidthPercentage(100); // entry_table.setWidths(new float[]{0.25f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,1.0f}); PdfPCell id = new PdfPCell(new Phrase("Station Point")); id.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell left_row = new PdfPCell(new Phrase("CH. Left(m)")); left_row.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell center_row = new PdfPCell(new Phrase("CH. Center(m)")); center_row.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell right_row = new PdfPCell(new Phrase("CH. Right(m)")); right_row.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell bs = new PdfPCell(new Phrase("BS(m)")); bs.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell is = new PdfPCell(new Phrase("IS(m)")); is.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell fs = new PdfPCell(new Phrase("FS(m)")); fs.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell hi = new PdfPCell(new Phrase("HI(m)")); hi.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rl = new PdfPCell(new Phrase("RL(m)")); rl.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell remarks = new PdfPCell(new Phrase("REMARKS")); remarks.setHorizontalAlignment(Element.ALIGN_CENTER); entry_table.addCell(id);/*from w w w .ja v a2 s . c om*/ entry_table.addCell(left_row); entry_table.addCell(center_row); entry_table.addCell(right_row); entry_table.addCell(bs); entry_table.addCell(is); entry_table.addCell(fs); entry_table.addCell(hi); entry_table.addCell(rl); entry_table.addCell(remarks); entry_table.setHeaderRows(1); int largest = rl_list.size(); Log.e("Total RL:", String.valueOf(largest)); double total_bs = 0, total_fs = 0, first_rl = 0, last_rl = 0; for (int i = 1; i <= largest; i++) { entry_table.addCell(String.valueOf(i)); if (i == 1) first_rl = rl_list.get(i); if (i == largest) last_rl = rl_list.get(i); if (left.containsKey(i)) { entry_table.addCell(String.valueOf(left.get(i))); entry_table.addCell(""); entry_table.addCell(""); } else if (center.containsKey(i)) { entry_table.addCell(""); entry_table.addCell(String.valueOf(center.get(i))); entry_table.addCell(""); } else if (right.containsKey(i)) { entry_table.addCell(""); entry_table.addCell(""); entry_table.addCell(String.valueOf(right.get(i))); } else { entry_table.addCell(""); entry_table.addCell(""); entry_table.addCell(""); } if (bs_list.containsKey(i)) { entry_table.addCell(String.valueOf(bs_list.get(i))); total_bs += bs_list.get(i); Log.e("TABLE:", "BS"); } else { entry_table.addCell(""); Log.e("TABLE:", "BS not entered"); } if (is_list.containsKey(i)) { entry_table.addCell(String.valueOf(is_list.get(i))); Log.e("TABLE:", "IS"); } else { entry_table.addCell(""); Log.e("TABLE:", "IS not entered"); } if (fs_list.containsKey(i)) { entry_table.addCell(String.valueOf(fs_list.get(i))); total_fs += fs_list.get(i); Log.e("TABLE:", "FS"); } else { entry_table.addCell(""); Log.e("TABLE:", "FS not entered"); } if (hi_list.containsKey(i)) { entry_table.addCell(String.valueOf(hi_list.get(i))); Log.e("TABLE:", "HI"); } else { entry_table.addCell(""); Log.e("TABLE:", "HI not entered"); } if (rl_list.containsKey(i)) { entry_table.addCell(String.valueOf(rl_list.get(i))); Log.e("TABLE:", "RL"); } else { entry_table.addCell(""); Log.e("TABLE:", "RL not entered"); } if (remarks_list.containsKey(i)) { entry_table.addCell(String.valueOf(remarks_list.get(i))); Log.e("TABLE:", "REMARKS"); } else { entry_table.addCell(""); Log.e("TABLE:", "REMARKS not entered"); } } subCatPart.add(entry_table); Log.e("Total BS:", String.valueOf(total_bs)); Log.e("Total FS:", String.valueOf(total_fs)); Log.e("First RL:", String.valueOf(first_rl)); Log.e("Last RL:", String.valueOf(last_rl)); Paragraph check_para = new Paragraph("Arithmetic Check:", subFont); addEmptyLine(check_para, 2); check_para.add("Summation(BS) - Summation(FS) = Last RL - First RL"); addEmptyLine(check_para, 1); double bsfs_diff = Math.round((total_bs - total_fs) * 1000.0) / 1000.0; double rl_diff = Math.round((last_rl - first_rl) * 1000.0) / 1000.0; boolean checktrue = (bsfs_diff) == (rl_diff) ? true : false; check_para.add(String.valueOf(bsfs_diff) + " = " + String.valueOf(rl_diff)); addEmptyLine(check_para, 1); if (checktrue) { check_para.setSpacingBefore(20); check_para.add("OK"); } else { check_para.setSpacingBefore(20); check_para.add("Check Fail!"); } addEmptyLine(check_para, 1); check_para.add("_______________________________________________________"); subCatPart.add(check_para); Paragraph legend_para = new Paragraph("LEGEND:", subFont); addEmptyLine(legend_para, 1); legend_para.add("BS : Back Sight"); addEmptyLine(legend_para, 1); legend_para.add("IS : Intermediate Sight"); addEmptyLine(legend_para, 1); legend_para.add("FS : Fore Sight"); addEmptyLine(legend_para, 1); legend_para.add("HI : Height of Instrument"); addEmptyLine(legend_para, 1); legend_para.add("RL : Reduced Level"); addEmptyLine(legend_para, 1); legend_para.add("CH. : Chainage"); subCatPart.add(legend_para); }
From source file:com.debashubham.dumpy.SimpleCalcActivity.java
private void createTable(Section subCatPart) throws BadElementException { PdfPTable entry_table = new PdfPTable(7); entry_table.setWidthPercentage(100); PdfPCell id = new PdfPCell(new Phrase("Station Point")); id.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell bs = new PdfPCell(new Phrase("BS")); bs.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell is = new PdfPCell(new Phrase("IS")); is.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell fs = new PdfPCell(new Phrase("FS")); fs.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell hi = new PdfPCell(new Phrase("HI")); hi.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rl = new PdfPCell(new Phrase("RL")); rl.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell remarks = new PdfPCell(new Phrase("REMARKS")); remarks.setHorizontalAlignment(Element.ALIGN_CENTER); entry_table.addCell(id);//from w ww. ja v a2 s .c o m entry_table.addCell(bs); entry_table.addCell(is); entry_table.addCell(fs); entry_table.addCell(hi); entry_table.addCell(rl); entry_table.addCell(remarks); entry_table.setHeaderRows(1); int largest = rl_list.size(); Log.e("Total RL:", String.valueOf(largest)); double total_bs = 0, total_fs = 0, first_rl = 0, last_rl = 0; for (int i = 1; i <= largest; i++) { entry_table.addCell(String.valueOf(i)); if (i == 1) first_rl = rl_list.get(i); if (i == largest) last_rl = rl_list.get(i); if (bs_list.containsKey(i)) { entry_table.addCell(String.valueOf(bs_list.get(i))); total_bs += bs_list.get(i); Log.e("TABLE:", "BS"); } else { entry_table.addCell(""); Log.e("TABLE:", "BS not entered"); } if (is_list.containsKey(i)) { entry_table.addCell(String.valueOf(is_list.get(i))); Log.e("TABLE:", "IS"); } else { entry_table.addCell(""); Log.e("TABLE:", "IS not entered"); } if (fs_list.containsKey(i)) { entry_table.addCell(String.valueOf(fs_list.get(i))); total_fs += fs_list.get(i); Log.e("TABLE:", "FS"); } else { entry_table.addCell(""); Log.e("TABLE:", "FS not entered"); } if (hi_list.containsKey(i)) { entry_table.addCell(String.valueOf(hi_list.get(i))); Log.e("TABLE:", "HI"); } else { entry_table.addCell(""); Log.e("TABLE:", "HI not entered"); } if (rl_list.containsKey(i)) { entry_table.addCell(String.valueOf(rl_list.get(i))); Log.e("TABLE:", "RL"); } else { entry_table.addCell(""); Log.e("TABLE:", "RL not entered"); } if (remarks_list.containsKey(i)) { entry_table.addCell(String.valueOf(remarks_list.get(i))); Log.e("TABLE:", "REMARKS"); } else { entry_table.addCell(""); Log.e("TABLE:", "REMARKS not entered"); } } subCatPart.add(entry_table); Log.e("Total BS:", String.valueOf(total_bs)); Log.e("Total FS:", String.valueOf(total_fs)); Log.e("First RL:", String.valueOf(first_rl)); Log.e("Last RL:", String.valueOf(last_rl)); Paragraph check_para = new Paragraph("Arithmetic Check:", subFont); addEmptyLine(check_para, 2); check_para.add("Summation(BS) - Summation(FS) = Last RL - First RL"); addEmptyLine(check_para, 1); double bsfs_diff = Math.round((total_bs - total_fs) * 1000.0) / 1000.0; double rl_diff = Math.round((last_rl - first_rl) * 1000.0) / 1000.0; boolean checktrue = (bsfs_diff) == (rl_diff) ? true : false; check_para.add(String.valueOf(bsfs_diff) + " = " + String.valueOf(rl_diff)); addEmptyLine(check_para, 1); if (checktrue) { check_para.setSpacingBefore(20); check_para.add("OK"); } else { check_para.setSpacingBefore(20); check_para.add("Check Fail!"); } addEmptyLine(check_para, 1); check_para.add("_______________________________________________________"); subCatPart.add(check_para); Paragraph legend_para = new Paragraph("LEGEND:", subFont); addEmptyLine(legend_para, 2); legend_para.add("BS : Back Sight"); addEmptyLine(legend_para, 1); legend_para.add("IS : Intermediate Sight"); addEmptyLine(legend_para, 1); legend_para.add("FS : Fore Sight"); addEmptyLine(legend_para, 1); legend_para.add("HI : Height of Instrument"); addEmptyLine(legend_para, 1); legend_para.add("RL : Reduced Level"); subCatPart.add(legend_para); }
From source file:com.devox.GUI.PDF.CrearReporteApto.java
@Override public PdfPTable configurarInformacion() { PdfPTable table = new PdfPTable(2); PdfPCell cell;/*from www . jav a 2 s . co m*/ cell = new PdfPCell(getPhraseFromChunks("FACTURA ", factura)); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("FECHA FACTURA", "")); cell.setBorder(PdfPCell.NO_BORDER); cell.setRowspan(2); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("FOLIO CLIENTE ", folioCliente)); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("CLIENTE ", clienteSucursal)); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("MOTIVO ", motivo)); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); table.setTotalWidth(400); return table; }
From source file:com.devox.GUI.PDF.CrearReporteApto.java
@Override public PdfPTable crearTabla() { PdfPTable table = new PdfPTable(8); //new float[]{2.4f, 3f, 1.25f, 1.2f, 1f, 1.15f, 1.1f, 1.55f} PdfPCell cell;/*from ww w . j a v a 2 s.co m*/ cell = new PdfPCell(new Phrase("CDIGO", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorRight(GRIS_CLARO); cell.setFixedHeight(20f); table.addCell(cell); cell = new PdfPCell(new Phrase("DESCRIPCIN", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("LOTE", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("FECHA DE CADUCIDAD", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("CANTIDAD", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("DICTAMEN", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(AMARILLO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("PRECIO", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(AMARILLO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("OBSERVACIONES", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(AMARILLO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); try { table.setWidths(new float[] { 2.4f, 3f, 1.25f, 1.2f, 1f, 1.15f, 1.1f, 1.55f }); table.setWidthPercentage(100); } catch (DocumentException ex) { Log.print(ex); } return table; }
From source file:com.devox.GUI.PDF.CrearReporteDestruccion.java
@Override public PdfPTable configurarInformacion() { PdfPTable table = new PdfPTable(2); try {//from ww w.j av a2s.c o m PdfPCell cell; Phrase folio = new Phrase(); folio.add(new Chunk("FOLIO DHL ", FUENTE_FOLIO_CHICA)); folio.add(new Chunk(contenido.getFolioDHL(), FUENTE_FOLIO_CHICA_ROJA)); cell = new PdfPCell(folio); cell.setRowspan(8); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Cliente ", contenido.getNombreCliente())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Nmero de cliente ", contenido.getClaveCliente())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Folio del cliente ", contenido.getFolioCliente())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Folio Abbott ", contenido.getFolioAbbott())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Motivo de devolucin ", contenido.getMotivo().getCodigo() + " - " + contenido.getMotivo().getDescripcion())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Factura ", contenido.getFactura())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("Almacn ", contenido.getAlmacen())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell( getPhraseFromChunks("Fecha de captura ", Funciones.getOtherDate(contenido.getFechaCaptura()))); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); table.setWidthPercentage(100); table.setWidths(new int[] { 1, 3 }); } catch (DocumentException ex) { Log.print(ex); } return table; }
From source file:com.devox.GUI.PDF.CrearReporteDestruccion.java
@Override public PdfPTable crearTabla() { PdfPTable table = new PdfPTable(6); PdfPCell cell;//from ww w . j a va 2s . c o m cell = new PdfPCell(new Phrase("DESCRIPCIN", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorRight(GRIS_CLARO); cell.setFixedHeight(20f); table.addCell(cell); cell = new PdfPCell(new Phrase("LOTE", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("CDIGO", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("CANTIDAD", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("PRECIO UNITARIO", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(GRIS_CLARO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); cell = new PdfPCell(new Phrase("SUBTOTAL", FUENTE_CABECERA_TABLA_CHICA)); cell.setBackgroundColor(AMARILLO); cell.setBorderColorBottom(BaseColor.BLACK); cell.setBorderColorLeft(GRIS_CLARO); cell.setBorderColorRight(AMARILLO); cell.setBorderColorTop(AMARILLO); table.addCell(cell); try { table.setWidths(new float[] { 5f, 2f, 3f, 1.2f, 1.4f, 1.5f }); table.setWidthPercentage(98); } catch (DocumentException ex) { Log.print(ex); } return table; }
From source file:com.devox.GUI.PDF.CrearReportePorEstado.java
@Override public PdfPTable configurarInformacion() { PdfPTable table = new PdfPTable(2); PdfPCell cell;/*from w w w.ja v a 2s . c o m*/ cell = new PdfPCell(getPhraseFromChunks("DEL ", fechaInicio)); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); cell = new PdfPCell(getPhraseFromChunks("AL ", fechaFin)); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(40); table.addCell(cell); table.setWidthPercentage(100); return table; }