List of usage examples for com.lowagie.text Element ALIGN_BOTTOM
int ALIGN_BOTTOM
To view the source code for com.lowagie.text Element ALIGN_BOTTOM.
Click Source Link
From source file:org.kuali.kfs.module.endow.report.util.EndowmentReportPrintBase.java
License:Educational Community License
/** * Create a cell with the given font, alignment, and borderline option * /*from w ww . j av a 2 s . c om*/ * @param content * @param font * @param alignment * @param borderLine * @return */ public PdfPCell createCell(String contents, Font font, int horizontalAlignment, boolean borderLine) { return createCell(contents, font, horizontalAlignment, Element.ALIGN_BOTTOM, borderLine); }
From source file:org.kuali.kfs.module.purap.pdf.PurchaseOrderPdf.java
License:Open Source License
/** * Create a PDF using the given input parameters. * * @param po The PurchaseOrderDocument to be used to create the pdf. * @param document The pdf document whose margins have already been set. * @param writer The PdfWriter to write the pdf document into. * @param statusInquiryUrl The status inquiry url to be displayed on the pdf document. * @param campusName The campus name to be displayed on the pdf document. * @param contractLanguage The contract language to be displayed on the pdf document. * @param logoImage The logo image file name to be displayed on the pdf document. * @param directorSignatureImage The director signature image to be displayed on the pdf document. * @param directorName The director name to be displayed on the pdf document. * @param directorTitle The director title to be displayed on the pdf document. * @param contractManagerSignatureImage The contract manager signature image to be displayed on the pdf document. * @param isRetransmit The boolean to indicate whether this is for a retransmit purchase order document. * @param environment The current environment used (e.g. DEV if it is a development environment). * @param retransmitItems The items selected by the user to be retransmitted. * @throws DocumentException/*from ww w .j ava 2s . co m*/ * @throws IOException */ private void createPdf(PurchaseOrderDocument po, Document document, PdfWriter writer, String statusInquiryUrl, String campusName, String contractLanguage, String logoImage, String directorSignatureImage, String directorName, String directorTitle, String contractManagerSignatureImage, boolean isRetransmit, String environment, List<PurchaseOrderItem> retransmitItems) throws DocumentException, IOException { if (LOG.isDebugEnabled()) { LOG.debug("createPdf() started for po number " + po.getPurapDocumentIdentifier().toString()); } // These have to be set because they are used by the onOpenDocument() and onStartPage() methods. this.campusName = campusName; this.po = po; this.logoImage = logoImage; this.environment = environment; NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.US); Collection errors = new ArrayList(); // Date format pattern: MM-dd-yyyy SimpleDateFormat sdf = PurApDateFormatUtils .getSimpleDateFormat(PurapConstants.NamedDateFormats.KUALI_SIMPLE_DATE_FORMAT_2); // This turns on the page events that handle the header and page numbers. PurchaseOrderPdf events = new PurchaseOrderPdf().getPageEvents(); writer.setPageEvent(this); // Passing in "this" lets it know about the po, campusName, etc. document.open(); PdfPCell cell; Paragraph p = new Paragraph(); // ***** Info table (vendor, address info) ***** LOG.debug("createPdf() info table started."); float[] infoWidths = { 0.50f, 0.50f }; PdfPTable infoTable = new PdfPTable(infoWidths); infoTable.setWidthPercentage(100); infoTable.setHorizontalAlignment(Element.ALIGN_CENTER); infoTable.setSplitLate(false); StringBuffer vendorInfo = new StringBuffer(); vendorInfo.append("\n"); if (StringUtils.isNotBlank(po.getVendorName())) { vendorInfo.append(" " + po.getVendorName() + "\n"); } vendorInfo.append(" ATTN: " + po.getVendorAttentionName() + "\n"); if (StringUtils.isNotBlank(po.getVendorLine1Address())) { vendorInfo.append(" " + po.getVendorLine1Address() + "\n"); } if (StringUtils.isNotBlank(po.getVendorLine2Address())) { vendorInfo.append(" " + po.getVendorLine2Address() + "\n"); } if (StringUtils.isNotBlank(po.getVendorCityName())) { vendorInfo.append(" " + po.getVendorCityName()); } if (StringUtils.isNotBlank(po.getVendorStateCode())) { vendorInfo.append(", " + po.getVendorStateCode()); } if (StringUtils.isNotBlank(po.getVendorAddressInternationalProvinceName())) { vendorInfo.append(", " + po.getVendorAddressInternationalProvinceName()); } if (StringUtils.isNotBlank(po.getVendorPostalCode())) { vendorInfo.append(" " + po.getVendorPostalCode() + "\n"); } else { vendorInfo.append("\n"); } if (!KFSConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(po.getVendorCountryCode()) && po.getVendorCountry() != null) { vendorInfo.append(" " + po.getVendorCountry().getName() + "\n\n"); } else { vendorInfo.append("\n\n"); } p = new Paragraph(); p.add(new Chunk(" Vendor", ver_5_normal)); p.add(new Chunk(vendorInfo.toString(), cour_7_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); StringBuffer shipToInfo = new StringBuffer(); shipToInfo.append("\n"); if (po.getAddressToVendorIndicator()) { // use receiving address shipToInfo.append(" " + po.getReceivingName() + "\n"); shipToInfo.append(" " + po.getReceivingLine1Address() + "\n"); if (StringUtils.isNotBlank(po.getReceivingLine2Address())) { shipToInfo.append(" " + po.getReceivingLine2Address() + "\n"); } shipToInfo.append(" " + po.getReceivingCityName() + ", " + po.getReceivingStateCode() + " " + po.getReceivingPostalCode() + "\n"); if (StringUtils.isNotBlank(po.getReceivingCountryCode()) && !KFSConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(po.getReceivingCountryCode())) { shipToInfo.append(" " + po.getReceivingCountryName() + "\n"); } } else { // use delivery address shipToInfo.append(" " + po.getDeliveryToName() + "\n"); // extra space needed below to separate other text going on same PDF line String deliveryBuildingName = po.getDeliveryBuildingName() + " "; if (po.isDeliveryBuildingOtherIndicator()) { deliveryBuildingName = ""; } shipToInfo .append(" " + deliveryBuildingName + "Room #" + po.getDeliveryBuildingRoomNumber() + "\n"); shipToInfo.append(" " + po.getDeliveryBuildingLine1Address() + "\n"); if (StringUtils.isNotBlank(po.getDeliveryBuildingLine2Address())) { shipToInfo.append(" " + po.getDeliveryBuildingLine2Address() + "\n"); } shipToInfo.append(" " + po.getDeliveryCityName() + ", " + po.getDeliveryStateCode() + " " + po.getDeliveryPostalCode() + "\n"); if (StringUtils.isNotBlank(po.getDeliveryCountryCode()) && !KFSConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(po.getDeliveryCountryCode())) { shipToInfo.append(" " + po.getDeliveryCountryName() + "\n"); } } // display deliveryToPhoneNumber disregard of whether receiving or delivery address is used shipToInfo.append(" " + po.getDeliveryToPhoneNumber()); /* // display deliveryToPhoneNumber based on the parameter indicator, disregard of whether receiving or delivery address is used boolean displayDeliveryPhoneNumber = SpringContext.getBean(ParameterService.class).getIndicatorParameter(PurchaseOrderDocument.class, PurapParameterConstants.DISPLAY_DELIVERY_PHONE_NUMBER_ON_PDF_IND); if (displayDeliveryPhoneNumber && StringUtils.isNotBlank(po.getDeliveryToPhoneNumber())) { shipToInfo.append(" " + po.getDeliveryToPhoneNumber()); } */ p = new Paragraph(); p.add(new Chunk(" Shipping Address", ver_5_normal)); p.add(new Chunk(shipToInfo.toString(), cour_7_normal)); cell = new PdfPCell(p); infoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Shipping Terms\n", ver_5_normal)); if (po.getVendorShippingPaymentTerms() != null && po.getVendorShippingTitle() != null) { p.add(new Chunk(" " + po.getVendorShippingPaymentTerms().getVendorShippingPaymentTermsDescription(), cour_7_normal)); p.add(new Chunk(" - " + po.getVendorShippingTitle().getVendorShippingTitleDescription(), cour_7_normal)); } else if (po.getVendorShippingPaymentTerms() != null && po.getVendorShippingTitle() == null) { p.add(new Chunk(" " + po.getVendorShippingPaymentTerms().getVendorShippingPaymentTermsDescription(), cour_7_normal)); } else if (po.getVendorShippingTitle() != null && po.getVendorShippingPaymentTerms() == null) { p.add(new Chunk(" " + po.getVendorShippingTitle().getVendorShippingTitleDescription(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Payment Terms\n", ver_5_normal)); if (po.getVendorPaymentTerms() != null) { p.add(new Chunk(" " + po.getVendorPaymentTerms().getVendorPaymentTermsDescription(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Delivery Required By\n", ver_5_normal)); if (po.getDeliveryRequiredDate() != null && po.getDeliveryRequiredDateReason() != null) { p.add(new Chunk(" " + sdf.format(po.getDeliveryRequiredDate()), cour_7_normal)); p.add(new Chunk(" - " + po.getDeliveryRequiredDateReason().getDeliveryRequiredDateReasonDescription(), cour_7_normal)); } else if (po.getDeliveryRequiredDate() != null && po.getDeliveryRequiredDateReason() == null) { p.add(new Chunk(" " + sdf.format(po.getDeliveryRequiredDate()), cour_7_normal)); } else if (po.getDeliveryRequiredDate() == null && po.getDeliveryRequiredDateReason() != null) { p.add(new Chunk(" " + po.getDeliveryRequiredDateReason().getDeliveryRequiredDateReasonDescription(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" ", ver_5_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); // Nested table for Order Date, etc. float[] nestedInfoWidths = { 0.50f, 0.50f }; PdfPTable nestedInfoTable = new PdfPTable(nestedInfoWidths); nestedInfoTable.setSplitLate(false); p = new Paragraph(); p.add(new Chunk(" Order Date\n", ver_5_normal)); String orderDate = ""; if (po.getPurchaseOrderInitialOpenTimestamp() != null) { orderDate = sdf.format(po.getPurchaseOrderInitialOpenTimestamp()); } else { // This date isn't set until the first time this document is printed, so will be null the first time; use today's date. orderDate = sdf.format(getDateTimeService().getCurrentSqlDate()); } p.add(new Chunk(" " + orderDate, cour_7_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); nestedInfoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Customer #\n", ver_5_normal)); if (po.getVendorCustomerNumber() != null) { p.add(new Chunk(" " + po.getVendorCustomerNumber(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); nestedInfoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Delivery Instructions\n", ver_5_normal)); if (StringUtils.isNotBlank(po.getDeliveryInstructionText())) { p.add(new Chunk(" " + po.getDeliveryInstructionText(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); nestedInfoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Contract ID\n", ver_5_normal)); if (po.getVendorContract() != null) { p.add(new Chunk(po.getVendorContract().getVendorContractName(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); nestedInfoTable.addCell(cell); // Add the nestedInfoTable to the infoTable cell = new PdfPCell(nestedInfoTable); cell.setHorizontalAlignment(Element.ALIGN_CENTER); infoTable.addCell(cell); StringBuffer billToInfo = new StringBuffer(); billToInfo.append("\n"); billToInfo.append(" " + po.getBillingName() + "\n"); billToInfo.append(" " + po.getBillingLine1Address() + "\n"); if (po.getBillingLine2Address() != null) { billToInfo.append(" " + po.getBillingLine2Address() + "\n"); } billToInfo.append(" " + po.getBillingCityName() + ", " + po.getBillingStateCode() + " " + po.getBillingPostalCode() + "\n"); if (po.getBillingPhoneNumber() != null) { billToInfo.append(" " + po.getBillingPhoneNumber()); } if (po.getBillingEmailAddress() != null) { billToInfo.append("\n " + po.getBillingEmailAddress()); } p = new Paragraph(); p.add(new Chunk(" Billing Address", ver_5_normal)); p.add(new Chunk(" " + billToInfo.toString(), cour_7_normal)); p.add(new Chunk("\n Invoice status inquiry: " + statusInquiryUrl, ver_6_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); document.add(infoTable); PdfPTable notesStipulationsTable = new PdfPTable(1); notesStipulationsTable.setWidthPercentage(100); notesStipulationsTable.setSplitLate(false); p = new Paragraph(); p.add(new Chunk(" Vendor Note(s)\n", ver_5_normal)); if (po.getVendorNoteText() != null) { p.add(new Chunk(" " + po.getVendorNoteText() + "\n", cour_7_normal)); } PdfPCell tableCell = new PdfPCell(p); tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); tableCell.setVerticalAlignment(Element.ALIGN_TOP); notesStipulationsTable.addCell(tableCell); p = new Paragraph(); p.add(new Chunk(" Vendor Stipulations and Information\n", ver_5_normal)); if ((po.getPurchaseOrderBeginDate() != null) && (po.getPurchaseOrderEndDate() != null)) { p.add(new Chunk(" Order in effect from " + sdf.format(po.getPurchaseOrderBeginDate()) + " to " + sdf.format(po.getPurchaseOrderEndDate()) + ".\n", cour_7_normal)); } Collection<PurchaseOrderVendorStipulation> vendorStipulationsList = po.getPurchaseOrderVendorStipulations(); if (vendorStipulationsList.size() > 0) { StringBuffer vendorStipulations = new StringBuffer(); for (PurchaseOrderVendorStipulation povs : vendorStipulationsList) { vendorStipulations.append(" " + povs.getVendorStipulationDescription() + "\n"); } p.add(new Chunk(" " + vendorStipulations.toString(), cour_7_normal)); } tableCell = new PdfPCell(p); tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); tableCell.setVerticalAlignment(Element.ALIGN_TOP); notesStipulationsTable.addCell(tableCell); document.add(notesStipulationsTable); // ***** Items table ***** LOG.debug("createPdf() items table started."); float[] itemsWidths = { 0.07f, 0.1f, 0.07f, 0.45f, 0.15f, 0.15f }; if (!po.isUseTaxIndicator()) { itemsWidths = ArrayUtils.add(itemsWidths, 0.14f); itemsWidths = ArrayUtils.add(itemsWidths, 0.15f); } PdfPTable itemsTable = new PdfPTable(itemsWidths.length); // itemsTable.setCellsFitPage(false); With this set to true a large cell will // skip to the next page. The default Table behaviour seems to be what we want: // start the large cell on the same page and continue it to the next. itemsTable.setWidthPercentage(100); itemsTable.setWidths(itemsWidths); itemsTable.setSplitLate(false); tableCell = new PdfPCell(new Paragraph("Item\nNo.", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("Quantity", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("UOM", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("Description", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("Unit Cost", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("Extended Cost", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); if (!po.isUseTaxIndicator()) { tableCell = new PdfPCell(new Paragraph("Tax Amount", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("Total Amount", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); } Collection<PurchaseOrderItem> itemsList = new ArrayList(); if (isRetransmit) { itemsList = retransmitItems; } else { itemsList = po.getItems(); } for (PurchaseOrderItem poi : itemsList) { if ((poi.getItemType() != null) && (poi.getItemType().isLineItemIndicator() || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) && lineItemDisplaysOnPdf(poi)) { String description = (poi.getItemCatalogNumber() != null) ? poi.getItemCatalogNumber().trim() + " - " : ""; description = description + ((poi.getItemDescription() != null) ? poi.getItemDescription().trim() : ""); if (StringUtils.isNotBlank(description)) { if (poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE)) { // If this is a full order discount or trade-in item, we add the item type description to the description. description = poi.getItemType().getItemTypeDescription() + " - " + description; } } // Above the line item types items display the line number; other types don't. if (poi.getItemType().isLineItemIndicator()) { tableCell = new PdfPCell(new Paragraph(poi.getItemLineNumber().toString(), cour_7_normal)); } else { tableCell = new PdfPCell(new Paragraph(" ", cour_7_normal)); } tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); String quantity = (poi.getItemQuantity() != null) ? poi.getItemQuantity().toString() : " "; tableCell = new PdfPCell(new Paragraph(quantity, cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph(poi.getItemUnitOfMeasureCode(), cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph(" " + description, cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); itemsTable.addCell(tableCell); String unitPrice = poi.getItemUnitPrice().setScale(4, BigDecimal.ROUND_HALF_UP).toString(); tableCell = new PdfPCell(new Paragraph(unitPrice + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); tableCell = new PdfPCell( new Paragraph(numberFormat.format(poi.getExtendedPrice()) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); if (!po.isUseTaxIndicator()) { KualiDecimal taxAmount = poi.getItemTaxAmount(); taxAmount = taxAmount == null ? KualiDecimal.ZERO : taxAmount; tableCell = new PdfPCell(new Paragraph(numberFormat.format(taxAmount) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); tableCell = new PdfPCell( new Paragraph(numberFormat.format(poi.getTotalAmount()) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); } } } // Blank line before totals itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); if (!po.isUseTaxIndicator()) { itemsTable.addCell(" "); itemsTable.addCell(" "); } //Next Line if (!po.isUseTaxIndicator()) { //Print Total Prior to Tax itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); tableCell = new PdfPCell(new Paragraph("Total Prior to Tax: ", ver_10_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); itemsTable.addCell(tableCell); itemsTable.addCell(" "); KualiDecimal totalDollarAmount = new KualiDecimal(BigDecimal.ZERO); if (po instanceof PurchaseOrderRetransmitDocument) { totalDollarAmount = ((PurchaseOrderRetransmitDocument) po) .getTotalPreTaxDollarAmountForRetransmit(); } else { totalDollarAmount = po.getTotalPreTaxDollarAmount(); } tableCell = new PdfPCell(new Paragraph(numberFormat.format(totalDollarAmount) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); //Print Total Tax itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); tableCell = new PdfPCell(new Paragraph("Total Tax: ", ver_10_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); itemsTable.addCell(tableCell); itemsTable.addCell(" "); totalDollarAmount = new KualiDecimal(BigDecimal.ZERO); if (po instanceof PurchaseOrderRetransmitDocument) { totalDollarAmount = ((PurchaseOrderRetransmitDocument) po).getTotalTaxDollarAmountForRetransmit(); } else { totalDollarAmount = po.getTotalTaxAmount(); } tableCell = new PdfPCell(new Paragraph(numberFormat.format(totalDollarAmount) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); } // Totals line; first 3 cols empty itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); if (!po.isUseTaxIndicator()) { itemsTable.addCell(" "); itemsTable.addCell(" "); } tableCell = new PdfPCell(new Paragraph("Total order amount: ", ver_10_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); itemsTable.addCell(tableCell); itemsTable.addCell(" "); KualiDecimal totalDollarAmount = new KualiDecimal(BigDecimal.ZERO); if (po instanceof PurchaseOrderRetransmitDocument) { totalDollarAmount = ((PurchaseOrderRetransmitDocument) po).getTotalDollarAmountForRetransmit(); } else { totalDollarAmount = po.getTotalDollarAmount(); } tableCell = new PdfPCell(new Paragraph(numberFormat.format(totalDollarAmount) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); // Blank line after totals itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); if (!po.isUseTaxIndicator()) { itemsTable.addCell(" "); itemsTable.addCell(" "); } document.add(itemsTable); // Contract language. LOG.debug("createPdf() contract language started."); document.add(new Paragraph(contractLanguage, ver_6_normal)); document.add(new Paragraph("\n", ver_6_normal)); // ***** Signatures table ***** LOG.debug("createPdf() signatures table started."); float[] signaturesWidths = { 0.30f, 0.70f }; PdfPTable signaturesTable = new PdfPTable(signaturesWidths); signaturesTable.setWidthPercentage(100); signaturesTable.setHorizontalAlignment(Element.ALIGN_CENTER); signaturesTable.setSplitLate(false); // Director signature and "for more info" line; only on APOs if (po.getPurchaseOrderAutomaticIndicator()) { // Empty cell. cell = new PdfPCell(new Paragraph(" ", cour_7_normal)); cell.setBorderWidth(0); signaturesTable.addCell(cell); //boolean displayRequestorEmail = true; //SpringContext.getBean(ParameterService.class).getIndicatorParameter(PurchaseOrderDocument.class, PurapParameterConstants.DISPLAY_REQUESTOR_EMAIL_ADDRESS_ON_PDF_IND); if (StringUtils.isBlank(po.getInstitutionContactName()) || StringUtils.isBlank(po.getInstitutionContactPhoneNumber()) || StringUtils.isBlank(po.getInstitutionContactEmailAddress())) { //String emailAddress = displayRequestorEmail ? " " + po.getRequestorPersonEmailAddress() : ""; //p = new Paragraph("For more information contact: " + po.getRequestorPersonName() + " " + po.getRequestorPersonPhoneNumber() + emailAddress, cour_7_normal); p = new Paragraph( "For more information contact: " + po.getRequestorPersonName() + " " + po.getRequestorPersonPhoneNumber() + " " + po.getRequestorPersonEmailAddress(), cour_7_normal); } else { //String emailAddress = displayRequestorEmail ? " " + po.getInstitutionContactEmailAddress() : ""; //p = new Paragraph("For more information contact: " + po.getInstitutionContactName() + " " + po.getInstitutionContactPhoneNumber() + emailAddress, cour_7_normal); p = new Paragraph("For more information contact: " + po.getInstitutionContactName() + " " + po.getInstitutionContactPhoneNumber() + " " + po.getInstitutionContactEmailAddress(), cour_7_normal); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(0); signaturesTable.addCell(cell); Image directorSignature = null; if (StringUtils.isNotBlank(directorSignatureImage)) { try { directorSignature = Image.getInstance(directorSignatureImage); } catch (FileNotFoundException e) { LOG.info("The director signature image [" + directorSignatureImage + "] is not available. Defaulting to the default image."); } } if (directorSignature == null) { // an empty cell if the contract manager signature image is not available. cell = new PdfPCell(); } else { directorSignature.scalePercent(30, 30); cell = new PdfPCell(directorSignature, false); } cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setBorderWidth(0); signaturesTable.addCell(cell); // Empty cell. cell = new PdfPCell(new Paragraph(" ", cour_7_normal)); cell.setBorderWidth(0); signaturesTable.addCell(cell); } // Director name and title; on every pdf. p = new Paragraph(); if (LOG.isDebugEnabled()) { LOG.debug("createPdf() directorName parameter: " + directorName); } if (po.getPurchaseOrderAutomaticIndicator()) { // The signature is on the pdf; use small font. p.add(new Chunk(directorName, ver_6_normal)); } else { // The signature isn't on the pdf; use larger font. p.add(new Chunk(directorName, ver_10_normal)); } p.add(new Chunk("\n" + directorTitle, ver_4_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(0); signaturesTable.addCell(cell); // Contract manager signature, name and phone; only on non-APOs if (!po.getPurchaseOrderAutomaticIndicator()) { Image contractManagerSignature = null; if (StringUtils.isNotBlank(contractManagerSignatureImage)) { try { contractManagerSignature = Image.getInstance(contractManagerSignatureImage); } catch (IOException e) { LOG.info("The contract manager image [" + contractManagerSignatureImage + "] is not available. Defaulting to the default image."); } } if (contractManagerSignature == null) { // an empty cell if the contract manager signature image is not available. cell = new PdfPCell(); } else { contractManagerSignature.scalePercent(15, 15); cell = new PdfPCell(contractManagerSignature, false); } cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setBorderWidth(0); signaturesTable.addCell(cell); // Empty cell. cell = new PdfPCell(new Paragraph(" ", ver_10_normal)); cell.setBorderWidth(0); signaturesTable.addCell(cell); cell = new PdfPCell(new Paragraph(po.getContractManager().getContractManagerName() + " " + po.getContractManager().getContractManagerPhoneNumber(), cour_7_normal)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(0); signaturesTable.addCell(cell); } else { // Empty cell. cell = new PdfPCell(new Paragraph(" ", ver_10_normal)); cell.setBorderWidth(0); signaturesTable.addCell(cell); } document.add(signaturesTable); document.close(); LOG.debug("createPdf()pdf document closed."); }
From source file:org.kuali.ole.module.purap.pdf.PurchaseOrderPdf.java
License:Educational Community License
/** * Create a PDF using the given input parameters. * * @param po The PurchaseOrderDocument to be used to create the pdf. * @param document The pdf document whose margins have already been set. * @param writer The PdfWriter to write the pdf document into. * @param statusInquiryUrl The status inquiry url to be displayed on the pdf document. * @param campusName The campus name to be displayed on the pdf document. * @param contractLanguage The contract language to be displayed on the pdf document. * @param logoImage The logo image file name to be displayed on the pdf document. * @param directorSignatureImage The director signature image to be displayed on the pdf document. * @param directorName The director name to be displayed on the pdf document. * @param directorTitle The director title to be displayed on the pdf document. * @param contractManagerSignatureImage The contract manager signature image to be displayed on the pdf document. * @param isRetransmit The boolean to indicate whether this is for a retransmit purchase order document. * @param environment The current environment used (e.g. DEV if it is a development environment). * @param retransmitItems The items selected by the user to be retransmitted. * @throws DocumentException//from www . java 2 s .c om * @throws IOException */ private void createPdf(PurchaseOrderDocument po, Document document, PdfWriter writer, String statusInquiryUrl, String campusName, String contractLanguage, String logoImage, String directorSignatureImage, String directorName, String directorTitle, String contractManagerSignatureImage, boolean isRetransmit, String environment, List<PurchaseOrderItem> retransmitItems) throws DocumentException, IOException { if (LOG.isInfoEnabled()) { LOG.info("Inside createPdf statement" + "PO:" + po + "Document:" + document + "PdfWriter:" + writer + "StatusInquiryUrl:" + statusInquiryUrl + "Campus Name:" + campusName + "Contract Language" + contractLanguage + "Logo Image:" + logoImage + "Director Signature Image:" + directorSignatureImage + "Director Name" + directorName + "Director Title:" + directorTitle + "Contract Manager Signature Image :" + contractManagerSignatureImage + "isRetransmit" + isRetransmit + "Environment" + environment + "retransmitItems" + retransmitItems); } if (LOG.isDebugEnabled()) { LOG.debug("createPdf() started for po number " + po.getPurapDocumentIdentifier().toString()); } // These have to be set because they are used by the onOpenDocument() and onStartPage() methods. this.campusName = campusName; this.po = po; this.logoImage = logoImage; this.environment = environment; // Code has been changed to get the locale dynamically NumberFormat numberFormat = NumberFormat.getCurrencyInstance(); Collection errors = new ArrayList(); // Date format pattern: MM-dd-yyyy SimpleDateFormat sdf = new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE, Locale.getDefault()); // This turns on the page events that handle the header and page numbers. PurchaseOrderPdf events = new PurchaseOrderPdf().getPageEvents(); writer.setPageEvent(this); // Passing in "this" lets it know about the po, campusName, etc. document.open(); PdfPCell cell; Paragraph p = new Paragraph(); // ***** Info table (vendor, address info) ***** LOG.debug("createPdf() info table started."); float[] infoWidths = { 0.50f, 0.50f }; PdfPTable infoTable = new PdfPTable(infoWidths); infoTable.setWidthPercentage(100); infoTable.setHorizontalAlignment(Element.ALIGN_CENTER); infoTable.setSplitLate(false); StringBuffer vendorInfo = new StringBuffer(); vendorInfo.append("\n"); if (StringUtils.isNotBlank(po.getVendorName())) { vendorInfo.append(" " + po.getVendorName() + "\n"); } vendorInfo.append(" ATTN: " + po.getVendorAttentionName() + "\n"); if (StringUtils.isNotBlank(po.getVendorLine1Address())) { vendorInfo.append(" " + po.getVendorLine1Address() + "\n"); } if (StringUtils.isNotBlank(po.getVendorLine2Address())) { vendorInfo.append(" " + po.getVendorLine2Address() + "\n"); } if (StringUtils.isNotBlank(po.getVendorCityName())) { vendorInfo.append(" " + po.getVendorCityName()); } if (StringUtils.isNotBlank(po.getVendorStateCode())) { vendorInfo.append(", " + po.getVendorStateCode()); } if (StringUtils.isNotBlank(po.getVendorAddressInternationalProvinceName())) { vendorInfo.append(", " + po.getVendorAddressInternationalProvinceName()); } if (StringUtils.isNotBlank(po.getVendorPostalCode())) { vendorInfo.append(" " + po.getVendorPostalCode() + "\n"); } else { vendorInfo.append("\n"); } if (!OLEConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(po.getVendorCountryCode()) && po.getVendorCountry() != null) { vendorInfo.append(" " + po.getVendorCountry().getName() + "\n\n"); } else { vendorInfo.append("\n\n"); } p = new Paragraph(); p.add(new Chunk(" Vendor", ver_5_normal)); p.add(new Chunk(vendorInfo.toString(), cour_7_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); StringBuffer shipToInfo = new StringBuffer(); shipToInfo.append("\n"); if (po.getAddressToVendorIndicator()) { // use receiving address shipToInfo.append(" " + po.getReceivingName() + "\n"); shipToInfo.append(" " + po.getReceivingLine1Address() + "\n"); if (StringUtils.isNotBlank(po.getReceivingLine2Address())) { shipToInfo.append(" " + po.getReceivingLine2Address() + "\n"); } shipToInfo.append(" " + po.getReceivingCityName() + ", " + po.getReceivingStateCode() + " " + po.getReceivingPostalCode() + "\n"); if (StringUtils.isNotBlank(po.getReceivingCountryCode()) && !OLEConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(po.getReceivingCountryCode())) { shipToInfo.append(" " + po.getReceivingCountryName() + "\n"); } } else { // use delivery address shipToInfo.append(" " + po.getDeliveryToName() + "\n"); // extra space needed below to separate other text going on same PDF line String deliveryBuildingName = po.getDeliveryBuildingName() + " "; if (po.isDeliveryBuildingOtherIndicator()) { deliveryBuildingName = ""; } shipToInfo .append(" " + deliveryBuildingName + "Room #" + po.getDeliveryBuildingRoomNumber() + "\n"); shipToInfo.append(" " + po.getDeliveryBuildingLine1Address() + "\n"); if (StringUtils.isNotBlank(po.getDeliveryBuildingLine2Address())) { shipToInfo.append(" " + po.getDeliveryBuildingLine2Address() + "\n"); } shipToInfo.append(" " + po.getDeliveryCityName() + ", " + po.getDeliveryStateCode() + " " + po.getDeliveryPostalCode() + "\n"); if (StringUtils.isNotBlank(po.getDeliveryCountryCode()) && !OLEConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(po.getDeliveryCountryCode())) { shipToInfo.append(" " + po.getDeliveryCountryName() + "\n"); } } // display deliveryToPhoneNumber disregard of whether receiving or delivery address is used shipToInfo.append(" " + po.getDeliveryToPhoneNumber()); /* // display deliveryToPhoneNumber based on the parameter indicator, disregard of whether receiving or delivery address is used boolean displayDeliveryPhoneNumber = SpringContext.getBean(ParameterService.class).getIndicatorParameter(PurchaseOrderDocument.class, PurapParameterConstants.DISPLAY_DELIVERY_PHONE_NUMBER_ON_PDF_IND); if (displayDeliveryPhoneNumber && StringUtils.isNotBlank(po.getDeliveryToPhoneNumber())) { shipToInfo.append(" " + po.getDeliveryToPhoneNumber()); } */ p = new Paragraph(); p.add(new Chunk(" Shipping Address", ver_5_normal)); p.add(new Chunk(shipToInfo.toString(), cour_7_normal)); cell = new PdfPCell(p); infoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Shipping Terms\n", ver_5_normal)); if (po.getVendorShippingPaymentTerms() != null && po.getVendorShippingTitle() != null) { p.add(new Chunk(" " + po.getVendorShippingPaymentTerms().getVendorShippingPaymentTermsDescription(), cour_7_normal)); p.add(new Chunk(" - " + po.getVendorShippingTitle().getVendorShippingTitleDescription(), cour_7_normal)); } else if (po.getVendorShippingPaymentTerms() != null && po.getVendorShippingTitle() == null) { p.add(new Chunk(" " + po.getVendorShippingPaymentTerms().getVendorShippingPaymentTermsDescription(), cour_7_normal)); } else if (po.getVendorShippingTitle() != null && po.getVendorShippingPaymentTerms() == null) { p.add(new Chunk(" " + po.getVendorShippingTitle().getVendorShippingTitleDescription(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Payment Terms\n", ver_5_normal)); if (po.getVendorPaymentTerms() != null) { p.add(new Chunk(" " + po.getVendorPaymentTerms().getVendorPaymentTermsDescription(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Delivery Required By\n", ver_5_normal)); if (po.getDeliveryRequiredDate() != null && po.getDeliveryRequiredDateReason() != null) { p.add(new Chunk(" " + sdf.format(po.getDeliveryRequiredDate()), cour_7_normal)); p.add(new Chunk(" - " + po.getDeliveryRequiredDateReason().getDeliveryRequiredDateReasonDescription(), cour_7_normal)); } else if (po.getDeliveryRequiredDate() != null && po.getDeliveryRequiredDateReason() == null) { p.add(new Chunk(" " + sdf.format(po.getDeliveryRequiredDate()), cour_7_normal)); } else if (po.getDeliveryRequiredDate() == null && po.getDeliveryRequiredDateReason() != null) { p.add(new Chunk(" " + po.getDeliveryRequiredDateReason().getDeliveryRequiredDateReasonDescription(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" ", ver_5_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); // Nested table for Order Date, etc. float[] nestedInfoWidths = { 0.50f, 0.50f }; PdfPTable nestedInfoTable = new PdfPTable(nestedInfoWidths); nestedInfoTable.setSplitLate(false); p = new Paragraph(); p.add(new Chunk(" Order Date\n", ver_5_normal)); String orderDate = ""; if (po.getPurchaseOrderInitialOpenTimestamp() != null) { orderDate = sdf.format(po.getPurchaseOrderInitialOpenTimestamp()); } else { // This date isn't set until the first time this document is printed, so will be null the first time; use today's date. orderDate = sdf.format(getDateTimeService().getCurrentSqlDate()); } p.add(new Chunk(" " + orderDate, cour_7_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); nestedInfoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Customer #\n", ver_5_normal)); if (po.getVendorCustomerNumber() != null) { p.add(new Chunk(" " + po.getVendorCustomerNumber(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); nestedInfoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Delivery Instructions\n", ver_5_normal)); if (StringUtils.isNotBlank(po.getDeliveryInstructionText())) { p.add(new Chunk(" " + po.getDeliveryInstructionText(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); nestedInfoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk(" Contract ID\n", ver_5_normal)); if (po.getVendorContract() != null) { p.add(new Chunk(po.getVendorContract().getVendorContractName(), cour_7_normal)); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); nestedInfoTable.addCell(cell); // Add the nestedInfoTable to the infoTable cell = new PdfPCell(nestedInfoTable); cell.setHorizontalAlignment(Element.ALIGN_CENTER); infoTable.addCell(cell); StringBuffer billToInfo = new StringBuffer(); billToInfo.append("\n"); billToInfo.append(" " + po.getBillingName() + "\n"); billToInfo.append(" " + po.getBillingLine1Address() + "\n"); if (po.getBillingLine2Address() != null) { billToInfo.append(" " + po.getBillingLine2Address() + "\n"); } billToInfo.append(" " + po.getBillingCityName() + ", " + po.getBillingStateCode() + " " + po.getBillingPostalCode() + "\n"); if (po.getBillingPhoneNumber() != null) { billToInfo.append(" " + po.getBillingPhoneNumber()); } if (po.getBillingEmailAddress() != null) { billToInfo.append("\n " + po.getBillingEmailAddress()); } p = new Paragraph(); p.add(new Chunk(" Billing Address", ver_5_normal)); p.add(new Chunk(" " + billToInfo.toString(), cour_7_normal)); p.add(new Chunk("\n Invoice status inquiry: " + statusInquiryUrl, ver_6_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); document.add(infoTable); PdfPTable notesStipulationsTable = new PdfPTable(1); notesStipulationsTable.setWidthPercentage(100); notesStipulationsTable.setSplitLate(false); p = new Paragraph(); p.add(new Chunk(" Vendor Note(s)\n", ver_5_normal)); if (po.getVendorNoteText() != null) { p.add(new Chunk(" " + po.getVendorNoteText() + "\n", cour_7_normal)); } PdfPCell tableCell = new PdfPCell(p); tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); tableCell.setVerticalAlignment(Element.ALIGN_TOP); notesStipulationsTable.addCell(tableCell); p = new Paragraph(); p.add(new Chunk(" Vendor Stipulations and Information\n", ver_5_normal)); if ((po.getPurchaseOrderBeginDate() != null) && (po.getPurchaseOrderEndDate() != null)) { p.add(new Chunk(" Order in effect from " + sdf.format(po.getPurchaseOrderBeginDate()) + " to " + sdf.format(po.getPurchaseOrderEndDate()) + ".\n", cour_7_normal)); } Collection<PurchaseOrderVendorStipulation> vendorStipulationsList = po.getPurchaseOrderVendorStipulations(); if (vendorStipulationsList.size() > 0) { StringBuffer vendorStipulations = new StringBuffer(); for (PurchaseOrderVendorStipulation povs : vendorStipulationsList) { vendorStipulations.append(" " + povs.getVendorStipulationDescription() + "\n"); } p.add(new Chunk(" " + vendorStipulations.toString(), cour_7_normal)); } tableCell = new PdfPCell(p); tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); tableCell.setVerticalAlignment(Element.ALIGN_TOP); notesStipulationsTable.addCell(tableCell); document.add(notesStipulationsTable); // ***** Items table ***** LOG.debug("createPdf() items table started."); float[] itemsWidths = { 0.07f, 0.1f, 0.07f, 0.25f, 0.25f, 0.10f, 0.10f }; if (!po.isUseTaxIndicator()) { itemsWidths = ArrayUtils.add(itemsWidths, 0.14f); itemsWidths = ArrayUtils.add(itemsWidths, 0.15f); } PdfPTable itemsTable = new PdfPTable(itemsWidths.length); // itemsTable.setCellsFitPage(false); With this set to true a large cell will // skip to the next page. The default Table behaviour seems to be what we want: // start the large cell on the same page and continue it to the next. itemsTable.setWidthPercentage(100); itemsTable.setWidths(itemsWidths); itemsTable.setSplitLate(false); tableCell = new PdfPCell(new Paragraph("Item\nNo.", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("Quantity", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("UOM", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("Description", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("Special Instructions", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("Unit Cost", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("Extended Cost", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); if (!po.isUseTaxIndicator()) { tableCell = new PdfPCell(new Paragraph("Tax Amount", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph("Total Amount", ver_5_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); } Collection<PurchaseOrderItem> itemsList = new ArrayList(); if (isRetransmit) { itemsList = retransmitItems; } else { itemsList = po.getItems(); } for (PurchaseOrderItem poi : itemsList) { if ((poi.getItemType() != null) && (poi.getItemType().isLineItemIndicator() || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) && lineItemDisplaysOnPdf(poi)) { boolean noteFlag = true; String description = (poi.getItemCatalogNumber() != null) ? poi.getItemCatalogNumber().trim() + " - " : ""; String vendorNotes = ""; if (poi.getNotes().size() > 0) { for (OleNotes oleNotes : poi.getNotes()) { String note = getNoteType(oleNotes.getNoteTypeId()); if ((note != null && note.equals(OLEConstants.VENDOR_TYPE)) && noteFlag) { vendorNotes = oleNotes.getNote(); noteFlag = false; } } } description = description + ((poi.getItemDescription() != null) ? poi.getItemDescription().trim() : ""); if (StringUtils.isNotBlank(description)) { if (poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) || poi.getItemType().getItemTypeCode() .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE)) { // If this is a full order discount or trade-in item, we add the item type description to the description. description = poi.getItemType().getItemTypeDescription() + " - " + description; } } // Above the line item types items display the line number; other types don't. if (poi.getItemType().isLineItemIndicator()) { tableCell = new PdfPCell(new Paragraph(poi.getItemLineNumber().toString(), cour_7_normal)); } else { tableCell = new PdfPCell(new Paragraph(" ", cour_7_normal)); } tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); String quantity = (poi.getItemQuantity() != null) ? poi.getItemQuantity().toString() : " "; tableCell = new PdfPCell(new Paragraph(quantity, cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph(poi.getItemUnitOfMeasureCode(), cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph(" " + description, cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); itemsTable.addCell(tableCell); tableCell = new PdfPCell(new Paragraph(" " + vendorNotes, cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); itemsTable.addCell(tableCell); String unitPrice = poi.getItemUnitPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString(); tableCell = new PdfPCell(new Paragraph(unitPrice + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); tableCell = new PdfPCell( new Paragraph(numberFormat.format(poi.getExtendedPrice()) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); if (!po.isUseTaxIndicator()) { KualiDecimal taxAmount = poi.getItemTaxAmount(); taxAmount = taxAmount == null ? KualiDecimal.ZERO : taxAmount; tableCell = new PdfPCell(new Paragraph(numberFormat.format(taxAmount) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); tableCell = new PdfPCell( new Paragraph(numberFormat.format(poi.getTotalAmount()) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); } } } // Blank line before totals itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); if (!po.isUseTaxIndicator()) { itemsTable.addCell(" "); itemsTable.addCell(" "); } //Next Line if (!po.isUseTaxIndicator()) { //Print Total Prior to Tax itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); tableCell = new PdfPCell(new Paragraph("Total Prior to Tax: ", ver_10_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); itemsTable.addCell(tableCell); itemsTable.addCell(" "); KualiDecimal totalDollarAmount = new KualiDecimal(BigDecimal.ZERO); if (po instanceof PurchaseOrderRetransmitDocument) { totalDollarAmount = ((PurchaseOrderRetransmitDocument) po) .getTotalPreTaxDollarAmountForRetransmit(); } else { totalDollarAmount = po.getTotalPreTaxDollarAmount(); } tableCell = new PdfPCell(new Paragraph(numberFormat.format(totalDollarAmount) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); //Print Total Tax itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); tableCell = new PdfPCell(new Paragraph("Total Tax: ", ver_10_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); itemsTable.addCell(tableCell); itemsTable.addCell(" "); totalDollarAmount = new KualiDecimal(BigDecimal.ZERO); if (po instanceof PurchaseOrderRetransmitDocument) { totalDollarAmount = ((PurchaseOrderRetransmitDocument) po).getTotalTaxDollarAmountForRetransmit(); } else { totalDollarAmount = po.getTotalTaxAmount(); } tableCell = new PdfPCell(new Paragraph(numberFormat.format(totalDollarAmount) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); } // Totals line; first 5 cols empty itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); if (!po.isUseTaxIndicator()) { itemsTable.addCell(" "); itemsTable.addCell(" "); } tableCell = new PdfPCell(new Paragraph("Total order amount: ", ver_10_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); itemsTable.addCell(tableCell); itemsTable.addCell(" "); KualiDecimal totalDollarAmount = new KualiDecimal(BigDecimal.ZERO); if (po instanceof PurchaseOrderRetransmitDocument) { totalDollarAmount = ((PurchaseOrderRetransmitDocument) po).getTotalDollarAmountForRetransmit(); } else { totalDollarAmount = po.getTotalDollarAmount(); } tableCell = new PdfPCell(new Paragraph(numberFormat.format(totalDollarAmount) + " ", cour_7_normal)); tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableCell.setNoWrap(true); itemsTable.addCell(tableCell); // Blank line after totals itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); if (!po.isUseTaxIndicator()) { itemsTable.addCell(" "); itemsTable.addCell(" "); } document.add(itemsTable); // Contract language. LOG.debug("createPdf() contract language started."); document.add(new Paragraph(contractLanguage, ver_6_normal)); document.add(new Paragraph("\n", ver_6_normal)); // ***** Signatures table ***** LOG.debug("createPdf() signatures table started."); float[] signaturesWidths = { 0.30f, 0.70f }; PdfPTable signaturesTable = new PdfPTable(signaturesWidths); signaturesTable.setWidthPercentage(100); signaturesTable.setHorizontalAlignment(Element.ALIGN_CENTER); signaturesTable.setSplitLate(false); // Director signature and "for more info" line; only on APOs if (po.getPurchaseOrderAutomaticIndicator()) { // Empty cell. cell = new PdfPCell(new Paragraph(" ", cour_7_normal)); cell.setBorderWidth(0); signaturesTable.addCell(cell); //boolean displayRequestorEmail = true; //SpringContext.getBean(ParameterService.class).getIndicatorParameter(PurchaseOrderDocument.class, PurapParameterConstants.DISPLAY_REQUESTOR_EMAIL_ADDRESS_ON_PDF_IND); if (StringUtils.isBlank(po.getInstitutionContactName()) || StringUtils.isBlank(po.getInstitutionContactPhoneNumber()) || StringUtils.isBlank(po.getInstitutionContactEmailAddress())) { //String emailAddress = displayRequestorEmail ? " " + po.getRequestorPersonEmailAddress() : ""; //p = new Paragraph("For more information contact: " + po.getRequestorPersonName() + " " + po.getRequestorPersonPhoneNumber() + emailAddress, cour_7_normal); p = new Paragraph( "For more information contact: " + po.getRequestorPersonName() + " " + po.getRequestorPersonPhoneNumber() + " " + po.getRequestorPersonEmailAddress(), cour_7_normal); } else { //String emailAddress = displayRequestorEmail ? " " + po.getInstitutionContactEmailAddress() : ""; //p = new Paragraph("For more information contact: " + po.getInstitutionContactName() + " " + po.getInstitutionContactPhoneNumber() + emailAddress, cour_7_normal); p = new Paragraph("For more information contact: " + po.getInstitutionContactName() + " " + po.getInstitutionContactPhoneNumber() + " " + po.getInstitutionContactEmailAddress(), cour_7_normal); } cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(0); signaturesTable.addCell(cell); Image directorSignature = null; if (StringUtils.isNotBlank(directorSignatureImage)) { try { directorSignature = Image.getInstance(directorSignatureImage); } catch (FileNotFoundException e) { LOG.info("The director signature image [" + directorSignatureImage + "] is not available. Defaulting to the default image."); } } if (directorSignature == null) { // an empty cell if the contract manager signature image is not available. cell = new PdfPCell(); } else { directorSignature.scalePercent(30, 30); cell = new PdfPCell(directorSignature, false); } cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setBorderWidth(0); signaturesTable.addCell(cell); // Empty cell. cell = new PdfPCell(new Paragraph(" ", cour_7_normal)); cell.setBorderWidth(0); signaturesTable.addCell(cell); } // Director name and title; on every pdf. p = new Paragraph(); if (LOG.isDebugEnabled()) { LOG.debug("createPdf() directorName parameter: " + directorName); } if (po.getPurchaseOrderAutomaticIndicator()) { // The signature is on the pdf; use small font. p.add(new Chunk(directorName, ver_6_normal)); } else { // The signature isn't on the pdf; use larger font. p.add(new Chunk(directorName, ver_10_normal)); } p.add(new Chunk("\n" + directorTitle, ver_4_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(0); signaturesTable.addCell(cell); // Contract manager signature, name and phone; only on non-APOs if (!po.getPurchaseOrderAutomaticIndicator()) { Image contractManagerSignature = null; if (StringUtils.isNotBlank(contractManagerSignatureImage)) { try { contractManagerSignature = Image.getInstance(contractManagerSignatureImage); } catch (FileNotFoundException e) { LOG.info("The contract manager image [" + contractManagerSignatureImage + "] is not available. Defaulting to the default image."); } } if (contractManagerSignature == null) { // an empty cell if the contract manager signature image is not available. cell = new PdfPCell(); } else { contractManagerSignature.scalePercent(15, 15); cell = new PdfPCell(contractManagerSignature, false); } cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setBorderWidth(0); signaturesTable.addCell(cell); // Empty cell. cell = new PdfPCell(new Paragraph(" ", ver_10_normal)); cell.setBorderWidth(0); signaturesTable.addCell(cell); cell = new PdfPCell(new Paragraph(po.getContractManager().getContractManagerName() + " " + po.getContractManager().getContractManagerPhoneNumber(), cour_7_normal)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setBorderWidth(0); signaturesTable.addCell(cell); } else { // Empty cell. cell = new PdfPCell(new Paragraph(" ", ver_10_normal)); cell.setBorderWidth(0); signaturesTable.addCell(cell); } document.add(signaturesTable); document.close(); LOG.debug("createPdf()pdf document closed."); }
From source file:org.odftoolkit.odfdom.converter.internal.itext.StyleEngineForIText.java
License:Open Source License
@Override public void visit(StyleTableCellPropertiesElement ele) { StyleTableCellProperties tableCellProperties = currentStyle.getTableCellProperties(); if (tableCellProperties == null) { tableCellProperties = new StyleTableCellProperties(); currentStyle.setTableCellProperties(tableCellProperties); }// w ww. j a v a 2 s. c o m // background-color String backgroundColor = ele.getFoBackgroundColorAttribute(); if (StringUtils.isNotEmpty(backgroundColor)) { tableCellProperties.setBackgroundColor(ColorRegistry.getInstance().getColor(backgroundColor)); } // border String border = ele.getFoBorderAttribute(); if (StringUtils.isNotEmpty(border)) { tableCellProperties.setBorder(new StyleBorder(border, BorderType.ALL)); } // border-bottom String borderBottom = ele.getFoBorderBottomAttribute(); if (StringUtils.isNotEmpty(borderBottom)) { tableCellProperties.setBorderBottom(new StyleBorder(borderBottom, BorderType.BOTTOM)); } // border-left String borderLeft = ele.getFoBorderLeftAttribute(); if (StringUtils.isNotEmpty(borderLeft)) { tableCellProperties.setBorderLeft(new StyleBorder(borderLeft, BorderType.LEFT)); } // border-bottom String borderRight = ele.getFoBorderRightAttribute(); if (StringUtils.isNotEmpty(borderRight)) { tableCellProperties.setBorderRight(new StyleBorder(borderRight, BorderType.RIGHT)); } // border-top String borderTop = ele.getFoBorderTopAttribute(); if (StringUtils.isNotEmpty(borderTop)) { tableCellProperties.setBorderTop(new StyleBorder(borderTop, BorderType.TOP)); } // padding String padding = ele.getFoPaddingAttribute(); if (StringUtils.isNotEmpty(padding)) { tableCellProperties.setPadding(ODFUtils.getDimensionAsPoint(padding)); } // padding-bottom String paddingBottom = ele.getFoPaddingBottomAttribute(); if (StringUtils.isNotEmpty(paddingBottom)) { tableCellProperties.setPaddingBottom(ODFUtils.getDimensionAsPoint(paddingBottom)); } // padding-left String paddingLeft = ele.getFoPaddingLeftAttribute(); if (StringUtils.isNotEmpty(paddingLeft)) { tableCellProperties.setPaddingLeft(ODFUtils.getDimensionAsPoint(paddingLeft)); } // padding-right String paddingRight = ele.getFoPaddingRightAttribute(); if (StringUtils.isNotEmpty(paddingRight)) { tableCellProperties.setPaddingRight(ODFUtils.getDimensionAsPoint(paddingRight)); } // padding-top String paddingTop = ele.getFoPaddingTopAttribute(); if (StringUtils.isNotEmpty(paddingTop)) { tableCellProperties.setPaddingTop(ODFUtils.getDimensionAsPoint(paddingTop)); } // vertical-align String verticalAlign = ele.getStyleVerticalAlignAttribute(); if (StringUtils.isNotEmpty(verticalAlign)) { if (BASELINE.equals(verticalAlign)) { tableCellProperties.setVerticalAlignment(Element.ALIGN_BASELINE); } else if (TOP.equals(verticalAlign)) { tableCellProperties.setVerticalAlignment(Element.ALIGN_TOP); } else if (MIDDLE.equals(verticalAlign)) { tableCellProperties.setVerticalAlignment(Element.ALIGN_MIDDLE); } else if (BOTTOM.equals(verticalAlign)) { tableCellProperties.setVerticalAlignment(Element.ALIGN_BOTTOM); } } super.visit(ele); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.helper.RTFPrinter.java
License:Open Source License
private void computeCellStyle(final RenderBox content, final Cell cell) { final ElementAlignment verticalAlign = content.getNodeLayoutProperties().getVerticalAlignment(); if (ElementAlignment.BOTTOM.equals(verticalAlign)) { cell.setVerticalAlignment(Element.ALIGN_BOTTOM); } else if (ElementAlignment.MIDDLE.equals(verticalAlign)) { cell.setVerticalAlignment(Element.ALIGN_MIDDLE); } else {//from ww w.jav a 2 s.c om cell.setVerticalAlignment(Element.ALIGN_TOP); } final ElementAlignment textAlign = (ElementAlignment) content.getStyleSheet() .getStyleProperty(ElementStyleKeys.ALIGNMENT); if (ElementAlignment.RIGHT.equals(textAlign)) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else if (ElementAlignment.JUSTIFY.equals(textAlign)) { cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); } else if (ElementAlignment.CENTER.equals(textAlign)) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.setHorizontalAlignment(Element.ALIGN_LEFT); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfCell.java
License:Open Source License
/** * Write the cell definition part of this PatchRtfCell *//*w w w . j a v a 2s. c om*/ public void writeDefinition(final OutputStream result) throws IOException { if (this.mergeType == MERGE_VERT_PARENT) { result.write(DocWriter.getISOBytes("\\clvmgf")); } else if (this.mergeType == MERGE_VERT_CHILD) { result.write(DocWriter.getISOBytes("\\clvmrg")); } switch (verticalAlignment) { case Element.ALIGN_BOTTOM: result.write(DocWriter.getISOBytes("\\clvertalb")); break; case Element.ALIGN_CENTER: case Element.ALIGN_MIDDLE: result.write(DocWriter.getISOBytes("\\clvertalc")); break; case Element.ALIGN_TOP: result.write(DocWriter.getISOBytes("\\clvertalt")); break; } this.borders.writeContent(result); if (this.backgroundColor != null) { result.write(DocWriter.getISOBytes("\\clcbpat")); result.write(intToByteArray(this.backgroundColor.getColorNumber())); } this.document.outputDebugLinebreak(result); result.write(DocWriter.getISOBytes("\\clftsWidth3")); this.document.outputDebugLinebreak(result); result.write(DocWriter.getISOBytes("\\clwWidth")); result.write(intToByteArray(this.cellWidth)); this.document.outputDebugLinebreak(result); if (this.cellPadding > 0) { result.write(DocWriter.getISOBytes("\\clpadl")); result.write(intToByteArray(this.cellPadding / 2)); result.write(DocWriter.getISOBytes("\\clpadt")); result.write(intToByteArray(this.cellPadding / 2)); result.write(DocWriter.getISOBytes("\\clpadr")); result.write(intToByteArray(this.cellPadding / 2)); result.write(DocWriter.getISOBytes("\\clpadb")); result.write(intToByteArray(this.cellPadding / 2)); result.write(DocWriter.getISOBytes("\\clpadfl3")); result.write(DocWriter.getISOBytes("\\clpadft3")); result.write(DocWriter.getISOBytes("\\clpadfr3")); result.write(DocWriter.getISOBytes("\\clpadfb3")); } result.write(DocWriter.getISOBytes("\\cellx")); result.write(intToByteArray(this.cellRight)); }
From source file:org.posterita.core.CrossTabReportGenerator.java
License:Open Source License
protected void writeDocument(Document document) throws OperationException { try {/* w w w. j a v a2s . co m*/ int noOfRows = dataSource.size(); String longestText = ""; int columnCount = 0; Object[] obj = null; Object[] header = (Object[]) dataSource.get(0); columnCount = header.length; PdfPTable table = new PdfPTable(columnCount); table.setWidthPercentage(100); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setPaddingBottom(5); table.getDefaultCell().setPaddingTop(5); //adding the headers for (int i = 0; i < columnCount; i++) { if (i == 0) { longestText = header[i].toString(); table.addCell(new Paragraph(header[i].toString())); } else { Image img = getTextAsImage(header[i].toString()); img.setRotationDegrees(90); img.setAlignment(Image.ALIGN_BOTTOM); PdfPCell cell = new PdfPCell(img); cell.setPadding(4); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); //cell.setBackgroundColor(new Color(0, 0, 255)); table.addCell(cell); } } //adding the data for (int j = 1; j < noOfRows; j++) { obj = (Object[]) dataSource.get(j); for (int k = 0; k < columnCount; k++) { if (k == 0) { String text = obj[0].toString(); if (new Chunk(text, HEADER_FONT).getWidthPoint() > new Chunk(longestText, HEADER_FONT) .getWidthPoint()) { longestText = text; } Chunk txtck = new Chunk(obj[0].toString(), HEADER_FONT); PdfPCell cell = new PdfPCell(new Paragraph(txtck)); if (j == noOfRows - 1) { cell.setBackgroundColor(new Color(170, 170, 170)); } cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingBottom(5); cell.setPaddingTop(5); cell.setPaddingLeft(5); table.addCell(cell); } else { Chunk txtck = new Chunk(obj[k].toString(), DATA_FONT); if (k == columnCount - 1) { PdfPCell cell = new PdfPCell(new Paragraph(txtck)); cell.setBackgroundColor(new Color(170, 170, 170)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingBottom(5); cell.setPaddingTop(5); table.addCell(cell); } else { PdfPCell cell = new PdfPCell(new Paragraph(txtck)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingBottom(5); cell.setPaddingTop(5); if (j == noOfRows - 1) { cell.setBackgroundColor(new Color(170, 170, 170)); } table.addCell(cell); } } } } //setting table width Chunk dataChk = new Chunk("9999", DATA_FONT); Chunk headerChk = new Chunk(longestText, HEADER_FONT); float dataChkLength = dataChk.getWidthPoint() + 2 * CELLPADDING; float headerChkLength = headerChk.getWidthPoint() + 2 * CELLPADDING; float tableWidth = headerChkLength + dataChkLength * columnCount; float actualTableWidth = document.getPageSize().getWidth() - 2 * MARGIN; float columnWidth = dataChkLength; if (tableWidth < actualTableWidth) { columnWidth = (actualTableWidth - headerChkLength) / (columnCount - 1); } float[] widths = new float[columnCount]; widths[0] = headerChkLength + 2 * CELLPADDING; for (int i = 1; i < columnCount; i++) { widths[i] = columnWidth; } table.setWidths(widths); //writing the table document.add(table); } catch (DocumentException e) { throw new OperationException(e); } }
From source file:org.revager.export.PDFPageEventHelper.java
License:Open Source License
@Override public void onEndPage(PdfWriter writer, Document document) { int columnNumber; try {//from ww w .j a v a2s . co m Rectangle page = document.getPageSize(); float pageWidth = page.getWidth() - document.leftMargin() - document.rightMargin(); /* * Write marks */ setMarks(writer, document); /* * Define fonts */ headBaseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); Font headFont = new Font(headBaseFont, headFontSize); footBaseFont = BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED); Font footFont = new Font(footBaseFont, footFontSize); /* * Cell fill for space between head/foot and content */ PdfPCell cellFill = new PdfPCell(); cellFill.setMinimumHeight(PDFTools.cmToPt(0.8f)); cellFill.setBorderWidth(0); /* * Write head */ if (headLogoPath != null) { columnNumber = 2; } else { columnNumber = 1; } PdfPTable head = new PdfPTable(columnNumber); Phrase phraseTitle = new Phrase(headTitle, headFont); PdfPCell cellTitle = new PdfPCell(phraseTitle); cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT); cellTitle.setVerticalAlignment(Element.ALIGN_BOTTOM); cellTitle.setPaddingTop(0); cellTitle.setPaddingBottom(PDFTools.cmToPt(0.2f)); cellTitle.setPaddingLeft(0); cellTitle.setPaddingRight(0); cellTitle.setBorderWidthTop(0); cellTitle.setBorderWidthBottom(0.5f); cellTitle.setBorderWidthLeft(0); cellTitle.setBorderWidthRight(0); head.addCell(cellTitle); if (headLogoPath != null) { Image headLogo = Image.getInstance(headLogoPath); headLogo.scaleToFit(PDFTools.cmToPt(5.0f), PDFTools.cmToPt(1.1f)); PdfPCell cellLogo = new PdfPCell(headLogo); cellLogo.setHorizontalAlignment(Element.ALIGN_RIGHT); cellLogo.setVerticalAlignment(Element.ALIGN_BOTTOM); cellLogo.setPaddingTop(0); cellLogo.setPaddingBottom(PDFTools.cmToPt(0.15f)); cellLogo.setPaddingLeft(0); cellLogo.setPaddingRight(0); cellLogo.setBorderWidthTop(0); cellLogo.setBorderWidthBottom(0.5f); cellLogo.setBorderWidthLeft(0); cellLogo.setBorderWidthRight(0); head.addCell(cellLogo); head.addCell(cellFill); } head.addCell(cellFill); head.setTotalWidth(pageWidth); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); /* * Write foot */ if (footText == null) { footText = " "; } PdfPTable foot = new PdfPTable(1); foot.addCell(cellFill); PdfPCell cellFootText = new PdfPCell(new Phrase(footText, footFont)); cellFootText.setHorizontalAlignment(Element.ALIGN_RIGHT); cellFootText.setVerticalAlignment(Element.ALIGN_TOP); cellFootText.setPaddingTop(PDFTools.cmToPt(0.15f)); cellFootText.setPaddingBottom(0); cellFootText.setPaddingLeft(0); cellFootText.setPaddingRight(0); cellFootText.setBorderWidthTop(0.5f); cellFootText.setBorderWidthBottom(0); cellFootText.setBorderWidthLeft(0); cellFootText.setBorderWidthRight(0); foot.addCell(cellFootText); /* * Print page numbers */ PdfContentByte contentByte = writer.getDirectContent(); contentByte.saveState(); String text = MessageFormat.format(translate("Page {0} of") + " ", writer.getPageNumber()); float textSize = footBaseFont.getWidthPoint(text, footFontSize); float textBase = document.bottom() - PDFTools.cmToPt(1.26f); contentByte.beginText(); contentByte.setFontAndSize(footBaseFont, footFontSize); float adjust; if (footText.trim().equals("")) { adjust = (pageWidth / 2) - (textSize / 2) - footBaseFont.getWidthPoint("0", footFontSize); } else { adjust = 0; } contentByte.setTextMatrix(document.left() + adjust, textBase); contentByte.showText(text); contentByte.endText(); contentByte.addTemplate(template, document.left() + adjust + textSize, textBase); contentByte.stroke(); contentByte.restoreState(); foot.setTotalWidth(pageWidth); foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent()); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExceptionConverter(e); } }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java
License:Open Source License
/** * Creates and adds the table at the top of the document * which contains the consultation request. */// w w w . j a v a2 s .com private void createConsultationRequest() throws DocumentException { float[] tableWidths = { 1f, 1f }; PdfPTable table = new PdfPTable(1); PdfPCell cell; PdfPTable border, border2, border1; table.setWidthPercentage(95); // Creating a border for the entire request. border = new PdfPTable(1); addToTable(table, border, true); if (props.getProperty("faxLogoInConsultation") != null) { // Creating container for logo and clinic information table. border1 = new PdfPTable(tableWidths); addTable(border, border1); // Adding fax logo PdfPTable infoTable = createLogoHeader(); addToTable(border1, infoTable, false); // Adding clinic information to the border. infoTable = createClinicInfoHeader(); addToTable(border1, infoTable, false); } else { // Adding clinic information to the border. PdfPTable infoTable = createClinicInfoHeader(); addTable(border, infoTable); } // Add reply info PdfPTable infoTable = createReplyHeader(); addTable(border, infoTable); // Creating container for specialist and patient table. border2 = new PdfPTable(tableWidths); addTable(border, border2); // Adding specialist info to container. infoTable = createSpecialistTable(); addToTable(border2, infoTable, true); // Adding patient info to main table. infoTable = createPatientTable(); addToTable(border2, infoTable, true); // Creating a table with details for the consultation request. infoTable = createConsultDetailTable(); // Adding promotional information if appropriate. if (props.getProperty("FORMS_PROMOTEXT") != null) { cell = new PdfPCell(new Phrase(props.getProperty(""), font)); cell.setBorder(0); infoTable.addCell(cell); cell.setPhrase(new Phrase(props.getProperty("FORMS_PROMOTEXT"), font)); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setHorizontalAlignment(Element.ALIGN_CENTER); infoTable.addCell(cell); } // Adding details and promotional information. addTable(border, infoTable); document.add(table); }
From source file:ro.nextreports.engine.exporter.RtfExporter.java
License:Apache License
private void setCellStyle(Font fnt, Map<String, Object> style, RtfCell cell) { if (style != null) { updateFont(fnt, style);/* ww w . ja v a 2s . c o m*/ if (style.containsKey(StyleFormatConstants.BACKGROUND_COLOR)) { Color val = (Color) style.get(StyleFormatConstants.BACKGROUND_COLOR); cell.setBackgroundColor(val); } if (style.containsKey(StyleFormatConstants.HORIZONTAL_ALIGN_KEY)) { if (StyleFormatConstants.HORIZONTAL_ALIGN_LEFT .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(Element.ALIGN_LEFT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_RIGHT .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_CENTER .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); } } if (style.containsKey(StyleFormatConstants.VERTICAL_ALIGN_KEY)) { if (StyleFormatConstants.VERTICAL_ALIGN_TOP .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_TOP); } if (StyleFormatConstants.VERTICAL_ALIGN_MIDDLE .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_MIDDLE); } if (StyleFormatConstants.VERTICAL_ALIGN_BOTTOM .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { cell.setVerticalAlignment(Element.ALIGN_BOTTOM); } } // if (style.containsKey(StyleFormatConstants.PADDING_LEFT)) { // Float val = (Float) style.get(StyleFormatConstants.PADDING_LEFT); // cell.setPaddingLeft(val); // } // if (style.containsKey(StyleFormatConstants.PADDING_RIGHT)) { // Float val = (Float) // style.get(StyleFormatConstants.PADDING_RIGHT); // cell.setPaddingRight(val); // } // if (style.containsKey(StyleFormatConstants.PADDING_TOP)) { // Float val = (Float) style.get(StyleFormatConstants.PADDING_TOP); // cell.setPaddingTop(val); // } // if (style.containsKey(StyleFormatConstants.PADDING_BOTTOM)) { // Float val = (Float) // style.get(StyleFormatConstants.PADDING_BOTTOM); // cell.setPaddingBottom(val); // } cell.setBorderWidth(0); Float val = Float.valueOf(1); RtfBorderGroup bg = new RtfBorderGroup(); if (style.containsKey(StyleFormatConstants.BORDER_LEFT)) { val = (Float) style.get(StyleFormatConstants.BORDER_LEFT); Color color = (Color) style.get(StyleFormatConstants.BORDER_LEFT_COLOR); bg.addBorder(Rectangle.LEFT, RtfBorder.BORDER_SINGLE, val, color); } if (style.containsKey(StyleFormatConstants.BORDER_RIGHT)) { val = (Float) style.get(StyleFormatConstants.BORDER_RIGHT); Color color = (Color) style.get(StyleFormatConstants.BORDER_RIGHT_COLOR); bg.addBorder(Rectangle.RIGHT, RtfBorder.BORDER_SINGLE, val, color); } if (style.containsKey(StyleFormatConstants.BORDER_TOP)) { val = (Float) style.get(StyleFormatConstants.BORDER_TOP); Color color = (Color) style.get(StyleFormatConstants.BORDER_TOP_COLOR); bg.addBorder(Rectangle.TOP, RtfBorder.BORDER_SINGLE, val, color); } if (style.containsKey(StyleFormatConstants.BORDER_BOTTOM)) { val = (Float) style.get(StyleFormatConstants.BORDER_BOTTOM); Color color = (Color) style.get(StyleFormatConstants.BORDER_BOTTOM_COLOR); bg.addBorder(Rectangle.BOTTOM, RtfBorder.BORDER_SINGLE, val, color); } cell.setBorders(bg); // cell.setNoWrap(true); // if (bandElement != null) { // if (bandElement.isWrapText()) { // cell.setNoWrap(false); // } // } } }