List of usage examples for com.itextpdf.text.pdf PdfPTable setHorizontalAlignment
public void setHorizontalAlignment(final int horizontalAlignment)
From source file:com.myapp.struts.transaction.transactionAction.java
public ActionForward generatememberreport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws SQLException, Exception { if (Constants.isSessionActive(request)) { transactionForm transactionForm = (transactionForm) form; try {//ww w . j av a2 s. co m Date utilDate = new Date(); java.sql.Date date = new java.sql.Date(utilDate.getTime()); Font bigFont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD, BaseColor.BLACK); Font bigFont_Uderline = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD | Font.UNDERLINE, BaseColor.BLACK); Font boldfont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 9, Font.BOLD); Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); //Or whatever format fits best your needs. Paragraph para1 = new Paragraph("PALKE JEWELLERS", bigFont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); para1 = new Paragraph("MEMBER ACCOUNT DETAILS", bigFont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); para1 = new Paragraph(transactionForm.getSelectedmember(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph( transactionForm.getMemberaddress() + "\n" + transactionForm.getMembercontactno(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); Groups obj = (Groups) hmGroups.get(transactionForm.getGroupid() + ""); if (obj != null) { para1 = new Paragraph("Group : " + obj.getGroupname(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Paid Amount : " + transactionForm.getTotalpaidamount(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Prize Amount : " + transactionForm.getDrawamount(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Total Amount : " + transactionForm.getTotalamount(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Status : " + transactionForm.getStatus(), boldfont); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); if (transactionForm.getStatus().equalsIgnoreCase("Settled")) { para1 = new Paragraph(transactionForm.getSettlementcomment(), boldfont); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); } String dateStr = sdf.format(date); para1 = new Paragraph("DATED:" + dateStr, font); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); // add a couple of blank lines document.add(Chunk.NEWLINE); if (transactionForm.getLstPayment() != null && transactionForm.getLstPayment().size() > 0) { PdfPTable table2 = new PdfPTable(7); float[] columnWidths = { 1.5f, 1.5f, 3f, 4f, 4f, 7f, 2f }; table2.setWidthPercentage(100); table2.setWidths(columnWidths); para1 = new Paragraph("Sl No.", font); para1.setAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Term", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Receipt No.", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Receipt Date", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Payment Mode", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Remarks", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Paid Amount", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); int x = 1; double total = 0; //Iterator it = hmPayments.entrySet().iterator(); //while (it.hasNext()) { if (hmPayments.size() > 0) { for (int i = 1; i <= obj.getNoofinstallment(); i++) { //float f = columnWidths[i]; Payment f1 = (Payment) hmPayments.get(i + ""); //} //Map.Entry pairs = (Map.Entry) it.next(); //Payment f1 = (Payment) pairs.getValue(); String term = i + ""; para1 = new Paragraph(Integer.toString(x), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); x++; para1 = new Paragraph(term, font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getPaymentid() + "", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(sdf.format(f1.getPaiddate()), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getPaymentmode() == 1 ? "Cash" : "Cheque/NEFT", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getRemarks(), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); //para1 = new Paragraph(f1.getPaidamount() + "", boldfont); para1 = new Paragraph((int) obj.getInstallmentamount() + "", boldfont); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); total = total + obj.getInstallmentamount(); if (hmPayments.size() == i) { break; } } para1 = new Paragraph("Total", boldfont); para1.setAlignment(Element.ALIGN_LEFT); cell = new PdfPCell(para1); cell.setColspan(6); table2.addCell(cell); //String numberStr = String.format("%.2f", total + ""); para1 = new Paragraph(total + "", boldfont); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); //cell.setColspan(7); table2.addCell(cell); table2.setHorizontalAlignment(Element.ALIGN_LEFT); document.add(table2); } else { para1 = new Paragraph("NO PAYMENTS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); } } else { para1 = new Paragraph("NO RECORDS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); } document.add(Chunk.NEWLINE); //document.close(); //fileInputStream = new FileInputStream(new File("C:\\reports\\PaymentReports.pdf")); document.close(); ServletOutputStream outputStream = response.getOutputStream(); baos.writeTo(outputStream); response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\""); response.setContentType("application/pdf"); outputStream.flush(); outputStream.close(); return mapping.findForward("display"); } else { para1 = new Paragraph("NO RECORDS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); document.close(); ServletOutputStream outputStream = response.getOutputStream(); baos.writeTo(outputStream); response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\""); response.setContentType("application/pdf"); outputStream.flush(); outputStream.close(); return mapping.findForward("display"); } } catch (DocumentException i) { System.out.println(i); return mapping.findForward("fail"); } catch (IOException i) { System.out.println(i); return mapping.findForward("fail"); } } else { return mapping.findForward("exp"); } }
From source file:com.pma.mpsr.export.PDFGenerator.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response)/*from www . j a v a 2 s. c o m*/ */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String mpsrID = request.getParameter("MPSR_ID"); if (null == mpsrID) return; MPSRProjectInfo basicInfo = MPSRProjectInfo.getInstance(mpsrID); MPSRExecutiveSummary exeSummary = MPSRExecutiveSummary.getInstance(mpsrID); MPSRStatusSummary statusSummary = MPSRStatusSummary.getInstance(mpsrID); MPSRFunctionPerformance funcPerform = MPSRFunctionPerformance.getInstance(mpsrID); MPSRCostPerformance costPerform = MPSRCostPerformance.getInstance(mpsrID); MPSRSchedulePerformance[] schedulePerform = MPSRSchedulePerformance.getInstance(mpsrID); MPSRSafety safety = MPSRSafety.getInstance(mpsrID); MPSRAuthorization auth = MPSRAuthorization.getInstance(mpsrID); MPSRBudget budget = MPSRBudget.getInstance(mpsrID); MPSRCostReport[] costRpt = MPSRCostReport.getInstance(mpsrID); MPSRSchedule schedule = MPSRSchedule.getInstance(mpsrID); MPSRMilestone[] milestones = MPSRMilestone.getInstance(mpsrID); MPSRLPE lpe = MPSRLPE.getInstance(mpsrID); MPSRInsidePlantDesign[] ipds = MPSRInsidePlantDesign.getInstance(mpsrID); MPSROutsidePlantDesign[] opds = MPSROutsidePlantDesign.getInstance(mpsrID); MPSRProcure procure = MPSRProcure.getInstance(mpsrID); MPSRApprovedChanges[] approvedChanges = MPSRApprovedChanges.getInstance(mpsrID); MPSRPendingChanges[] pendingChanges = MPSRPendingChanges.getInstance(mpsrID); MPSRInsidePlantConstruction[] ipcs = MPSRInsidePlantConstruction.getInstance(mpsrID); MPSROutsidePlantConstruction[] opcs = MPSROutsidePlantConstruction.getInstance(mpsrID); MPSRAppendix[] appendixs = MPSRAppendix.getInstance(mpsrID); MPSRAttachment[] attachments = MPSRAttachment.getInstance(mpsrID); // response.setContentType("application/pdf"); // response.setHeader("Content-Disposition", // "attachment; filename=\"test.pdf\""); Font fontNormal = null; Font fontCoverTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); Font fontCoverTableHeader = new Font(FontFamily.HELVETICA, 16, Font.BOLD); Font fontCoverTableContent = new Font(FontFamily.HELVETICA, 16); Font fontChapterHeader = new Font(FontFamily.HELVETICA, 18, Font.BOLD); Font fontSection1Header = new Font(FontFamily.HELVETICA, 16, Font.BOLD); Font fontSection2Header = new Font(FontFamily.HELVETICA, 14, Font.BOLD); Font fontWork = new Font(FontFamily.HELVETICA, 12, Font.UNDERLINE); Font fontTableCaption = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD); Font fontTableColumnHeader = new Font(FontFamily.HELVETICA, 12, Font.BOLD); Font fontTableColumnHeaderYellow = new Font(FontFamily.HELVETICA, 12, Font.BOLD); fontTableColumnHeaderYellow.setColor(BaseColor.YELLOW); Font fontTableRowTitle = new Font(FontFamily.HELVETICA, 12, Font.ITALIC); Font fontTableCellBold = new Font(FontFamily.HELVETICA, 12, Font.BOLD); Font fontTableNote = new Font(FontFamily.HELVETICA, 10, Font.ITALIC); Font fontImageCaption = new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD); Font fontPOTableHeader = new Font(FontFamily.HELVETICA, 10, Font.BOLD); fontPOTableHeader.setColor(BaseColor.YELLOW); Font fontPOTable = new Font(FontFamily.HELVETICA, 9); Font fontPOTableSummary = new Font(FontFamily.HELVETICA, 9, Font.BOLD); Font fontPageHeader = new Font(FontFamily.HELVETICA, 8); Font fontPageFooter = new Font(FontFamily.HELVETICA, 10); Phrase[] headerTexts = new Phrase[] { new Phrase("PMA - ELECTRIC DELIVERY", fontPageHeader), new Phrase("DELIVERY PROJECTS & CONSTRUCTION (DP&C)", fontPageHeader), new Phrase("PROJECT MONTHLY REPORT", fontPageHeader) }; Paragraph paragraph = null; PdfPTable table = null; PdfPCell cell = null; Document document = new Document(DEFAULT_PAGE_SIZE, 36, 36, 9 * 10, 36); ByteArrayOutputStream baosOrig = new ByteArrayOutputStream(); XMLWorkerHelper xmlWorker = XMLWorkerHelper.getInstance(); try { PdfWriter writer = PdfWriter.getInstance(document, baosOrig); writer.setStrictImageSequence(true); writer.setLinearPageMode(); writer.setViewerPreferences(PdfWriter.PageModeUseOutlines | PdfWriter.FitWindow); Image icon = getEmbeddedImage(getServletContext(), "/resource/image/pma.bmp"); document.open(); PdfOutline root = writer.getRootOutline(); // *******************************************************************************************// // addOutline(root, writer, MPSRUI.TREE_0); for (int i = 0; i < 2; i++) { document.add(new Paragraph(" ")); } String[] titles = { "PMA DELIVERY PROJECTS & CONSTRUCTION", "MONTHLY REPORT", basicInfo.getReportMonthYear(), basicInfo.getProjectTitle(), "PROJECT No. " + basicInfo.getProjectDefinition() }; int[] spaceingAfters = { 48, 48, 48, 24, 48 }; for (int i = 0; i < titles.length; i++) { paragraph = new Paragraph(); paragraph.setSpacingAfter(spaceingAfters[i]); paragraph.setFont(fontCoverTitle); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.add(new Chunk(titles[i])); document.add(paragraph); } addCoverImage(document, MPSRUI.getFilePath(mpsrID, basicInfo.getFileName())); document.add(new Paragraph(" ")); table = new PdfPTable(2); table.addCell(new Phrase("Client", fontCoverTableHeader)); table.addCell(new Phrase(basicInfo.getProjectManager(), fontCoverTableContent)); table.addCell(new Phrase("Location", fontCoverTableHeader)); table.addCell(new Phrase(basicInfo.getProjectDirector(), fontCoverTableContent)); document.add(table); // *******************************************************************************************// document.resetPageCount(); document.add(Chunk.NEXTPAGE); writer.setPageEvent(new MPSRPageEventHelper(icon, headerTexts, fontPageFooter)); // *******************************************************************************************// PdfOutline outline1 = addOutline(root, writer, MPSRUI.TREE_1); addSectionTitle(document, MPSRUI.TREE_1, fontChapterHeader, 0, 0, 12); PdfOutline outline2 = addOutline(outline1, writer, "1.1"); addOutline(outline2, writer, MPSRUI.TREE_1_1_1); addSectionTitle(document, MPSRUI.TREE_1_1_1, fontSection2Header, 12, 12, 0); addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_1(), fontNormal, 12, 0, 12); addOutline(outline2, writer, MPSRUI.TREE_1_1_2); addSectionTitle(document, MPSRUI.TREE_1_1_2, fontSection2Header, 12, 12, 0); addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_2(), fontNormal, 12, 0, 12); addOutline(outline2, writer, MPSRUI.TREE_1_1_3); addSectionTitle(document, MPSRUI.TREE_1_1_3, fontSection2Header, 12, 12, 0); addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_3(), fontNormal, 12, 0, 12); addOutline(outline2, writer, MPSRUI.TREE_1_1_4); addSectionTitle(document, MPSRUI.TREE_1_1_4, fontSection2Header, 12, 12, 0); addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_4(), fontNormal, 12, 0, 12); // *******************************************************************************************// // 1.2 Status Summary // *******************************************************************************************// outline2 = addOutline(outline1, writer, MPSRUI.TREE_1_2); addSectionTitle(document, MPSRUI.TREE_1_2, fontSection1Header, 6, 12, 12); paragraph = new Paragraph(); paragraph.add(basicInfo.getProjectTitle()); paragraph.setSpacingAfter(4); document.add(paragraph); table = new PdfPTable(5); table.setTotalWidth(500); table.setLockedWidth(true); table.setWidths(new int[] { 3, 1, 1, 1, 1 }); cell = new PdfPCell( new Phrase("Project #: " + basicInfo.getProjectDefinition(), fontTableColumnHeader)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); String[] headers = { "Status", "Approved (Include RnC)", "To Date", "At Completion" }; for (String header : headers) { cell = new PdfPCell(new Phrase(header, fontTableColumnHeader)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } String[][] cellValues = { { "Budget ($M)", statusSummary.getBudgetStatus(), !"".equals(statusSummary.getBudgetApproved()) ? CURRENCY_FORMATTER .format(Double.parseDouble(statusSummary.getBudgetApproved())) : "", !"".equals(statusSummary.getBudgetToDate()) ? CURRENCY_FORMATTER.format(Double.parseDouble(statusSummary.getBudgetToDate())) : "", !"".equals(statusSummary.getBudgetAtCompletion()) ? CURRENCY_FORMATTER .format(Double.parseDouble(statusSummary.getBudgetAtCompletion())) : "" }, { "Schedule - Duration (months)", statusSummary.getScheduleStatus(), statusSummary.getScheduleApproved(), statusSummary.getScheduleToDate(), statusSummary.getScheduleAtCompletion() }, { "In-Service Date", statusSummary.getInServiceDateStatus(), statusSummary.getInServiceDateApproved(), statusSummary.getInServiceDateToDate(), statusSummary.getInServiceDateAtCompletion() } }; for (int i = 0; i < cellValues.length; i++) { table.addCell(new Phrase(cellValues[i][0])); cell = new PdfPCell(new Phrase(cellValues[i][1])); cell.setBackgroundColor(getBackgroundColor(cellValues[i][1])); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); for (int j = 2; j < 5; j++) { cell = new PdfPCell(new Phrase(cellValues[i][j])); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } } document.add(table); // -------------------------------------------------------------------// paragraph = new Paragraph("Legend:"); paragraph.setSpacingAfter(4); paragraph.setIndentationLeft(25); document.add(paragraph); table = new PdfPTable(3); table.setTotalWidth(240); table.setLockedWidth(true); table.setHorizontalAlignment(Element.ALIGN_LEFT); String[] legends = { "On Target", "At Risk", "Off Target" }; for (String legend : legends) { cell = new PdfPCell(new Phrase(legend)); cell.setBackgroundColor(getBackgroundColor(legend)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setMinimumHeight(18); cell.setPadding(0); table.addCell(cell); } paragraph = new Paragraph(); paragraph.add(table); paragraph.setIndentationLeft(25); document.add(paragraph); // *******************************************************************************************// // 1.2.1 Functional Area Performance Indicators // *******************************************************************************************// addOutline(outline2, writer, MPSRUI.TREE_1_2_1); addSectionTitle(document, MPSRUI.TREE_1_2_1, fontSection2Header, 12, 12, 12); table = new PdfPTable(4); table.setTotalWidth(550); table.setLockedWidth(true); table.setWidths(new int[] { 4, 1, 1, 4 }); headers = new String[] { "Activities", "Current Status", "Trend", "Comments (main performance drives)" }; for (String header : headers) { cell = new PdfPCell(new Phrase(header, fontTableColumnHeader)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } Image imgArrowUp = getEmbeddedImage(getServletContext(), "/VAADIN/themes/MPSR/img/Arrow_Up.png"); Image imgArrowDown = getEmbeddedImage(getServletContext(), "/VAADIN/themes/MPSR/img/Arrow_Down.png"); Image imgArrowEven = getEmbeddedImage(getServletContext(), "/VAADIN/themes/MPSR/img/Arrow_Even.png"); Image[] images = { imgArrowUp, imgArrowDown, imgArrowEven }; for (Image image : images) { image.scaleToFit(12, 12); } cellValues = new String[][] { { "Project - " + basicInfo.getProjectTitle(), funcPerform.getProjectStatus(), funcPerform.getProjectTrend(), funcPerform.getProjectComment() }, { " Target Budget", funcPerform.getTargetBudgetStatus(), funcPerform.getTargetBudgetTrend(), funcPerform.getTargetBudgetComment() }, { " Safety", funcPerform.getSafetyStatus(), funcPerform.getSafetyTrend(), funcPerform.getSafetyComment() }, { " Licensing & Permitting", funcPerform.getLicensingStatus(), funcPerform.getLicensingTrend(), funcPerform.getLicensingComment() }, { " Corporate Properties", funcPerform.getCorporateStatus(), funcPerform.getCorporateTrend(), funcPerform.getCorporateComment() }, { " Inside Plant Design & Engineering", funcPerform.getIPDEStatus(), funcPerform.getIPDETrend(), funcPerform.getIPDEComment() }, { " Public Outreach", funcPerform.getOutreachStatus(), funcPerform.getOutreachTrend(), funcPerform.getOutreachComment() }, { " Procurement", funcPerform.getProcureStatus(), funcPerform.getProcureTrend(), funcPerform.getProcureComment() }, { " Construction", funcPerform.getConstructionStatus(), funcPerform.getConstructionTrend(), funcPerform.getConstructionComment() }, { " Environmental - Resource Recovery", funcPerform.getEnviromentStatus(), funcPerform.getEnviromentTrend(), funcPerform.getEnviromentComment() }, { " Salvage", funcPerform.getSalvageStatus(), funcPerform.getSalvageTrend(), funcPerform.getSalvageComment() }, { " Withdrawal", funcPerform.getWithdrawalStatus(), funcPerform.getWithdrawalTrend(), funcPerform.getWithdrawalComment() } }; for (int i = 0; i < cellValues.length; i++) { cell = new PdfPCell(new Phrase(cellValues[i][0])); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell = new PdfPCell(new Phrase(cellValues[i][1])); cell.setBackgroundColor(getBackgroundColor(cellValues[i][1])); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); if ("Up".equals(cellValues[i][2])) { cell = new PdfPCell(imgArrowUp); } else if ("Down".equals(cellValues[i][2])) { cell = new PdfPCell(imgArrowDown); } else if ("Even".equals(cellValues[i][2])) { cell = new PdfPCell(imgArrowEven); } else { cell = new PdfPCell(); } cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(cellValues[i][3])); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } document.add(table); // *******************************************************************************************// document.setPageSize(DEFAULT_PAGE_SIZE.rotate()); document.add(Chunk.NEXTPAGE); addOutline(outline2, writer, MPSRUI.TREE_1_2_2); addSectionTitle(document, MPSRUI.TREE_1_2_2, fontSection2Header, 12, 12, 12); addImage(document, MPSRUI.getFilePath(mpsrID, costPerform.getFileName())); // *******************************************************************************************// // 1.2.3 Schedule Performance // *******************************************************************************************// document.add(Chunk.NEXTPAGE); addOutline(outline2, writer, MPSRUI.TREE_1_2_3); addSectionTitle(document, MPSRUI.TREE_1_2_3, fontSection2Header, 12, 12, 12); table = new PdfPTable(9); table.setTotalWidth(750); table.setLockedWidth(true); table.setWidths(new int[] { 3, 1, 1, 1, 1, 1, 1, 1, 1 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); headers = new String[] { "WBS", "Original Duration", "Remaining Duration", "Baseline Start Date", "Baseline Finish Date", "Start Date", "Finish Date", "Total Float", "Status" }; for (String header : headers) { cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow)); cell.setBackgroundColor(BaseColor.BLUE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } for (int i = 0; i < schedulePerform.length; i++) { cell = new PdfPCell(new Phrase(schedulePerform[i].getWBS())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(Double.toString(schedulePerform[i].getOriginalDuration()))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(Double.toString(schedulePerform[i].getRemainingDuration()))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(schedulePerform[i].getPlannedStartDate())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(schedulePerform[i].getPlannedFinishDate())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(schedulePerform[i].getStartDate())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(schedulePerform[i].getFinishDate())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(schedulePerform[i].getTotalFloat())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(schedulePerform[i].getStatus())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } table.setHeaderRows(1); document.add(table); // *******************************************************************************************// // 1.3 Project Change Control // *******************************************************************************************// document.setPageSize(DEFAULT_PAGE_SIZE); document.add(Chunk.NEXTPAGE); outline2 = addOutline(outline1, writer, MPSRUI.TREE_1_3); addSectionTitle(document, MPSRUI.TREE_1_3, fontSection1Header, 6, 12, 12); addOutline(outline2, writer, MPSRUI.TREE_1_3_1); addSectionTitle(document, MPSRUI.TREE_1_3_1, fontSection2Header, 12, 12, 0); addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_3_1(), fontNormal, 12, 0, 12); addOutline(outline2, writer, MPSRUI.TREE_1_3_2); addSectionTitle(document, MPSRUI.TREE_1_3_2, fontSection2Header, 12, 12, 0); addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_3_2(), fontNormal, 12, 0, 12); // *******************************************************************************************// // 2 Safety // *******************************************************************************************// addOutline(root, writer, MPSRUI.TREE_2); addSectionTitle(document, MPSRUI.TREE_2, fontChapterHeader, 0, 24, 12); addParagraph(document, writer, xmlWorker, safety.getDesc1(), fontNormal, 12, 0, 12); paragraph = new Paragraph("Table 2.1 Project Safety Summary", fontTableCaption); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingAfter(6); document.add(paragraph); table = new PdfPTable(3); table.setTotalWidth(300); table.setLockedWidth(true); table.setWidths(new int[] { 1, 1, 1 }); table.setHorizontalAlignment(Element.ALIGN_RIGHT); cell = new PdfPCell(new Phrase("Total Work Hours", fontTableColumnHeaderYellow)); cell.setColspan(3); cell.setBackgroundColor(BaseColor.BLUE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); headers = new String[] { "Current Period", "Calendar YTD", "Project To Date" }; for (String header : headers) { cell = new PdfPCell(new Phrase(header, fontTableColumnHeader)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } cellValues = new String[][] { { INTEGER_FORMATTER.format(safety.getTotalWorkHoursCurrent()), INTEGER_FORMATTER.format(safety.getTotalWorkHoursYTD()), INTEGER_FORMATTER.format(safety.getTotalWorkHoursPTD()) } }; for (int i = 0; i < cellValues.length; i++) { cell = new PdfPCell(new Phrase(cellValues[i][0])); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(cellValues[i][1])); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(cellValues[i][2], fontTableCellBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } document.add(table); // ----------------------------------- table = new PdfPTable(4); table.setTotalWidth(500); table.setLockedWidth(true); table.setWidths(new int[] { 2, 1, 1, 1 }); table.setHorizontalAlignment(Element.ALIGN_RIGHT); cell = new PdfPCell(new Phrase("Incidents", fontTableColumnHeaderYellow)); cell.setColspan(4); cell.setBackgroundColor(BaseColor.BLUE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cellValues = new String[][] { { "OSHA Recordable", INTEGER_FORMATTER.format(safety.getOshaRecordableCurrent()), INTEGER_FORMATTER.format(safety.getOshaRecordableYTD()), INTEGER_FORMATTER.format(safety.getOshaRecordablePTD()) }, { "First Aid", INTEGER_FORMATTER.format(safety.getFirstAid1Current()), INTEGER_FORMATTER.format(safety.getFirstAid1YTD()), INTEGER_FORMATTER.format(safety.getFirstAid1PTD()) }, { "Near Miss", INTEGER_FORMATTER.format(safety.getNearMissCurrent()), INTEGER_FORMATTER.format(safety.getNearMissYTD()), INTEGER_FORMATTER.format(safety.getNearMissPTD()) }, { "First Aid", INTEGER_FORMATTER.format(safety.getFirstAid2Current()), INTEGER_FORMATTER.format(safety.getFirstAid2YTD()), INTEGER_FORMATTER.format(safety.getFirstAid2PTD()) } }; for (int i = 0; i < cellValues.length; i++) { cell = new PdfPCell(new Phrase(cellValues[i][0], fontTableRowTitle)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(cellValues[i][1])); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(cellValues[i][2])); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(cellValues[i][3], fontTableCellBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } cell = new PdfPCell(new Phrase("*Note - " + safety.getNote(), fontTableNote)); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); document.add(table); // *******************************************************************************************// // 3 Project Authorization // *******************************************************************************************// addOutline(root, writer, MPSRUI.TREE_3); addSectionTitle(document, MPSRUI.TREE_3, fontChapterHeader, 0, 24, 12); addParagraph(document, writer, xmlWorker, auth.getDesc1(), fontNormal, 12, 0, 12); table = new PdfPTable(10); table.setSpacingBefore(6); table.setTotalWidth(550); table.setLockedWidth(true); table.setWidths(new int[] { 3, 1, 1, 1, 1, 1, 1, 2, 1, 1 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); headers = new String[] { "$ Millions", "Prior", auth.getHeaderYear0(), auth.getHeaderYear1(), auth.getHeaderYear2(), auth.getHeaderYear3(), auth.getHeaderYear4(), auth.getHeaderPostYear(), "Total", "Auth" }; for (String header : headers) { cell = new PdfPCell(new Phrase(header, fontTableColumnHeader)); cell.setBackgroundColor(BaseColor.YELLOW); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } cellValues = new String[][] { { "Base", NUMBER_FORMATTER.format(auth.getBasePriorYear()), NUMBER_FORMATTER.format(auth.getBaseYear0()), NUMBER_FORMATTER.format(auth.getBaseYear1()), NUMBER_FORMATTER.format(auth.getBaseYear2()), NUMBER_FORMATTER.format(auth.getBaseYear3()), NUMBER_FORMATTER.format(auth.getBaseYear4()), NUMBER_FORMATTER.format(auth.getBasePostYear()), NUMBER_FORMATTER.format(auth.getBaseTotal()), "" }, { "Risk & Contingency", NUMBER_FORMATTER.format(auth.getRnCPriorYear()), NUMBER_FORMATTER.format(auth.getRnCYear0()), NUMBER_FORMATTER.format(auth.getRnCYear1()), NUMBER_FORMATTER.format(auth.getRnCYear2()), NUMBER_FORMATTER.format(auth.getRnCYear3()), NUMBER_FORMATTER.format(auth.getRnCYear4()), NUMBER_FORMATTER.format(auth.getRnCPostYear()), NUMBER_FORMATTER.format(auth.getRnCTotal()), "" }, { "Total Project " + auth.getTotalProjectDate(), NUMBER_FORMATTER.format(auth.getPriorTotal()), NUMBER_FORMATTER.format(auth.getYear0Total()), NUMBER_FORMATTER.format(auth.getYear1Total()), NUMBER_FORMATTER.format(auth.getYear2Total()), NUMBER_FORMATTER.format(auth.getYear3Total()), NUMBER_FORMATTER.format(auth.getYear4Total()), NUMBER_FORMATTER.format(auth.getPostTotal()), NUMBER_FORMATTER.format(auth.getTotalTotal()), "" }, { "Current Request " + auth.getReq0RequestDate(), NUMBER_FORMATTER.format(auth.getReq0PriorYear()), NUMBER_FORMATTER.format(auth.getReq0Year0()), NUMBER_FORMATTER.format(auth.getReq0Year1()), NUMBER_FORMATTER.format(auth.getReq0Year2()), NUMBER_FORMATTER.format(auth.getReq0Year3()), NUMBER_FORMATTER.format(auth.getReq0Year4()), NUMBER_FORMATTER.format(auth.getReq0PostYear()), NUMBER_FORMATTER.format(auth.getReq0Total()), NUMBER_FORMATTER.format(auth.getReq0Authorization()) }, { "Request Date " + auth.getReq1RequestDate(), NUMBER_FORMATTER.format(auth.getReq1PriorYear()), NUMBER_FORMATTER.format(auth.getReq1Year0()), NUMBER_FORMATTER.format(auth.getReq1Year1()), NUMBER_FORMATTER.format(auth.getReq1Year2()), NUMBER_FORMATTER.format(auth.getReq1Year3()), NUMBER_FORMATTER.format(auth.getReq1Year4()), NUMBER_FORMATTER.format(auth.getReq1PostYear()), NUMBER_FORMATTER.format(auth.getReq1Total()), NUMBER_FORMATTER.format(auth.getReq1Authorization()) }, { "Request Date " + auth.getReq2RequestDate(), NUMBER_FORMATTER.format(auth.getReq2PriorYear()), NUMBER_FORMATTER.format(auth.getReq2Year0()), NUMBER_FORMATTER.format(auth.getReq2Year1()), NUMBER_FORMATTER.format(auth.getReq2Year2()), NUMBER_FORMATTER.format(auth.getReq2Year3()), NUMBER_FORMATTER.format(auth.getReq2Year4()), NUMBER_FORMATTER.format(auth.getReq2PostYear()), NUMBER_FORMATTER.format(auth.getReq2Total()), NUMBER_FORMATTER.format(auth.getReq2Authorization()) }, { "Target Budget", "", "", "", "", "", "", "", auth.getTargetBudget(), "" } }; for (int i = 0; i < cellValues.length; i++) { cell = new PdfPCell(new Phrase(cellValues[i][0])); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); for (int j = 1; j < cellValues[i].length; j++) { cell = new PdfPCell(new Phrase(cellValues[i][j])); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } } document.add(table); // *******************************************************************************************// // 4 Project Budget // *******************************************************************************************// addOutline(root, writer, MPSRUI.TREE_4); addSectionTitle(document, MPSRUI.TREE_4, fontChapterHeader, 0, 24, 12); addParagraph(document, writer, xmlWorker, budget.getDesc1(), fontNormal, 12, 0, 12); table = new PdfPTable(2); table.setSpacingBefore(6); table.setTotalWidth(350); table.setLockedWidth(true); table.setWidths(new int[] { 5, 2 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); cellValues = new String[][] { { "Current Approved Budget (Base + RnC)", CURRENCY_FORMATTER.format(budget.getPMBudget()) + "M" }, { "Approved Phase Funding", CURRENCY_FORMATTER.format(budget.getPMActual()) + "M" }, { "Expended To Date", CURRENCY_FORMATTER.format(budget.getPMCommitment()) + "M" }, { "At Completion", CURRENCY_FORMATTER.format(budget.getPMAdditionalCost()) + "M" } }; for (int i = 0; i < cellValues.length; i++) { cell = new PdfPCell(new Phrase(cellValues[i][0])); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(cellValues[i][1])); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } document.add(table); // ---------------------------------------------------- // table 4.1 // ---------------------------------------------------- paragraph = new Paragraph("Table 4.1 Cost Report Summary", fontTableCaption); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingAfter(6); document.add(paragraph); table = new PdfPTable(5); table.setTotalWidth(500); table.setLockedWidth(true); table.setWidths(new int[] { 1, 1, 1, 1, 1 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); headers = new String[] { "Work Element", "Description", "Estimate", "Actual", "EAC" }; for (String header : headers) { cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow)); cell.setBackgroundColor(BaseColor.BLUE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } for (int i = 0; i < costRpt.length; i++) { cell = new PdfPCell(new Phrase(costRpt[i].getWbs())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(costRpt[i].getWbsDesc())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(formatNumberString(costRpt[i].getEstimate()))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(formatNumberString(costRpt[i].getActual()))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(formatNumberString(costRpt[i].getEAC()))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } document.add(table); // *******************************************************************************************// // 5 Project Schedule // *******************************************************************************************// outline1 = addOutline(root, writer, MPSRUI.TREE_5); addSectionTitle(document, MPSRUI.TREE_5, fontChapterHeader, 0, 24, 12); addOutline(outline1, writer, MPSRUI.TREE_5_1); addSectionTitle(document, MPSRUI.TREE_5_1, fontSection1Header, 6, 12, 12); addParagraph(document, writer, xmlWorker, schedule.getDesc_5_1(), fontNormal, 12, 0, 12); addOutline(outline1, writer, MPSRUI.TREE_5_2); addSectionTitle(document, MPSRUI.TREE_5_2, fontSection1Header, 6, 12, 12); addParagraph(document, writer, xmlWorker, schedule.getDesc_5_2(), fontNormal, 12, 0, 12); addOutline(outline1, writer, MPSRUI.TREE_5_3); addSectionTitle(document, MPSRUI.TREE_5_3, fontSection1Header, 6, 12, 12); addParagraph(document, writer, xmlWorker, schedule.getDesc_5_3(), fontNormal, 12, 0, 12); addOutline(outline1, writer, MPSRUI.TREE_5_4); addSectionTitle(document, MPSRUI.TREE_5_4, fontSection1Header, 6, 12, 12); addParagraph(document, writer, xmlWorker, schedule.getDesc_5_4(), fontNormal, 12, 0, 12); // ---------------------------------------------------- // table 5.1 // ---------------------------------------------------- paragraph = new Paragraph("Table 5.1 Planned Scorecard Milestones", fontTableCaption); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingAfter(6); document.add(paragraph); table = new PdfPTable(3); table.setTotalWidth(500); table.setLockedWidth(true); table.setWidths(new int[] { 3, 1, 1 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); headers = new String[] { "Milestone", "Planned Date", "Finish Date" }; for (String header : headers) { cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow)); cell.setBackgroundColor(BaseColor.BLUE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } for (int i = 0; i < milestones.length; i++) { cell = new PdfPCell(new Phrase(milestones[i].getMilestone())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(milestones[i].getPlannedDate())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(milestones[i].getFinishDate())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } document.add(table); // *******************************************************************************************// // 6 License & Permitting, and Environmental Status // *******************************************************************************************// outline1 = addOutline(root, writer, MPSRUI.TREE_6); addSectionTitle(document, MPSRUI.TREE_6, fontChapterHeader, 0, 24, 12); addOutline(outline1, writer, MPSRUI.TREE_6_1); addSectionTitle(document, MPSRUI.TREE_6_1, fontSection1Header, 6, 12, 12); addParagraph(document, writer, xmlWorker, lpe.getDesc_6_1(), fontNormal, 12, 0, 12); outline2 = addOutline(outline1, writer, MPSRUI.TREE_6_2); addSectionTitle(document, MPSRUI.TREE_6_2, fontSection1Header, 6, 12, 12); addOutline(outline2, writer, MPSRUI.TREE_6_2_1); addSectionTitle(document, MPSRUI.TREE_6_2_1, fontSection2Header, 12, 12, 12); addParagraph(document, writer, xmlWorker, lpe.getDesc_6_2_1(), fontNormal, 12, 0, 12); addOutline(outline2, writer, MPSRUI.TREE_6_2_2); addSectionTitle(document, MPSRUI.TREE_6_2_2, fontSection2Header, 12, 12, 12); addParagraph(document, writer, xmlWorker, lpe.getDesc_6_2_2(), fontNormal, 12, 0, 12); // *******************************************************************************************// // 7 Engineering Status // *******************************************************************************************// outline1 = addOutline(root, writer, MPSRUI.TREE_7); addSectionTitle(document, MPSRUI.TREE_7, fontChapterHeader, 0, 24, 12); addOutline(outline1, writer, MPSRUI.TREE_7_1); addSectionTitle(document, MPSRUI.TREE_7_1, fontSection1Header, 6, 12, 12); table = new PdfPTable(5); table.setTotalWidth(500); table.setLockedWidth(true); table.setWidths(new int[] { 2, 1, 1, 1, 3 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); headers = new String[] { "Package", "IFR", "IFC", "Indicator", "Note" }; for (String header : headers) { cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow)); cell.setBackgroundColor(BaseColor.BLUE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } for (int i = 0; i < ipds.length; i++) { cell = new PdfPCell(new Phrase(ipds[i].getPackage())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(ipds[i].getIFR())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(ipds[i].getIFC())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(ipds[i].getIndicator())); cell.setBackgroundColor(getBackgroundColor(ipds[i].getIndicator())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(ipds[i].getNote())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); } document.add(table); // -----------------------------------------------------------------------------------// addOutline(outline1, writer, MPSRUI.TREE_7_2); addSectionTitle(document, MPSRUI.TREE_7_2, fontSection1Header, 6, 12, 12); table = new PdfPTable(5); table.setTotalWidth(500); table.setLockedWidth(true); table.setWidths(new int[] { 2, 1, 1, 1, 3 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); headers = new String[] { "Package", "IFR", "IFC", "Indicator", "Note" }; for (String header : headers) { cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow)); cell.setBackgroundColor(BaseColor.BLUE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } for (int i = 0; i < opds.length; i++) { cell = new PdfPCell(new Phrase(opds[i].getPackage())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(opds[i].getIFR())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(opds[i].getIFC())); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(opds[i].getIndicator())); cell.setBackgroundColor(getBackgroundColor(opds[i].getIndicator())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(opds[i].getNote())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); } document.add(table); // *******************************************************************************************// // 8 Procurement Status // *******************************************************************************************// outline1 = addOutline(root, writer, MPSRUI.TREE_8); addSectionTitle(document, MPSRUI.TREE_8, fontChapterHeader, 0, 24, 12); outline2 = addOutline(outline1, writer, MPSRUI.TREE_8_1); addSectionTitle(document, MPSRUI.TREE_8_1, fontSection1Header, 6, 12, 12); table = new PdfPTable(2); table.setTotalWidth(300); table.setLockedWidth(true); table.setWidths(new int[] { 1, 1 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); cellValues = new String[][] { { "Receipted to Date", CURRENCY_FORMATTER.format(procure.getReceiptedToDate()) }, { "Open Commitments", CURRENCY_FORMATTER.format(procure.getOpenCommitment()) }, { "Total", CURRENCY_FORMATTER.format(procure.getTotalPurchaseOrder()) } }; for (int i = 0; i < cellValues.length; i++) { cell = new PdfPCell(new Phrase(cellValues[i][0])); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Phrase(cellValues[i][1])); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } document.add(table); addParagraph(document, writer, xmlWorker, procure.getDesc_8_1_B(), fontNormal, 12, 12, 12); outline2 = addOutline(outline1, writer, MPSRUI.TREE_8_2); addSectionTitle(document, MPSRUI.TREE_8_2, fontSection1Header, 6, 12, 12); // ---------------------------------------------------- // section 8.2.1 // ---------------------------------------------------- addOutline(outline2, writer, MPSRUI.TREE_8_2_1); addSectionTitle(document, MPSRUI.TREE_8_2_1, fontSection2Header, 12, 12, 12); addParagraph(document, writer, xmlWorker, procure.getDesc_8_2_1(), fontNormal, 12, 0, 12); table = new PdfPTable(6); table.setTotalWidth(550); table.setLockedWidth(true); table.setWidths(new int[] { 1, 2, 1, 1, 2, 1 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); headers = new String[] { "Purchase Order", "Vendor", "Previous Amount", "This Month Amount", "This Month Description", "Total Amount" }; for (String header : headers) { cell = new PdfPCell(new Phrase(header, fontPOTableHeader)); cell.setBackgroundColor(BaseColor.BLUE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } double totalToDate = 0; for (int i = 0; i < approvedChanges.length; i++) { cell = new PdfPCell(new Phrase(approvedChanges[i].getPurchaseOrder(), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(approvedChanges[i].getVendor(), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell( new Phrase(CURRENCY_FORMATTER.format(approvedChanges[i].getPreviousAmount()), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(CURRENCY_FORMATTER.format(approvedChanges[i].getThisMonthAmount()), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(approvedChanges[i].getThisMonthDescription(), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell( new Phrase(CURRENCY_FORMATTER.format(approvedChanges[i].getTotalAmount()), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); totalToDate += approvedChanges[i].getTotalAmount(); } document.add(table); table = new PdfPTable(2); table.setTotalWidth(550); table.setLockedWidth(true); table.setWidths(new int[] { 7, 1 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(new Phrase("Total To Date", fontPOTableSummary)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(CURRENCY_FORMATTER.format(totalToDate), fontPOTableSummary)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); document.add(table); // ---------------------------------------------------- // section 8.2.2 // ---------------------------------------------------- addOutline(outline2, writer, MPSRUI.TREE_8_2_2); addSectionTitle(document, MPSRUI.TREE_8_2_2, fontSection2Header, 12, 12, 12); addParagraph(document, writer, xmlWorker, procure.getDesc_8_2_2(), fontNormal, 12, 0, 12); table = new PdfPTable(6); table.setTotalWidth(550); table.setLockedWidth(true); table.setWidths(new int[] { 1, 2, 1, 1, 2, 1 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); headers = new String[] { "Purchase Order", "Vendor", "Previous Amount", "This Month Amount", "This Month Description", "Total Amount" }; for (String header : headers) { cell = new PdfPCell(new Phrase(header, fontPOTableHeader)); cell.setBackgroundColor(BaseColor.BLUE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } totalToDate = 0; for (int i = 0; i < pendingChanges.length; i++) { cell = new PdfPCell(new Phrase(pendingChanges[i].getPurchaseOrder(), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(pendingChanges[i].getVendor(), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell( new Phrase(CURRENCY_FORMATTER.format(pendingChanges[i].getPreviousAmount()), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell( new Phrase(CURRENCY_FORMATTER.format(pendingChanges[i].getThisMonthAmount()), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(pendingChanges[i].getThisMonthDescription(), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell( new Phrase(CURRENCY_FORMATTER.format(pendingChanges[i].getTotalAmount()), fontPOTable)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); totalToDate += pendingChanges[i].getTotalAmount(); } document.add(table); table = new PdfPTable(2); table.setTotalWidth(550); table.setLockedWidth(true); table.setWidths(new int[] { 7, 1 }); table.setHorizontalAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(new Phrase("Total To Date", fontPOTableSummary)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); cell = new PdfPCell(new Phrase(CURRENCY_FORMATTER.format(totalToDate), fontPOTableSummary)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(cell); document.add(table); // *******************************************************************************************// // 9 Construction Status // *******************************************************************************************// outline1 = addOutline(root, writer, MPSRUI.TREE_9); addSectionTitle(document, MPSRUI.TREE_9, fontChapterHeader, 0, 24, 12); addOutline(outline1, writer, MPSRUI.TREE_9_1); addSectionTitle(document, MPSRUI.TREE_9_1, fontSection1Header, 6, 12, 12); for (int i = 0; i < ipcs.length; i++) { addParagraph(document, writer, xmlWorker, ipcs[i].getWork(), fontWork, 12, 12, 0); addParagraph(document, writer, xmlWorker, ipcs[i].getDescription(), fontNormal, 12, 0, 0); addImage(document, MPSRUI.getFilePath(mpsrID, ipcs[i].getFileName()), "Figure " + ipcs[i].getFigure() + " " + ipcs[i].getTitle(), fontImageCaption, 12, 3, 12); } // -----------------------------------------------------------------------------------------// addOutline(outline1, writer, MPSRUI.TREE_9_2); addSectionTitle(document, MPSRUI.TREE_9_2, fontSection1Header, 6, 12, 12); for (int i = 0; i < opcs.length; i++) { addParagraph(document, writer, xmlWorker, opcs[i].getWork(), fontWork, 12, 12, 0); addParagraph(document, writer, xmlWorker, opcs[i].getDescription(), fontNormal, 12, 0, 0); addImage(document, MPSRUI.getFilePath(mpsrID, opcs[i].getFileName()), "Figure " + opcs[i].getFigure() + " " + opcs[i].getTitle(), fontImageCaption, 12, 3, 12); } // *******************************************************************************************// // Appendix // *******************************************************************************************// if (appendixs.length > 0) { document.add(Chunk.NEXTPAGE); outline1 = addOutline(root, writer, MPSRUI.TREE_APPENDIX); for (int i = 0; i < appendixs.length; i++) { addOutline(outline1, writer, "Appendix " + appendixs[i].getNumber() + " " + appendixs[i].getTitle()); addSectionTitle(document, "Appendix " + appendixs[i].getNumber() + " " + appendixs[i].getTitle(), fontChapterHeader, 0, 12, 12); addParagraph(document, writer, xmlWorker, appendixs[i].getDescription(), fontNormal, 12, 0, 0); importPages(document, writer, mpsrID, appendixs[i].getFileName()); } } // *******************************************************************************************// // Attachment // *******************************************************************************************// if (attachments.length > 0) { document.setPageSize(DEFAULT_PAGE_SIZE); document.add(Chunk.NEXTPAGE); outline1 = addOutline(root, writer, MPSRUI.TREE_ATTACHMENT); for (int i = 0; i < attachments.length; i++) { addOutline(outline1, writer, "Attachment " + attachments[i].getNumber() + " " + attachments[i].getTitle()); addSectionTitle(document, "Attachment " + attachments[i].getNumber() + " " + attachments[i].getTitle(), fontChapterHeader, 0, 12, 12); addParagraph(document, writer, xmlWorker, attachments[i].getDescription(), fontNormal, 12, 0, 0); importPages(document, writer, mpsrID, attachments[i].getFileName()); } } document.close(); // *******************************************************************************************// // retrieve outline PdfReader readerOrig = new PdfReader(baosOrig.toByteArray()); // int origNumberOfPages = readerOrig.getNumberOfPages(); ColumnText ct = new ColumnText(null); ct.addElement(new Paragraph("Table of Contents", fontCoverTitle)); List<HashMap<String, Object>> bookmarkList = SimpleBookmark.getBookmark(readerOrig); fillColumnText(bookmarkList, ct, 18, 0, fontSection2Header); // generate TOC after cover page ByteArrayOutputStream baosTOC = new ByteArrayOutputStream(); PdfStamper stamperTOC = new PdfStamper(readerOrig, baosTOC); int tocPageEnd = 1; while (true) { stamperTOC.insertPage(++tocPageEnd, readerOrig.getPageSize(1)); PdfContentByte underContent = stamperTOC.getUnderContent(tocPageEnd); generatePageHeader(document, underContent, icon, headerTexts); ct.setCanvas(stamperTOC.getOverContent(tocPageEnd)); ct.setSimpleColumn(36, 36, 558, 693); if (!ColumnText.hasMoreText(ct.go())) break; } stamperTOC.close(); // change page labels PdfPageLabels labels = new PdfPageLabels(); labels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS); labels.addPageLabel(tocPageEnd + 1, PdfPageLabels.DECIMAL_ARABIC_NUMERALS); // add labels ByteArrayOutputStream baosFinal = new ByteArrayOutputStream(); PdfReader readerTOC = new PdfReader(baosTOC.toByteArray()); // String selectPages = String.format("1-%s,%s-%s", tocPageEnd, // tocPageEnd + 1, origNumberOfPages + (tocPageEnd - 1)); // readerTOC.selectPages(selectPages); PdfStamper stamperFinal = new PdfStamper(readerTOC, baosFinal); stamperFinal.getWriter().setPageLabels(labels); stamperFinal.close(); // *******************************************************************************************// // send final PDF to browser response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); response.setContentType("application/pdf"); response.setContentLength(baosFinal.size()); OutputStream os = response.getOutputStream(); os.write(baosFinal.toByteArray()); os.flush(); os.close(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:com.tomasz.drag.triballocommanderro.controller.MakerPDF.java
public static void printToPDFBoss(ArrayList<Person> workers, EventGig event) throws IOException, DocumentException { String filename = event.getName() + " Boss" + ".pdf"; String path = event.getData() + " " + event.getName() + "//"; //Rectangle rect = new Rectangle(0, 595, 8, 0); Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0); //Document document = new Document(rect); //document.setMargins(0, 0, 0, 0); BaseFont bf;/*from w ww.j ava 2 s . c o m*/ //BaseFont bf2; // bf = BaseFont.createFont("arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); bf = BaseFont.createFont("src\\main\\resources\\font\\arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); //bf2 = BaseFont.createFont("src\\main\\resources\\font\\arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); com.itextpdf.text.Font ft = new com.itextpdf.text.Font(bf, 9); //com.itextpdf.text.Font ft2 = new com.itextpdf.text.Font(bf2,9); PdfWriter.getInstance(document, new FileOutputStream(path + filename)); document.open(); Paragraph p = new Paragraph(event.getName() + " " + event.getData(), ft); p.setAlignment(Element.ALIGN_CENTER); document.add(p); document.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(workers.size() + 1); table.setWidthPercentage(98); PdfPCell cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); for (Person tempPerson : workers) { cell = new PdfPCell(new Paragraph(tempPerson.getName(), ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } if (event.isZaladunekScenaDach()) { cell = new PdfPCell(new Paragraph("Za. Sc./Dach", ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getZaladunekScenaDachWyplata() > 0) { cell = new PdfPCell( new Paragraph(String.format("%.2f", tempPerson.getZaladunekScenaDachWyplata()), ft)); cell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isZaladunekTechniki()) { cell = new PdfPCell(new Phrase("Za. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getZaladunekTechnikiWyplata() > 0) { cell = new PdfPCell( new Paragraph(String.format("%.2f", tempPerson.getZaladunekTechnikiWyplata()), ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRozladunekScenaDach()) { cell = new PdfPCell(new Phrase("Roz Sc/Dach", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRozladunekScenaDachWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRozladunekScenaDachWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRozladunekTechniki()) { cell = new PdfPCell(new Phrase("Roz. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRozladunekTechnikiWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRozladunekTechnikiWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazDachu()) { cell = new PdfPCell(new Phrase("Mon. Dach", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazDachuWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getMontazDachuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazDzwieku()) { cell = new PdfPCell(new Phrase("Mon. Dw.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazDzwiekuWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getMontazDzwiekuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazSceny()) { cell = new PdfPCell(new Phrase("Mon. Sc.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazScenyWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getMontazScenyWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazSwiatla()) { cell = new PdfPCell(new Phrase("Mon. w.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazSwiatlaWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getMontazSwiatlaWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazTechniki()) { cell = new PdfPCell(new Phrase("Mon. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazTechnikiWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getMontazTechnikiWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazDachu()) { cell = new PdfPCell(new Phrase("Dem. Dach", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazDachuWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazDachuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazDzwieku()) { cell = new PdfPCell(new Phrase("Dem. Dw.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazDzwiekuWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazDzwiekuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazSceny()) { cell = new PdfPCell(new Phrase("Dem. Sc.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazScenyWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazScenyWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazSwiatla()) { cell = new PdfPCell(new Phrase("Dem. w.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazSwiatlaWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazSwiatlaWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazTechniki()) { cell = new PdfPCell(new Phrase("Dem. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazTechnikiWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazTechnikiWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDyzur()) { cell = new PdfPCell(new Phrase("Dyur", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDyzurWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getDyzurWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase("")); table.addCell(cell); } } } if (event.isTechnikSceny()) { cell = new PdfPCell(new Phrase("Technik Sc.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getTechnikScenyWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getTechnikScenyWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRealizacjaFOH()) { cell = new PdfPCell(new Phrase("Real. FOH", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRealizacjaFOHWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRealizacjaFOHWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRealizacjaMON()) { cell = new PdfPCell(new Phrase("Real. MON", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRealizacjaMONWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRealizacjaMONWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRealizacjaSwiatla()) { cell = new PdfPCell(new Phrase("Real. w.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRealizacjaSwiatlaWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (true) { cell = new PdfPCell(new Phrase("Premia", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getPremia() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getPremia()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } Paragraph ph = new Paragraph("Razem", ft); //cell = new PdfPCell(new Phrase(ph)); cell.addElement(ph); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getSumaWyplata() >= 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getSumaWyplata()) + " z", ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } // for (Object obj : table.getChunks()) { // if (obj instanceof PdfPCell) { // System.out.println("jest PdfCell"); // PdfPCell tempCell = (PdfPCell) obj; // tempCell.setVerticalAlignment(Element.ALIGN_CENTER); // //tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // } // // } table.setHorizontalAlignment(Element.ALIGN_CENTER); document.add(table); document.close(); }
From source file:Controller.ControllerCompra.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w . j a va2 s . com * * @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 { response.setContentType("text/html;charset=UTF-8"); if (request.getParameter("action") != null) { //int estado = 0; String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); String action = request.getParameter("action"); switch (action) { case "Registrar": { String documentoUsuario = (request.getParameter("documentoUsuario")); String facturaProveedor = (request.getParameter("txtNumeroFactura")); String nombreProveedor = (request.getParameter("txtNombre")); int lenght = Integer.parseInt(request.getParameter("size")); int totalCompra = Integer.parseInt(request.getParameter("txtTotalCompra")); listObjDetalleMovimientos = new ArrayList<>(); for (int i = 0; i < lenght; i++) { _objDetalleMovimiento = new ObjDetalleMovimiento(); _objDetalleMovimiento .setIdArticulo(Integer.parseInt(request.getParameter("lista[" + i + "][idArticulo]"))); _objDetalleMovimiento .setCantidad(Integer.parseInt(request.getParameter("lista[" + i + "][cantidad]"))); _objDetalleMovimiento.setPrecioArticulo( Integer.parseInt(request.getParameter("lista[" + i + "][precioArticulo]"))); _objDetalleMovimiento.setTotalDetalleMovimiento( _objDetalleMovimiento.getCantidad() * _objDetalleMovimiento.getPrecioArticulo()); _objDetalleMovimiento.setDescuento(lenght); listObjDetalleMovimientos.add(_objDetalleMovimiento); } _objUsuario.setDocumentoUsuario(documentoUsuario); _objCompra.setFacturaProveedor(facturaProveedor); _objCompra.setNombreProveedor(nombreProveedor); _objCompra.setTotalCompra(totalCompra); daoModelCompra = new ModelCompra(); String salida = Mensaje(daoModelCompra.Add(_objCompra, _objUsuario, listObjDetalleMovimientos), "La compra ha sido registrada", "Ha ocurrido un error"); daoModelCompra.Signout(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(salida); break; } case "Consultar": { int id = Integer.parseInt(request.getParameter("id")); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(consultarDetalle(id)); break; } case "Enlistar": { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(getTableCompra()); break; } //<editor-fold defaultstate="collapsed" desc="PDF mediante iText"> case "Imprimir": { response.setContentType("application/pdf"); try { Locale loc = Locale.getDefault(); NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(loc); //Primero obtengo el id del Movimiento int id = Integer.parseInt(request.getParameter("id")); //Obtengo el reporte a manera de Map Map material = reporte(id); //Topo ese reporte y lo divido, primero en la compra y luego el detalle Map<String, String> compra = (Map) material.get("Compra"); List<Map> detalle = (List) material.get("Detalle"); //Creo el documento y obtengo el canal de comunicacion con el servidor, para luego enviar el documento. Document document = new Document(); OutputStream os = response.getOutputStream(); //Creo una instancia a partir del documento y del canal PdfWriter.getInstance(document, os); //Abro el documento document.open(); Image logo = Image.getInstance(url + "/public/images/logo.png"); logo.scaleAbsolute(new Rectangle(logo.getPlainWidth() / 4, logo.getPlainHeight() / 4)); document.add(logo); //Creo una fuente para la letra en negrilla final Font helveticaBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); //Escribo y agrego un primer parrafo con los datos basicos de la compra Paragraph headerDerecha = new Paragraph(); headerDerecha.add(new Chunk("Nombre del Proveedor: ", helveticaBold)); headerDerecha.add(new Chunk(compra.get("nombreProveedor") + "\n")); headerDerecha.add(new Chunk("Factura del Proveedor: ", helveticaBold)); headerDerecha.add(new Chunk(compra.get("facturaProveedor") + "\n")); headerDerecha.add(new Chunk("Fecha Compra: ", helveticaBold)); headerDerecha.add(new Chunk(compra.get("fechaCompra") + "\n")); //Escribo y agrego un segundo parrafo con los datos basicos de Stelarte Paragraph headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Stelarte.Decoracion \n", helveticaBold)); headerIzquierda.add(new Chunk("Direccin: ", helveticaBold)); headerIzquierda.add(new Chunk("Calle Falsa 123 # 12a34\n")); headerIzquierda.add(new Chunk("Telfono: ", helveticaBold)); headerIzquierda.add(new Chunk("2583697 \n")); //Agrego los dos anteriores parrafos al Header PdfPTable header = new PdfPTable(2); header.getDefaultCell().setBorder(0); header.addCell(headerIzquierda); header.addCell(headerDerecha); header.setWidthPercentage(100f); header.setSpacingAfter(20); document.add(header); //Creo la tabla del detalle PdfPTable tablaDetalle = new PdfPTable(new float[] { 1, 3, 2, 2 }); tablaDetalle.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); //Creo el titulo, le quito el borde, le digo que ocupara cuatro columnas y que ser centrado PdfPCell tituloCell = new PdfPCell(new Phrase("Detalle de Compra", helveticaBold)); tituloCell.setBorder(0); tituloCell.setColspan(4); tituloCell.setHorizontalAlignment(Element.ALIGN_CENTER); tablaDetalle.addCell(tituloCell); //Aqui creo cada cabecera tablaDetalle.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); tablaDetalle.addCell(new Phrase("ID", helveticaBold)); tablaDetalle.addCell(new Phrase("Nombre", helveticaBold)); tablaDetalle.addCell(new Phrase("Cantidad", helveticaBold)); tablaDetalle.addCell(new Phrase("Valor", helveticaBold)); tablaDetalle.getDefaultCell().setBackgroundColor(null); //Aqui agrego la tabla cada articulo. for (Map<String, String> next : detalle) { tablaDetalle.addCell(next.get("idArticulo")); tablaDetalle.addCell(next.get("descripcionArticulo")); tablaDetalle.addCell(next.get("cantidad")); tablaDetalle .addCell(currencyFormatter.format(Integer.parseInt(next.get("precioArticulo")))); } //Creo el Footer headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Total: ", helveticaBold)); headerIzquierda .add(new Chunk(currencyFormatter.format(Integer.parseInt(compra.get("totalCompra"))))); PdfPCell footerCell = new PdfPCell(headerIzquierda); footerCell.setBorder(0); footerCell.setColspan(4); footerCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tablaDetalle.addCell(footerCell); //Establesco el tamao y posicion de la tabla, luego la agrego al documento tablaDetalle.setWidthPercentage(100f); tablaDetalle.setHorizontalAlignment(Element.ALIGN_RIGHT); document.add(tablaDetalle); //Cierro el documento y lo envio con flush. document.close(); response.setHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\""); os.flush(); os.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } break; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="PDF mediante iReports"> case "Imprimir2": { try { int id = Integer.parseInt(request.getParameter("id")); String source = url + "/reports/newReport1.jrxml"; JasperPrint jasperPrint = null; JasperReport jasperReport = null; JasperDesign jasperDesign = null; System.out.println(source); String reportPath = request.getServletContext().getRealPath("reports") + "\\newReport1.jrxml"; jasperDesign = JRXmlLoader.load(reportPath); jasperReport = JasperCompileManager.compileReport(jasperDesign); jasperPrint = JasperFillManager.fillReport(jasperReport, reporte(id), daoModelCompra.getConnection()); JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream()); } catch (Exception ex) { for (StackTraceElement ruta : ex.getStackTrace()) { System.err.println(ruta); } } } break; //</editor-fold> } } }
From source file:Controller.ControllerVenta.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w . jav a 2 s . 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 { response.setContentType("text/html;charset=UTF-8"); if (request.getParameter("action") != null) { String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); String action = request.getParameter("action"); switch (action) { case "Registrar": { String documentoUsuario = (request.getParameter("documentoUsuario")); String documentoCliente = null; String nombreCliente = null; int numeroVenta = 0; if (Validador.validarDocumento(request.getParameter("documentoCliente")) & Validador.validarNombresCompletos(request.getParameter("txtNombreCliente")) & Validador.validarNumero(request.getParameter("txtNumeroVenta"))) { documentoCliente = (request.getParameter("documentoCliente")); nombreCliente = (request.getParameter("txtNombreCliente")); numeroVenta = Integer.parseInt(request.getParameter("txtNumeroVenta")); } else { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(Mensaje(false, null, "Ha ingresado datos incorrectos")); break; } int lenght = Integer.parseInt(request.getParameter("size")); int totalCompra = Integer.parseInt(request.getParameter("txtTotalVenta")); listOjbDetalleMovimientos = new ArrayList<>(); for (int i = 0; i < lenght; i++) { _objDetalleMovimiento = new ObjDetalleMovimiento(); _objDetalleMovimiento .setIdArticulo(Integer.parseInt(request.getParameter("lista[" + i + "][idArticulo]"))); _objDetalleMovimiento .setCantidad(Integer.parseInt(request.getParameter("lista[" + i + "][cantidad]"))); _objDetalleMovimiento.setPrecioArticulo( Integer.parseInt(request.getParameter("lista[" + i + "][precioArticulo]"))); _objDetalleMovimiento.setTotalDetalleMovimiento( _objDetalleMovimiento.getCantidad() * _objDetalleMovimiento.getPrecioArticulo()); _objDetalleMovimiento.setDescuento(lenght); listOjbDetalleMovimientos.add(_objDetalleMovimiento); } _objUsuario.setDocumentoUsuario(documentoUsuario); _objVenta.setIdVenta(numeroVenta); _objVenta.setDocumentoCliente(documentoCliente); _objVenta.setNombreCliente(nombreCliente); _objVenta.setTotalVenta(totalCompra); daoModelVenta = new ModelVenta(); String salida = Mensaje(daoModelVenta.Add(_objVenta, _objUsuario, listOjbDetalleMovimientos), "La venta ha sido registrada", "Ha ocurrido un error"); daoModelVenta.Signout(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(salida); break; } case "Consultar": { int id = Integer.parseInt(request.getParameter("id")); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(consultarDetalle(id)); break; } case "Enlistar": { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(getTableVenta()); break; } case "Contador": { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(getContador()); break; } case "Imprimir": { response.setContentType("application/pdf"); try { Locale loc = Locale.getDefault(); NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(loc); //Primero obtengo el id del Movimiento int id = Integer.parseInt(request.getParameter("id")); //Obtengo el reporte a manera de Map Map material = reporte(id); //Topo ese reporte y lo divido, primero en la compra y luego el detalle Map<String, String> venta = (Map) material.get("Venta"); List<Map> detalle = (List) material.get("Detalle"); //Creo el documento y obtengo el canal de comunicacion con el servidor, para luego enviar el documento. Document document = new Document(); OutputStream os = response.getOutputStream(); //Creo una instancia a partir del documento y del canal PdfWriter.getInstance(document, os); //Abro el documento document.open(); Image logo = Image.getInstance(url + "/public/images/logo.png"); logo.scaleAbsolute(new Rectangle(logo.getPlainWidth() / 4, logo.getPlainHeight() / 4)); document.add(logo); //Creo una fuente para la letra en negrilla final Font helveticaBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); //Escribo y agrego un primer parrafo con los datos basicos de la compra Paragraph headerDerecha = new Paragraph(); headerDerecha.add(new Chunk("Id. de la Venta: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("numeroVenta") + "\n")); headerDerecha.add(new Chunk("Nombre del Cliente: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("nombreCliente") + "\n")); headerDerecha.add(new Chunk("Documento del Cliente: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("documentoCliente") + "\n")); headerDerecha.add(new Chunk("Fecha Venta: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("fechaVenta") + "\n")); //Escribo y agrego un segundo parrafo con los datos basicos de Stelarte Paragraph headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Stelarte.Decoracion \n", helveticaBold)); headerIzquierda.add(new Chunk("Direccin: ", helveticaBold)); headerIzquierda.add(new Chunk("Calle Falsa 123 # 12a34\n")); headerIzquierda.add(new Chunk("Telfono: ", helveticaBold)); headerIzquierda.add(new Chunk("2583697 \n")); //Agrego los dos anteriores parrafos al Header PdfPTable header = new PdfPTable(2); header.getDefaultCell().setBorder(0); header.addCell(headerIzquierda); header.addCell(headerDerecha); header.setWidthPercentage(100f); header.setSpacingAfter(20); document.add(header); //Creo la tabla del detalle PdfPTable tablaDetalle = new PdfPTable(new float[] { 1, 3, 2, 2 }); tablaDetalle.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); //Creo el titulo, le quito el borde, le digo que ocupara cuatro columnas y que ser centrado PdfPCell tituloCell = new PdfPCell(new Phrase("Detalle de Venta", helveticaBold)); tituloCell.setBorder(0); tituloCell.setColspan(4); tituloCell.setHorizontalAlignment(Element.ALIGN_CENTER); tablaDetalle.addCell(tituloCell); //Aqui creo cada cabecera tablaDetalle.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); tablaDetalle.addCell(new Phrase("ID", helveticaBold)); tablaDetalle.addCell(new Phrase("Nombre", helveticaBold)); tablaDetalle.addCell(new Phrase("Cantidad", helveticaBold)); tablaDetalle.addCell(new Phrase("Valor", helveticaBold)); tablaDetalle.getDefaultCell().setBackgroundColor(null); //Aqui agrego la tabla cada articulo. for (Map<String, String> next : detalle) { tablaDetalle.addCell(next.get("idArticulo")); tablaDetalle.addCell(next.get("descripcionArticulo")); tablaDetalle.addCell(next.get("cantidad")); tablaDetalle .addCell(currencyFormatter.format(Integer.parseInt(next.get("precioArticulo")))); } //Creo el Footer headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Total: ", helveticaBold)); headerIzquierda .add(new Chunk(currencyFormatter.format(Integer.parseInt(venta.get("totalVenta"))))); PdfPCell footerCell = new PdfPCell(headerIzquierda); footerCell.setBorder(0); footerCell.setColspan(4); footerCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tablaDetalle.addCell(footerCell); //Establesco el tamao y posicion de la tabla, luego la agrego al documento tablaDetalle.setWidthPercentage(100f); tablaDetalle.setHorizontalAlignment(Element.ALIGN_RIGHT); document.add(tablaDetalle); //Cierro el documento y lo envio con flush. document.close(); response.setHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\""); os.flush(); os.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } break; } } } }
From source file:Controller.PrintOrderManagedBean.java
public void executePDF(String maDH) { try {//from ww w . ja v a2 s. c om DonHang donhang = new DonHang(); donhang.init(maDH); float CONVERT = 28.346457f;// 1 cm FacesContext faces = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); //response.setHeader("Content-disposition","inline; filename=kiran.pdf"); response.setHeader("Pragma", "public"); response.setContentType("application/pdf"); //response.setHeader("Content-Disposition", "attachment;filename=\"ContactList.pdf\""); response.addHeader("Content-disposition", "attachment;filename=\"DataListBean.pdf\""); //step 1: creation of a document-object Document document = new Document(PageSize.A4, 0.5f * CONVERT, 0.5f * CONVERT, 1.0f * CONVERT, 1.0f * CONVERT); //step 2: we create a writer that listens to the document // and directs a PDF-stream to a temporary buffer ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); PdfWriter writer = PdfWriter.getInstance(document, baos); BaseFont bf = BaseFont.createFont("c:\\windows\\fonts\\arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font font = new Font(bf, 18, Font.BOLD); Font font11 = new Font(bf, 11, Font.NORMAL); Font font11_bo = new Font(bf, 11, Font.BOLD); Font font12 = new Font(bf, 12, Font.NORMAL); Font font10 = new Font(bf, 10, Font.NORMAL); Font font9 = new Font(bf, 9, Font.NORMAL); //step 3: we open the document document.open(); PdfPTable tab_Header1; tab_Header1 = new PdfPTable(1); tab_Header1.setWidthPercentage(100); tab_Header1.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell1; cell1 = new PdfPCell(new Phrase("CNG TY TNHH ABC FASHION", font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell( new Phrase("?a ch: 146 Linh Trung,P. Linh Trung, Q. Th ?c, TP HCM", font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("S?T: 0909465621", font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("", font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("?N GIAO HNG", font12)); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("Bn Bn:", font11_bo)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("Tn: CNG TY TNHH ABC FASHION", font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell( new Phrase("?a ch: 146 Linh Trung,P. Linh Trung, Q. Th ?c, TP HCM", font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("S in thoi: 0909465621", font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("Bn Mua:", font11_bo)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("Tn: " + donhang.getTenKH(), font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("?a ch: " + donhang.getDiaChiKH(), font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("S in thoi: " + donhang.getSoDTKH(), font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("Bn Vn chuyn:", font11_bo)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("Tn:....................................", font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("?a ch:...............................", font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("S in thoi:...............................", font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("Danh sch hng ha:", font11)); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); ///////////////////////////////bn sn phm float[] crDonHang = { 1.0f * CONVERT, 4.0f * CONVERT, 1.0f * CONVERT, 2.0f * CONVERT, 2.0f * CONVERT }; PdfPTable tab_Header2; tab_Header2 = new PdfPTable(crDonHang.length); tab_Header2.setWidthPercentage(100); tab_Header2.setWidths(crDonHang); tab_Header2.setHorizontalAlignment(Element.ALIGN_CENTER); NumberFormat formatter = new DecimalFormat("#,###,###"); String[] crheader = { "STT", "Tn Hng", "S Lng", "Gi Bn(VN?)", "Thnh Ti?n(VN?)" }; for (int i = 0; i < crheader.length; i++) { PdfPCell cell = new PdfPCell(new Phrase(crheader[i], font11)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tab_Header2.addCell(cell); } int stt = 1; for (SanPhamDH sp : donhang.getListSP()) { PdfPCell cell = new PdfPCell(new Phrase(String.valueOf(stt), font11)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tab_Header2.addCell(cell); cell = new PdfPCell(new Phrase(sp.getTenSP(), font11)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); tab_Header2.addCell(cell); cell = new PdfPCell(new Phrase(sp.getSoluong(), font11)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); tab_Header2.addCell(cell); cell = new PdfPCell(new Phrase(formatter.format(Double.parseDouble(sp.getGiaSP())), font11)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); tab_Header2.addCell(cell); cell = new PdfPCell(new Phrase(formatter.format(Double.parseDouble(sp.getThanhTien())), font11)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); tab_Header2.addCell(cell); stt++; } cell1 = new PdfPCell(tab_Header2); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("Tng ti?n hng: " + formatter.format( Double.parseDouble(donhang.getTienTamTinh() == null ? "0" : donhang.getTienTamTinh())) + " VN?", font11)); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("Tng ti?n vn chuyn: " + formatter.format(Double .parseDouble(donhang.getTienVanChuyen() == null ? "0" : donhang.getTienVanChuyen())) + " VN?", font11)); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("Tng ti?n thanh ton: " + formatter.format(Double.parseDouble(donhang.getTongTien())) + " VN?", font11)); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("S ti?n thanh ton bng ch: " + DocTien.doctien(donhang.getTongTien().replaceAll(" ", "")) + "ng", font11)); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase(" ", font11)); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase("TP H Ch Minh, ngy thng nm ", font11)); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); cell1.setPaddingRight(1.0f * CONVERT); cell1.setBorder(0); tab_Header1.addCell(cell1); cell1 = new PdfPCell(new Phrase(" ", font11)); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header1.addCell(cell1); PdfPTable tab_Header3; tab_Header3 = new PdfPTable(3); tab_Header3.setWidthPercentage(100); tab_Header3.setHorizontalAlignment(Element.ALIGN_CENTER); cell1 = new PdfPCell(new Phrase("Ng?i nhn hng", font11)); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header3.addCell(cell1); cell1 = new PdfPCell(new Phrase("Ng?i giao hng", font11)); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header3.addCell(cell1); cell1 = new PdfPCell(new Phrase("Ng?i bn hng", font11)); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header3.addCell(cell1); cell1 = new PdfPCell(new Phrase("(k v ghi r h? tn)", font11)); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header3.addCell(cell1); cell1 = new PdfPCell(new Phrase("(k v ghi r h? tn)", font11)); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header3.addCell(cell1); cell1 = new PdfPCell(new Phrase("(k v ghi r h? tn)", font11)); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setPaddingBottom(5.0f); cell1.setBorder(0); tab_Header3.addCell(cell1); cell1 = new PdfPCell(tab_Header3); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBorder(0); tab_Header1.addCell(cell1); document.add(tab_Header1); document.close(); //step 6: we output the writer as bytes to the response output // the contentlength is needed for MSIE!!! response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); baos.flush(); faces.responseComplete(); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.fau.osr.util.matrix.MatrixTools.java
License:Open Source License
/** * /**//from ww w.ja va2 s . co m * saves matrix to {@code path} in pdf format * @param matrix matrix to save * @param path file where matrix will be saved */ public static boolean SaveMatrixToPdf(RequirementsTraceabilityMatrixByImpact matrix, File path, String matrixTitle) { Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(path)); document.open(); document.addTitle(matrixTitle); Paragraph headerPar = new Paragraph("Traceability Matrix"); headerPar.add(new Paragraph(" ")); //new line document.add(headerPar); java.util.List<String> reqs = matrix.getRequirements(); //table setup PdfPTable table = new PdfPTable(reqs.size() + 1); //reqs + "file name" col table.setHeaderRows(1); table.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); table.setWidthPercentage(100); table.setSpacingBefore(0); table.setSpacingAfter(0); //file name col width/req col width 4:1 float[] widths = new float[reqs.size() + 1]; widths[0] = 4; for (int i = 0; i < reqs.size(); i++) { widths[i + 1] = 1; } table.setWidths(widths); //header row //add filename col to header addCell(table, "File name", 10, Element.ALIGN_LEFT); //add req cols to header for (String req : reqs) { addCell(table, "req-" + req, 8, Element.ALIGN_CENTER); } //content, row by row: for (int i = 0; i < matrix.getFiles().size(); i++) { //filename col String fileName = matrix.getFiles().get(i); addCell(table, fileName, 5, Element.ALIGN_LEFT, 18); //impact value cols for (String req : reqs) { RequirementFileImpactValue value = matrix .getImpactValue(new RequirementFilePair(req, fileName)); if (value == null) { value = new RequirementFileImpactValue(0); } //round DecimalFormat df = new DecimalFormat("#.##"); df.setRoundingMode(RoundingMode.CEILING); String valString = df.format(value.getImpactPercentage()); addCell(table, valString, 10, Element.ALIGN_CENTER); } } document.add(table); } catch (DocumentException | FileNotFoundException e) { e.printStackTrace(); return false; } finally { document.close(); } return true; }
From source file:Documentos.ReportesPDF.java
public void agregarTabla(Paragraph parrafo) { //Anchos de las columnas PdfPTable tabla = new PdfPTable(anchosFilas); // Porcentaje que ocupa a lo ancho de la pagina del PDF tabla.setWidthPercentage(90);//from ww w .j a v a2 s .c om //Alineacion horizontal centrada tabla.setHorizontalAlignment(Element.ALIGN_CENTER); //agregar celda que ocupa las columnas de los rotulos PdfPCell cell0 = new PdfPCell(new Paragraph("Repostera AnaIs")); cell0.setColspan(anchosFilas.length); cell0.setBackgroundColor(new BaseColor(66, 139, 202)); //Centrar contenido de celda cell0.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(new Paragraph(tituloReporte())); cell.setColspan(anchosFilas.length); cell.setBackgroundColor(new BaseColor(49, 176, 213)); //Centrar contenido de celda cell.setHorizontalAlignment(Element.ALIGN_CENTER); //Color de fondo de la celda tabla.addCell(cell0); tabla.addCell(cell); // Mostrar los rotulos de las columnas for (int i = 0; i < rotulosColumnas.length; i++) { cell = new PdfPCell(new Paragraph(rotulosColumnas[i])); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new BaseColor(248, 248, 248)); tabla.addCell(cell); } switch (numReport) { case 1: DataBase.DataBasePDF.pdfVendedores(cell, tabla); break; case 2: DataBase.DataBasePDF.pdfProveedores(cell, tabla); break; case 3: DataBase.DataBasePDF.pdfClientes(cell, tabla); break; case 4: DataBase.DataBasePDF.pdfVentas(cell, tabla); break; case 5: DataBase.DataBasePDF.pdfProductos(cell, tabla); break; case 6: DataBase.DataBasePDF.pdfPedidos(cell, tabla); break; } //Agregar la tabla con los datos al parrafo que nos llego como entrada parrafo.add(tabla); }
From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java
License:Open Source License
private PdfPTable createTable(Map<String, Integer> yearToPublicationCount) { Font normalContentStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11); Font summaryContentStyle = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLDITALIC); BaseColor summaryBackgroundColor = new BaseColor(0xEE, 0xEE, 0xEE); BaseColor headerBackgroundColor = new BaseColor(0xC3, 0xD9, 0xFF); BaseColor bodyBackgroundColor = new BaseColor(Color.white); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(36.0f);//from w w w.ja va 2s .c o m table.setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setBorderWidth(0.0f); table.setHeaderRows(2); PdfPCell cell; cell = new PdfPCell(new Phrase("Publications per year", normalContentStyle)); setTableCaptionStyle(summaryBackgroundColor, cell); table.addCell(cell); cell = new PdfPCell(new Phrase("Year", normalContentStyle)); setTableHeaderStyle(headerBackgroundColor, cell); table.addCell(cell); cell.setPhrase(new Phrase("Publications", normalContentStyle)); table.addCell(cell); setTableBodyStyle(bodyBackgroundColor, cell); int totalPublications = 0; for (Entry<String, Integer> currentEntry : yearToPublicationCount.entrySet()) { cell.setPhrase(new Phrase(currentEntry.getKey(), normalContentStyle)); table.addCell(cell); cell.setPhrase(new Phrase(currentEntry.getValue().toString(), normalContentStyle)); table.addCell(cell); totalPublications += currentEntry.getValue(); } setTableFooterStyle(summaryBackgroundColor, cell); cell.setPhrase(new Phrase("Total", summaryContentStyle)); table.addCell(cell); cell.setPhrase(new Phrase(String.valueOf(totalPublications), summaryContentStyle)); table.addCell(cell); return table; }
From source file:edu.harvard.mcz.precapture.encoder.LabelEncoder.java
License:Open Source License
public static PdfPTable setupTable(int paperWidthPoints, int marginsPoints, int labelWidthPoints, int columns, int subCellColumnCount, float relWidthTextCell, float relWidthBarcodeCell) throws DocumentException { PdfPTable table = new PdfPTable(subCellColumnCount); table.setLockedWidth(true); // force use of totalWidth in points, rather than percentWidth. float percentWidth = ((((float) paperWidthPoints) - (2f * ((float) marginsPoints))) / ((float) paperWidthPoints)) * 100f; //percentWidth = 100f; log.debug("Table Width Percent = " + percentWidth); table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); float[] cellWidthsRatio = new float[subCellColumnCount]; int cellNumber = 0; for (int c = 0; c < columns; c++) { cellWidthsRatio[cellNumber] = relWidthTextCell; // width of text cell cellNumber++;// ww w . j a va 2 s .c om if (subCellColumnCount > 1) { cellWidthsRatio[cellNumber] = relWidthBarcodeCell; // width of barcode cell cellNumber++; } } table.setTotalWidth(paperWidthPoints - 2 * marginsPoints); // must set total width before setting relative cell widths. table.setWidths(cellWidthsRatio); log.debug("Width:" + table.getTotalWidth()); return table; }