List of usage examples for com.lowagie.text Element ALIGN_RIGHT
int ALIGN_RIGHT
To view the source code for com.lowagie.text Element ALIGN_RIGHT.
Click Source Link
From source file:org.kuali.kfs.module.purap.pdf.PurchaseOrderQuotePdf.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 poqv The PurchaseOrderVendorQuote to be used to generate the pdf. * @param campusName The campus name to be used to generate the pdf. * @param contractManagerCampusCode The contract manager campus code to be used to generate the pdf. * @param logoImage The logo image file name to be used to generate the pdf. * @param document The pdf document whose margins have already been set. * @param writer The PdfWriter to write the pdf document into. * @param environment The current environment used (e.g. DEV if it is a development environment). * @throws DocumentException//from w w w . jav a 2 s . com */ private void createPOQuotePdf(PurchaseOrderDocument po, PurchaseOrderVendorQuote poqv, String campusName, String contractManagerCampusCode, String logoImage, Document document, PdfWriter writer, String environment) throws DocumentException { if (LOG.isDebugEnabled()) { LOG.debug("createQuotePdf() started for po number " + po.getPurapDocumentIdentifier()); } // 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); // Date format pattern: MM-dd-yyyy SimpleDateFormat sdf = PurApDateFormatUtils .getSimpleDateFormat(PurapConstants.NamedDateFormats.KUALI_SIMPLE_DATE_FORMAT_2); CampusParameter campusParameter = getCampusParameter(contractManagerCampusCode); String purchasingAddressFull = getPurchasingAddressFull(campusParameter); // Turn on the page events that handle the header and page numbers. PurchaseOrderQuotePdf events = new PurchaseOrderQuotePdf().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 (address, vendor, other info) ***** LOG.debug("createQuotePdf() info table started."); float[] infoWidths = { 0.45f, 0.55f }; PdfPTable infoTable = new PdfPTable(infoWidths); infoTable.setWidthPercentage(100); infoTable.setHorizontalAlignment(Element.ALIGN_CENTER); infoTable.setSplitLate(false); p = new Paragraph(); ContractManager contractManager = po.getContractManager(); p.add(new Chunk("\n Return this form to:\n", ver_8_bold)); p.add(new Chunk(purchasingAddressFull + "\n", cour_10_normal)); p.add(new Chunk("\n", cour_10_normal)); p.add(new Chunk(" Fax #: ", ver_6_normal)); p.add(new Chunk(contractManager.getContractManagerFaxNumber() + "\n", cour_10_normal)); p.add(new Chunk(" Contract Manager: ", ver_6_normal)); p.add(new Chunk(contractManager.getContractManagerName() + " " + contractManager.getContractManagerPhoneNumber() + "\n", cour_10_normal)); p.add(new Chunk("\n", cour_10_normal)); p.add(new Chunk(" To:\n", ver_6_normal)); StringBuffer vendorInfo = new StringBuffer(); if (StringUtils.isNotBlank(poqv.getVendorAttentionName())) { vendorInfo.append(" ATTN: " + poqv.getVendorAttentionName().trim() + "\n"); } vendorInfo.append(" " + poqv.getVendorName() + "\n"); if (StringUtils.isNotBlank(poqv.getVendorLine1Address())) { vendorInfo.append(" " + poqv.getVendorLine1Address() + "\n"); } if (StringUtils.isNotBlank(poqv.getVendorLine2Address())) { vendorInfo.append(" " + poqv.getVendorLine2Address() + "\n"); } if (StringUtils.isNotBlank(poqv.getVendorCityName())) { vendorInfo.append(" " + poqv.getVendorCityName()); } if ((StringUtils.isNotBlank(poqv.getVendorStateCode())) && (!poqv.getVendorStateCode().equals("--"))) { vendorInfo.append(", " + poqv.getVendorStateCode()); } if (StringUtils.isNotBlank(poqv.getVendorAddressInternationalProvinceName())) { vendorInfo.append(", " + poqv.getVendorAddressInternationalProvinceName()); } if (StringUtils.isNotBlank(poqv.getVendorPostalCode())) { vendorInfo.append(" " + poqv.getVendorPostalCode() + "\n"); } else { vendorInfo.append("\n"); } if (!KFSConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(poqv.getVendorCountryCode()) && poqv.getVendorCountryCode() != null) { vendorInfo.append(" " + poqv.getVendorCountry().getName() + "\n\n"); } else { vendorInfo.append(" \n\n"); } p.add(new Chunk(vendorInfo.toString(), cour_10_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk("\n R.Q. Number: ", ver_8_bold)); p.add(new Chunk(po.getPurapDocumentIdentifier() + "\n", cour_10_normal)); java.sql.Date requestDate = getDateTimeService().getCurrentSqlDate(); if (poqv.getPurchaseOrderQuoteTransmitTimestamp() != null) { try { requestDate = getDateTimeService().convertToSqlDate(poqv.getPurchaseOrderQuoteTransmitTimestamp()); } catch (ParseException e) { throw new RuntimeException( "ParseException thrown when trying to convert from Timestamp to SqlDate.", e); } } p.add(new Chunk(" R.Q. Date: ", ver_8_bold)); p.add(new Chunk(sdf.format(requestDate) + "\n", cour_10_normal)); p.add(new Chunk(" RESPONSE MUST BE RECEIVED BY: ", ver_8_bold)); if (po.getPurchaseOrderQuoteDueDate() != null) { p.add(new Chunk(sdf.format(po.getPurchaseOrderQuoteDueDate()) + "\n\n", cour_10_normal)); } else { p.add(new Chunk("N/A\n\n", cour_10_normal)); } // retrieve the quote stipulations StringBuffer quoteStipulations = getPoQuoteLanguage(); p.add(new Chunk(quoteStipulations.toString(), ver_6_normal)); p.add(new Chunk("\n ALL QUOTES MUST BE TOTALED", ver_12_normal)); cell = new PdfPCell(p); infoTable.addCell(cell); document.add(infoTable); // ***** Notes and Stipulations table ***** // The notes and stipulations table is type Table instead of PdfPTable // because Table has the method setCellsFitPage and I can't find an equivalent // in PdfPTable. Long notes or stipulations would break to the next page, leaving // a large white space on the previous page. PdfPTable notesStipulationsTable = new PdfPTable(1); notesStipulationsTable.setWidthPercentage(100); notesStipulationsTable.setSplitLate(false); p = new Paragraph(); p.add(new Chunk(" Vendor Stipulations and Information\n\n", ver_6_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_10_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_10_normal)); } PdfPCell tableCell = new PdfPCell(p); tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); tableCell.setVerticalAlignment(Element.ALIGN_TOP); notesStipulationsTable.addCell(tableCell); document.add(notesStipulationsTable); // ***** Items table ***** LOG.debug("createQuotePdf() items table started."); float[] itemsWidths = { 0.07f, 0.1f, 0.07f, 0.50f, 0.13f, 0.13f }; PdfPTable itemsTable = new PdfPTable(6); // 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 = createCell("Item\nNo.", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("Quantity", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("UOM", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("Description", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("Unit Cost\n(Required)", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("Extended Cost\n(Required)", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); if (StringUtils.isNotBlank(po.getPurchaseOrderQuoteVendorNoteText())) { // Vendor notes line. itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); tableCell = createCell(po.getPurchaseOrderQuoteVendorNoteText(), false, false, false, false, Element.ALIGN_LEFT, cour_10_normal); itemsTable.addCell(tableCell); itemsTable.addCell(" "); itemsTable.addCell(" "); } for (PurchaseOrderItem poi : (List<PurchaseOrderItem>) po.getItems()) { if ((poi.getItemType() != null) && (StringUtils.isNotBlank(poi.getItemDescription())) && (poi .getItemType().isLineItemIndicator() || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE))) { // "ITEM"s display the line number; other types don't. String description = ""; description = (StringUtils.isNotBlank(poi.getItemCatalogNumber())) ? poi.getItemCatalogNumber().trim() + " - " : ""; description = description + ((StringUtils.isNotBlank(poi.getItemDescription())) ? poi.getItemDescription().trim() : ""); // If this is a full order discount item or trade in item, we add the // itemType description and a dash to the purchase order item description. if (StringUtils.isNotBlank(poi.getItemDescription())) { if (poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) { description = poi.getItemType().getItemTypeDescription() + " - " + description; } } // We can do the normal table now because description is not too long. String itemLineNumber = new String(); if (poi.getItemType().isLineItemIndicator()) { itemLineNumber = poi.getItemLineNumber().toString(); } else { itemLineNumber = ""; } tableCell = createCell(itemLineNumber, false, false, false, false, Element.ALIGN_CENTER, cour_10_normal); itemsTable.addCell(tableCell); String quantity = (poi.getItemQuantity() != null) ? poi.getItemQuantity().toString() : " "; tableCell = createCell(quantity, false, false, false, false, Element.ALIGN_CENTER, cour_10_normal); itemsTable.addCell(tableCell); tableCell = createCell(poi.getItemUnitOfMeasureCode(), false, false, false, false, Element.ALIGN_CENTER, cour_10_normal); itemsTable.addCell(tableCell); tableCell = createCell(description, false, false, false, false, Element.ALIGN_LEFT, cour_10_normal); itemsTable.addCell(tableCell); itemsTable.addCell(" "); itemsTable.addCell(" "); } } // Blank line before totals createBlankRowInItemsTable(itemsTable); // Totals line. itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); tableCell = createCell("Total: ", false, false, false, false, Element.ALIGN_RIGHT, ver_10_normal); itemsTable.addCell(tableCell); itemsTable.addCell(" "); itemsTable.addCell(" "); // Blank line after totals createBlankRowInItemsTable(itemsTable); document.add(itemsTable); LOG.debug("createQuotePdf() vendorFillsIn table started."); float[] vendorFillsInWidths = { 0.50f, 0.50f }; PdfPTable vendorFillsInTable = new PdfPTable(vendorFillsInWidths); vendorFillsInTable.setWidthPercentage(100); vendorFillsInTable.setHorizontalAlignment(Element.ALIGN_CENTER); vendorFillsInTable.setSplitLate(false); vendorFillsInTable.getDefaultCell().setBorderWidth(0); vendorFillsInTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); vendorFillsInTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER); // New row String important = new String( "\nIMPORTANT: The information and signature below MUST BE COMPLETED or your offer may be rejected.\n"); cell = createCell(important, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row String cashDiscount = new String( "Terms of Payment: Cash discount_________%_________Days-Net________Days\n"); cell = createCell(cashDiscount, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row String fob = new String(" FOB: __ Destination (Title)\n"); cell = createCell(fob, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); String freightVendor = new String(" __ Freight Vendor Paid (Allowed)\n"); cell = createCell(freightVendor, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); // New row String shipping = new String(" __ Shipping Point (Title)\n"); cell = createCell(shipping, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); String freightPrepaid = new String(" __ Freight Prepaid & Added Amount $_________\n"); cell = createCell(freightPrepaid, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); // New row String commonCarrier = new String( " If material will ship common carrier, please provide the following:\n"); cell = createCell(commonCarrier, true, false, false, false, Element.ALIGN_LEFT, ver_8_bold); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row String origin = new String( " Point of origin and zip code: ______________________ Weight: _________ Class: _________\n"); cell = createCell(origin, true, false, false, false, Element.ALIGN_LEFT, ver_8_bold); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row p = new Paragraph(); p.add(new Chunk(" Unless otherwise stated, all material to be shipped to ", ver_8_normal)); String purchasingAddressPartial; if (po.getAddressToVendorIndicator()) { purchasingAddressPartial = po.getReceivingCityName() + ", " + po.getReceivingStateCode() + " " + po.getReceivingPostalCode(); } else { purchasingAddressPartial = po.getDeliveryCityName() + ", " + po.getDeliveryStateCode() + " " + po.getDeliveryPostalCode(); } p.add(new Chunk(purchasingAddressPartial + "\n", cour_10_normal)); cell = new PdfPCell(p); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorderWidth(0); vendorFillsInTable.addCell(cell); // New row String offerEffective = new String(" Offer effective until (Date):_____________\n"); cell = createCell(offerEffective, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); String deliverBy = new String(" Delivery can be made by (Date):_____________\n"); cell = createCell(deliverBy, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); // New row String sign = new String(" SIGN HERE:____________________________\n"); cell = createCell(sign, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); String date = new String(" DATE:____________________________\n"); cell = createCell(date, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); // New row String name = new String(" PRINT NAME:____________________________\n"); cell = createCell(name, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); String phone = new String(" PHONE:____________________________\n"); cell = createCell(phone, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); // New row String company = new String(" COMPANY:____________________________\n"); cell = createCell(company, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); String fax = new String(" FAX:____________________________\n"); cell = createCell(fax, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); document.add(vendorFillsInTable); document.close(); LOG.debug("createQuotePdf()pdf document closed."); }
From source file:org.kuali.kfs.pdp.batch.service.impl.DailyReportServiceImpl.java
License:Educational Community License
protected void addHeader(PdfPTable dataTable) { String sortOrderSubtitle = this.kualiConfigurationService .getPropertyValueAsString(PdpKeyConstants.DAILY_REPORT_SERVICE_SORT_ORDER_SUBTITLE); sortOrderSubtitle = MessageFormat.format(sortOrderSubtitle, new Object[] { null }); PdfPCell cell = new PdfPCell(new Phrase(sortOrderSubtitle, headerFont)); dataTable.addCell(cell);/*from w w w . j a v a 2 s .c o m*/ String customerSubtitle = this.kualiConfigurationService .getPropertyValueAsString(PdpKeyConstants.DAILY_REPORT_SERVICE_CUSTOMER_SUBTITLE); customerSubtitle = MessageFormat.format(customerSubtitle, new Object[] { null }); cell = new PdfPCell(new Phrase(customerSubtitle, headerFont)); dataTable.addCell(cell); String amountOfPaymentsSubtitle = this.kualiConfigurationService .getPropertyValueAsString(PdpKeyConstants.DAILY_REPORT_SERVICE_AMOUNT_OF_PAYMENTS_SUBTITLE); amountOfPaymentsSubtitle = MessageFormat.format(amountOfPaymentsSubtitle, new Object[] { null }); cell = new PdfPCell(new Phrase(amountOfPaymentsSubtitle, headerFont)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); dataTable.addCell(cell); String numberOfPaymentRecordsSubtitle = this.kualiConfigurationService .getPropertyValueAsString(PdpKeyConstants.DAILY_REPORT_SERVICE_NUMBER_OF_PAYMENT_RECORDS_SUBTITLE); numberOfPaymentRecordsSubtitle = MessageFormat.format(numberOfPaymentRecordsSubtitle, new Object[] { null }); cell = new PdfPCell(new Phrase(numberOfPaymentRecordsSubtitle, headerFont)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); dataTable.addCell(cell); String numberOfPayeesSubtitle = this.kualiConfigurationService .getPropertyValueAsString(PdpKeyConstants.DAILY_REPORT_SERVICE_NUMBER_OF_PAYEES_SUBTITLE); numberOfPayeesSubtitle = MessageFormat.format(numberOfPayeesSubtitle, new Object[] { null }); cell = new PdfPCell(new Phrase(numberOfPayeesSubtitle, headerFont)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); dataTable.addCell(cell); }
From source file:org.kuali.ole.module.purap.pdf.PurchaseOrderPdf.java
License:Educational Community License
/** * Overrides the method in PdfPageEventHelper from itext to create and set the headerTable and set its logo image if * there is a logoImage to be used, creates and sets the nestedHeaderTable and its content. * * @param writer The PdfWriter for this document. * @param document The document.//from w ww. j a v a 2 s. c o m * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document) */ @Override public void onOpenDocument(PdfWriter writer, Document document) { if (LOG.isDebugEnabled()) { LOG.debug("onOpenDocument() started. isRetransmit is " + isRetransmit); } try { float[] headerWidths = { 0.20f, 0.80f }; headerTable = new PdfPTable(headerWidths); headerTable.setWidthPercentage(100); headerTable.setHorizontalAlignment(Element.ALIGN_CENTER); headerTable.setSplitLate(false); headerTable.getDefaultCell().setBorderWidth(0); headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); headerTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER); Image logo = null; if (StringUtils.isNotBlank(logoImage)) { LOG.info(" Logo Image in open document :" + logoImage); try { logo = Image.getInstance(logoImage); } catch (FileNotFoundException e) { LOG.info("The logo image [" + logoImage + "] is not available. Defaulting to the default image."); } } if (logo == null) { // if we don't use images headerTable.addCell(new Phrase(new Chunk(""))); } else { logo.scalePercent(3, 3); headerTable.addCell(new Phrase(new Chunk(logo, 0, 0))); } // Nested table for titles, etc. float[] nestedHeaderWidths = { 0.70f, 0.30f }; nestedHeaderTable = new PdfPTable(nestedHeaderWidths); nestedHeaderTable.setSplitLate(false); PdfPCell cell; // New nestedHeaderTable row cell = new PdfPCell(new Paragraph(po.getBillingName(), ver_15_normal)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(0); nestedHeaderTable.addCell(cell); cell = new PdfPCell(new Paragraph(" ", ver_15_normal)); cell.setBorderWidth(0); nestedHeaderTable.addCell(cell); // New nestedHeaderTable row if (isRetransmit) { cell = new PdfPCell(new Paragraph(po.getRetransmitHeader(), ver_15_normal)); } else { cell = new PdfPCell(new Paragraph("PURCHASE ORDER", ver_15_normal)); } cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(0); nestedHeaderTable.addCell(cell); Paragraph p = new Paragraph(); p.add(new Chunk("PO Number: ", ver_11_normal)); p.add(new Chunk(po.getPurapDocumentIdentifier().toString(), cour_7_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidth(0); nestedHeaderTable.addCell(cell); if (!po.getPurchaseOrderAutomaticIndicator()) { // Contract manager name goes on non-APOs. // New nestedHeaderTable row, spans both columns p = new Paragraph(); p.add(new Chunk("Contract Manager: ", ver_11_normal)); p.add(new Chunk(po.getContractManager().getContractManagerName(), cour_7_normal)); cell = new PdfPCell(p); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidth(0); nestedHeaderTable.addCell(cell); } // Add the nestedHeaderTable to the headerTable cell = new PdfPCell(nestedHeaderTable); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(0); headerTable.addCell(cell); // initialization of the template tpl = writer.getDirectContent().createTemplate(100, 100); // initialization of the font helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); } catch (Exception e) { throw new ExceptionConverter(e); } }
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. jav a 2s .com * @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.kuali.ole.module.purap.pdf.PurchaseOrderQuotePdf.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 poqv The PurchaseOrderVendorQuote to be used to generate the pdf. * @param campusName The campus name to be used to generate the pdf. * @param contractManagerCampusCode The contract manager campus code to be used to generate the pdf. * @param logoImage The logo image file name to be used to generate the pdf. * @param document The pdf document whose margins have already been set. * @param writer The PdfWriter to write the pdf document into. * @param environment The current environment used (e.g. DEV if it is a development environment). * @throws DocumentException//from w w w . j a va 2s.c o m */ private void createPOQuotePdf(PurchaseOrderDocument po, PurchaseOrderVendorQuote poqv, String campusName, String contractManagerCampusCode, String logoImage, Document document, PdfWriter writer, String environment) throws DocumentException { if (LOG.isDebugEnabled()) { LOG.debug("createQuotePdf() started for po number " + po.getPurapDocumentIdentifier()); } // 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); // Date format pattern: MM-dd-yyyy SimpleDateFormat sdf = new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE, Locale.getDefault()); CampusParameter campusParameter = getCampusParameter(contractManagerCampusCode); String purchasingAddressFull = getPurchasingAddressFull(campusParameter); // Turn on the page events that handle the header and page numbers. PurchaseOrderQuotePdf events = new PurchaseOrderQuotePdf().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 (address, vendor, other info) ***** LOG.debug("createQuotePdf() info table started."); float[] infoWidths = { 0.45f, 0.55f }; PdfPTable infoTable = new PdfPTable(infoWidths); infoTable.setWidthPercentage(100); infoTable.setHorizontalAlignment(Element.ALIGN_CENTER); infoTable.setSplitLate(false); p = new Paragraph(); ContractManager contractManager = po.getContractManager(); p.add(new Chunk("\n Return this form to:\n", ver_8_bold)); p.add(new Chunk(purchasingAddressFull + "\n", cour_10_normal)); p.add(new Chunk("\n", cour_10_normal)); p.add(new Chunk(" Fax #: ", ver_6_normal)); p.add(new Chunk(contractManager.getContractManagerFaxNumber() + "\n", cour_10_normal)); p.add(new Chunk(" Contract Manager: ", ver_6_normal)); p.add(new Chunk(contractManager.getContractManagerName() + " " + contractManager.getContractManagerPhoneNumber() + "\n", cour_10_normal)); p.add(new Chunk("\n", cour_10_normal)); p.add(new Chunk(" To:\n", ver_6_normal)); StringBuffer vendorInfo = new StringBuffer(); if (StringUtils.isNotBlank(poqv.getVendorAttentionName())) { vendorInfo.append(" ATTN: " + poqv.getVendorAttentionName().trim() + "\n"); } vendorInfo.append(" " + poqv.getVendorName() + "\n"); if (StringUtils.isNotBlank(poqv.getVendorLine1Address())) { vendorInfo.append(" " + poqv.getVendorLine1Address() + "\n"); } if (StringUtils.isNotBlank(poqv.getVendorLine2Address())) { vendorInfo.append(" " + poqv.getVendorLine2Address() + "\n"); } if (StringUtils.isNotBlank(poqv.getVendorCityName())) { vendorInfo.append(" " + poqv.getVendorCityName()); } if ((StringUtils.isNotBlank(poqv.getVendorStateCode())) && (!poqv.getVendorStateCode().equals("--"))) { vendorInfo.append(", " + poqv.getVendorStateCode()); } if (StringUtils.isNotBlank(poqv.getVendorAddressInternationalProvinceName())) { vendorInfo.append(", " + poqv.getVendorAddressInternationalProvinceName()); } if (StringUtils.isNotBlank(poqv.getVendorPostalCode())) { vendorInfo.append(" " + poqv.getVendorPostalCode() + "\n"); } else { vendorInfo.append("\n"); } if (!OLEConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(poqv.getVendorCountryCode()) && poqv.getVendorCountryCode() != null) { vendorInfo.append(" " + poqv.getVendorCountry().getName() + "\n\n"); } else { vendorInfo.append(" \n\n"); } p.add(new Chunk(vendorInfo.toString(), cour_10_normal)); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); p = new Paragraph(); p.add(new Chunk("\n R.Q. Number: ", ver_8_bold)); p.add(new Chunk(po.getPurapDocumentIdentifier() + "\n", cour_10_normal)); java.sql.Date requestDate = getDateTimeService().getCurrentSqlDate(); if (poqv.getPurchaseOrderQuoteTransmitTimestamp() != null) { try { requestDate = getDateTimeService().convertToSqlDate(poqv.getPurchaseOrderQuoteTransmitTimestamp()); } catch (ParseException e) { throw new RuntimeException( "ParseException thrown when trying to convert from Timestamp to SqlDate.", e); } } p.add(new Chunk(" R.Q. Date: ", ver_8_bold)); p.add(new Chunk(sdf.format(requestDate) + "\n", cour_10_normal)); p.add(new Chunk(" RESPONSE MUST BE RECEIVED BY: ", ver_8_bold)); if (po.getPurchaseOrderQuoteDueDate() != null) { p.add(new Chunk(sdf.format(po.getPurchaseOrderQuoteDueDate()) + "\n\n", cour_10_normal)); } else { p.add(new Chunk("N/A\n\n", cour_10_normal)); } // retrieve the quote stipulations StringBuffer quoteStipulations = getPoQuoteLanguage(); p.add(new Chunk(quoteStipulations.toString(), ver_6_normal)); p.add(new Chunk("\n ALL QUOTES MUST BE TOTALED", ver_12_normal)); cell = new PdfPCell(p); infoTable.addCell(cell); document.add(infoTable); // ***** Notes and Stipulations table ***** // The notes and stipulations table is type Table instead of PdfPTable // because Table has the method setCellsFitPage and I can't find an equivalent // in PdfPTable. Long notes or stipulations would break to the next page, leaving // a large white space on the previous page. PdfPTable notesStipulationsTable = new PdfPTable(1); notesStipulationsTable.setWidthPercentage(100); notesStipulationsTable.setSplitLate(false); p = new Paragraph(); p.add(new Chunk(" Vendor Stipulations and Information\n\n", ver_6_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_10_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_10_normal)); } PdfPCell tableCell = new PdfPCell(p); tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); tableCell.setVerticalAlignment(Element.ALIGN_TOP); notesStipulationsTable.addCell(tableCell); document.add(notesStipulationsTable); // ***** Items table ***** LOG.debug("createQuotePdf() items table started."); float[] itemsWidths = { 0.07f, 0.1f, 0.07f, 0.50f, 0.13f, 0.13f }; PdfPTable itemsTable = new PdfPTable(6); // 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 = createCell("Item\nNo.", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("Quantity", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("UOM", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("Description", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("Unit Cost\n(Required)", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); tableCell = createCell("Extended Cost\n(Required)", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal); itemsTable.addCell(tableCell); if (StringUtils.isNotBlank(po.getPurchaseOrderQuoteVendorNoteText())) { // Vendor notes line. itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); tableCell = createCell(po.getPurchaseOrderQuoteVendorNoteText(), false, false, false, false, Element.ALIGN_LEFT, cour_10_normal); itemsTable.addCell(tableCell); itemsTable.addCell(" "); itemsTable.addCell(" "); } for (PurchaseOrderItem poi : (List<PurchaseOrderItem>) po.getItems()) { if ((poi.getItemType() != null) && (StringUtils.isNotBlank(poi.getItemDescription())) && (poi .getItemType().isLineItemIndicator() || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE))) { // "ITEM"s display the line number; other types don't. String description = ""; description = (StringUtils.isNotBlank(poi.getItemCatalogNumber())) ? poi.getItemCatalogNumber().trim() + " - " : ""; description = description + ((StringUtils.isNotBlank(poi.getItemDescription())) ? poi.getItemDescription().trim() : ""); // If this is a full order discount item or trade in item, we add the // itemType description and a dash to the purchase order item description. if (StringUtils.isNotBlank(poi.getItemDescription())) { if (poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) { description = poi.getItemType().getItemTypeDescription() + " - " + description; } } // We can do the normal table now because description is not too long. String itemLineNumber = new String(); if (poi.getItemType().isLineItemIndicator()) { itemLineNumber = poi.getItemLineNumber().toString(); } else { itemLineNumber = ""; } tableCell = createCell(itemLineNumber, false, false, false, false, Element.ALIGN_CENTER, cour_10_normal); itemsTable.addCell(tableCell); String quantity = (poi.getItemQuantity() != null) ? poi.getItemQuantity().toString() : " "; tableCell = createCell(quantity, false, false, false, false, Element.ALIGN_CENTER, cour_10_normal); itemsTable.addCell(tableCell); tableCell = createCell(poi.getItemUnitOfMeasureCode(), false, false, false, false, Element.ALIGN_CENTER, cour_10_normal); itemsTable.addCell(tableCell); tableCell = createCell(description, false, false, false, false, Element.ALIGN_LEFT, cour_10_normal); itemsTable.addCell(tableCell); itemsTable.addCell(" "); itemsTable.addCell(" "); } } // Blank line before totals createBlankRowInItemsTable(itemsTable); // Totals line. itemsTable.addCell(" "); itemsTable.addCell(" "); itemsTable.addCell(" "); tableCell = createCell("Total: ", false, false, false, false, Element.ALIGN_RIGHT, ver_10_normal); itemsTable.addCell(tableCell); itemsTable.addCell(" "); itemsTable.addCell(" "); // Blank line after totals createBlankRowInItemsTable(itemsTable); document.add(itemsTable); LOG.debug("createQuotePdf() vendorFillsIn table started."); float[] vendorFillsInWidths = { 0.50f, 0.50f }; PdfPTable vendorFillsInTable = new PdfPTable(vendorFillsInWidths); vendorFillsInTable.setWidthPercentage(100); vendorFillsInTable.setHorizontalAlignment(Element.ALIGN_CENTER); vendorFillsInTable.setSplitLate(false); vendorFillsInTable.getDefaultCell().setBorderWidth(0); vendorFillsInTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); vendorFillsInTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER); // New row String important = new String( "\nIMPORTANT: The information and signature below MUST BE COMPLETED or your offer may be rejected.\n"); cell = createCell(important, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row String cashDiscount = new String( "Terms of Payment: Cash discount_________%_________Days-Net________Days\n"); cell = createCell(cashDiscount, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row String fob = new String(" FOB: __ Destination (Title)\n"); cell = createCell(fob, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); String freightVendor = new String(" __ Freight Vendor Paid (Allowed)\n"); cell = createCell(freightVendor, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); // New row String shipping = new String(" __ Shipping Point (Title)\n"); cell = createCell(shipping, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); String freightPrepaid = new String(" __ Freight Prepaid & Added Amount $_________\n"); cell = createCell(freightPrepaid, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); // New row String commonCarrier = new String( " If material will ship common carrier, please provide the following:\n"); cell = createCell(commonCarrier, true, false, false, false, Element.ALIGN_LEFT, ver_8_bold); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row String origin = new String( " Point of origin and zip code: ______________________ Weight: _________ Class: _________\n"); cell = createCell(origin, true, false, false, false, Element.ALIGN_LEFT, ver_8_bold); cell.setColspan(2); vendorFillsInTable.addCell(cell); // New row p = new Paragraph(); p.add(new Chunk(" Unless otherwise stated, all material to be shipped to ", ver_8_normal)); String purchasingAddressPartial; if (po.getAddressToVendorIndicator()) // use receiving address purchasingAddressPartial = po.getReceivingCityName() + ", " + po.getReceivingStateCode() + " " + po.getReceivingPostalCode(); else // use final delivery address purchasingAddressPartial = po.getDeliveryCityName() + ", " + po.getDeliveryStateCode() + " " + po.getDeliveryPostalCode(); p.add(new Chunk(purchasingAddressPartial + "\n", cour_10_normal)); cell = new PdfPCell(p); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorderWidth(0); vendorFillsInTable.addCell(cell); // New row String offerEffective = new String(" Offer effective until (Date):_____________\n"); cell = createCell(offerEffective, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); String deliverBy = new String(" Delivery can be made by (Date):_____________\n"); cell = createCell(deliverBy, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal); vendorFillsInTable.addCell(cell); // New row String sign = new String(" SIGN HERE:____________________________\n"); cell = createCell(sign, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); String date = new String(" DATE:____________________________\n"); cell = createCell(date, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); // New row String name = new String(" PRINT NAME:____________________________\n"); cell = createCell(name, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); String phone = new String(" PHONE:____________________________\n"); cell = createCell(phone, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); // New row String company = new String(" COMPANY:____________________________\n"); cell = createCell(company, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); String fax = new String(" FAX:____________________________\n"); cell = createCell(fax, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold); vendorFillsInTable.addCell(cell); document.add(vendorFillsInTable); document.close(); LOG.debug("createQuotePdf()pdf document closed."); }
From source file:org.lucee.extension.pdf.tag.PDF.java
License:Open Source License
public void setAlign(String align) throws PageException { if (Util.isEmpty(align, true)) return;//from w w w. j av a2s. co m align = align.trim().toLowerCase(); if ("center".equals(align)) this.align = Element.ALIGN_CENTER; else if ("left".equals(align)) this.align = Element.ALIGN_LEFT; else if ("right".equals(align)) this.align = Element.ALIGN_RIGHT; // else if("justified".equals(align)) this.align=Element.ALIGN_JUSTIFIED; // else if("justify".equals(align)) this.align=Element.ALIGN_JUSTIFIED; else throw engine.getExceptionUtil().createApplicationException( "invalid align value [" + align + "], valid align values are [center,left,right]"); }
From source file:org.lucee.extension.pdf.tag.PDF.java
License:Open Source License
private void doActionAddHeaderFooter(boolean isHeader) throws PageException, IOException, DocumentException { required("pdf", "write", "source", source); // required("pdf", "write", "destination", destination); /*// w w w . java2 s .c om * optinal - pages */ /* * isBase64 = "yes|no" showonprint = "yes|no"> opacity = "header opacity" image = "image file name to be used as the header" * */ PDFStruct doc = toPDFDocument(source, password, null); PdfReader reader = doc.getPdfReader(); BIF bif = null; if (NUMBERFORMAT_NUMERIC != numberformat) { ClassUtil classUtil = engine.getClassUtil(); try { bif = classUtil.loadBIF(pageContext, "lucee.runtime.functions.displayFormatting.NumberFormat"); } catch (Exception e) { e.printStackTrace(); throw engine.getCastUtil().toPageException(e); } } // output stream boolean destIsSource = destination != null && doc.getResource() != null && destination.equals(doc.getResource()); OutputStream os = null; if (!Util.isEmpty(name) || destIsSource) { os = new ByteArrayOutputStream(); } else if (destination != null) { os = destination.getOutputStream(); } PdfStamper stamper = null; try { if (destination != null && destination.exists() && !overwrite) throw engine.getExceptionUtil() .createApplicationException("destination file [" + destination + "] already exists"); int len = reader.getNumberOfPages(); Set<Integer> pageSet = PDFUtil.parsePageDefinition(pages, len); stamper = new PdfStamper(reader, destination.getOutputStream()); if (font == null) font = getDefaultFont(); // , new Font(FontFamily.HELVETICA, 14) for (int p = 1; p <= len; p++) { if (pageSet != null && !pageSet.contains(p)) continue; Phrase header = text(text, p, len, numberformat, bif, font); // vertical orientation float y; if (isHeader) { y = reader.getPageSize(p).getTop(header.getFont().getCalculatedSize() + (topmargin - 3)); } else { y = reader.getPageSize(p).getBottom((bottommargin + 2)); /* * System.out.println("y:"+y); System.out.println("bottom:"+reader.getPageSize(p).getBottom()); System.out.println("margin:"+bottommargin); * System.out.println("font:"+header.getFont().getSize()); System.out.println("CalculatedStyle:"+header.getFont().getCalculatedStyle()); * System.out.println("CalculatedSize:"+header.getFont().getCalculatedSize()); */ } // float yh = reader.getPageSize(p).getTop(topmargin); // float yf = reader.getPageSize(p).getBottom(bottommargin); System.out.println("++++++++++++"); System.out.println(y); System.out.println(reader.getPageSize(p).getTop()); // horizontal orientation float x = reader.getPageSize(p).getWidth() / 2; if (Element.ALIGN_LEFT == align) { x = leftmargin; } else if (Element.ALIGN_RIGHT == align) { x = reader.getPageSize(p).getWidth() - rightmargin; } else { x = reader.getPageSize(p).getWidth() / 2; } ColumnText.showTextAligned(stamper.getOverContent(p), align, header, x, y, 0); } } finally { try { if (stamper != null) stamper.close(); } catch (IOException ioe) { } ; Util.closeEL(os); if (os instanceof ByteArrayOutputStream) { if (destination != null) engine.getIOUtil().copy(new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray()), destination, true);// MUST overwrite if (!Util.isEmpty(name)) { pageContext.setVariable(name, new PDFStruct(((ByteArrayOutputStream) os).toByteArray(), password)); } } } // PdfReader pr = doc.getPdfReader(); // output /* * boolean destIsSource = doc.getResource()!=null && destination.equals(doc.getResource()); * * OutputStream os=null; if(destIsSource){ os=new ByteArrayOutputStream(); } else if(destination!=null) { os=destination.getOutputStream(); } * * try { PDFUtil.concat(new PDFStruct[]{doc}, os, true, true, true,version); } finally { Util.closeEL(os); if(os instanceof ByteArrayOutputStream) { * if(destination!=null)engine.getIOUtil().copy(new ByteArrayInputStream(((ByteArrayOutputStream)os).toByteArray()), destination,true);// MUST overwrite * } } */ }
From source file:org.netxilia.server.rest.pdf.SheetPdfProvider.java
License:Open Source License
/** * Generates all the row cells./*from w ww.j a va 2s. c o m*/ * * @throws JspException * for errors during value retrieving from the table model * @throws BadElementException * errors while generating content * @throws NetxiliaBusinessException * @throws NetxiliaResourceException */ protected void generateRows(ISheet sheet, boolean summarySheet, Table tablePDF, Font font, int columnCount) throws JspException, BadElementException, NetxiliaResourceException, NetxiliaBusinessException { Styles rightAlign = Styles.styles("a-r"); List<RowData> rowData = sheet.receiveRows(Range.ALL).getNonBlocking(); List<ColumnData> columnData = sheet.receiveColumns(Range.ALL).getNonBlocking(); Matrix<CellData> cellData = sheet.receiveCells(AreaReference.ALL).getNonBlocking(); for (RowData row : rowData) { String rowHdr = ""; if (summarySheet) { rowHdr += "S"; } rowHdr += Integer.toString(row.getIndex() + 1); Cell rowHdrCell = getCell(rowHdr, font, Element.ALIGN_LEFT, -1); rowHdrCell.setGrayFill(0.9f); tablePDF.addCell(rowHdrCell); int c = 0; for (CellData cell : cellData.getRow(row.getIndex())) { RichValue formattedValue = styleService.formatCell(sheet.getWorkbook().getId(), cell, rowData.get(cell.getReference().getRowIndex()), columnData.get(cell.getReference().getColumnIndex())); // TODO check for aligns int horizAlign = Element.ALIGN_LEFT; if (formattedValue.getStyles() != null && formattedValue.getStyles().contains(rightAlign)) { horizAlign = Element.ALIGN_RIGHT; } Cell pdfCell = getCell(formattedValue.getDisplay(), font, horizAlign, -1); tablePDF.addCell(pdfCell); c++; } for (; c < columnCount; ++c) { tablePDF.addCell(getCell("", font, Element.ALIGN_LEFT, -1)); } } }
From source file:org.odftoolkit.odfdom.converter.internal.itext.StyleEngineForIText.java
License:Open Source License
@Override public void visit(StyleParagraphPropertiesElement ele) { StyleParagraphProperties paragraphProperties = currentStyle.getParagraphProperties(); if (paragraphProperties == null) { paragraphProperties = new StyleParagraphProperties(); currentStyle.setParagraphProperties(paragraphProperties); }//from ww w .j a va 2 s . com // background-color String backgroundColor = ele.getFoBackgroundColorAttribute(); if (StringUtils.isNotEmpty(backgroundColor)) { paragraphProperties.setBackgroundColor(ColorRegistry.getInstance().getColor(backgroundColor)); } // border String border = ele.getFoBorderAttribute(); if (StringUtils.isNotEmpty(border)) { paragraphProperties.setBorder(new StyleBorder(border, BorderType.ALL)); } // border-bottom String borderBottom = ele.getFoBorderBottomAttribute(); if (StringUtils.isNotEmpty(borderBottom)) { paragraphProperties.setBorderBottom(new StyleBorder(borderBottom, BorderType.BOTTOM)); } // border-left String borderLeft = ele.getFoBorderLeftAttribute(); if (StringUtils.isNotEmpty(borderLeft)) { paragraphProperties.setBorderLeft(new StyleBorder(borderLeft, BorderType.LEFT)); } // border-bottom String borderRight = ele.getFoBorderRightAttribute(); if (StringUtils.isNotEmpty(borderRight)) { paragraphProperties.setBorderRight(new StyleBorder(borderRight, BorderType.RIGHT)); } // border-top String borderTop = ele.getFoBorderTopAttribute(); if (StringUtils.isNotEmpty(borderTop)) { paragraphProperties.setBorderTop(new StyleBorder(borderTop, BorderType.TOP)); } // line-height String lineHeight = ele.getFoLineHeightAttribute(); if (StringUtils.isNotEmpty(lineHeight)) { paragraphProperties.setLineHeight(new StyleLineHeight(ODFUtils.getDimensionAsPoint(lineHeight), ODFUtils.hasPercentUnit(lineHeight))); } // margin String margin = ele.getFoMarginAttribute(); if (StringUtils.isNotEmpty(margin)) { paragraphProperties.setMargin(ODFUtils.getDimensionAsPoint(margin)); } // margin-bottom String marginBottom = ele.getFoMarginBottomAttribute(); if (StringUtils.isNotEmpty(marginBottom)) { paragraphProperties.setMarginBottom(ODFUtils.getDimensionAsPoint(marginBottom)); } // margin-left String marginLeft = ele.getFoMarginLeftAttribute(); if (StringUtils.isNotEmpty(marginLeft)) { paragraphProperties.setMarginLeft(ODFUtils.getDimensionAsPoint(marginLeft)); } // margin-right String marginRight = ele.getFoMarginRightAttribute(); if (StringUtils.isNotEmpty(marginRight)) { paragraphProperties.setMarginRight(ODFUtils.getDimensionAsPoint(marginRight)); } // margin-top String marginTop = ele.getFoMarginTopAttribute(); if (StringUtils.isNotEmpty(marginTop)) { paragraphProperties.setMarginTop(ODFUtils.getDimensionAsPoint(marginTop)); } // padding String padding = ele.getFoPaddingAttribute(); if (StringUtils.isNotEmpty(padding)) { // cssStyleSheet.setCSSProperty("padding", padding); } // padding-bottom String paddingBottom = ele.getFoPaddingBottomAttribute(); if (StringUtils.isNotEmpty(paddingBottom)) { // cssStyleSheet.setCSSProperty("padding-bottom", paddingBottom); } // padding-left String paddingLeft = ele.getFoPaddingLeftAttribute(); if (StringUtils.isNotEmpty(paddingLeft)) { // cssStyleSheet.setCSSProperty("padding-left", paddingLeft); } // padding-bottom String paddingRight = ele.getFoPaddingRightAttribute(); if (StringUtils.isNotEmpty(paddingRight)) { // cssStyleSheet.setCSSProperty("padding-right", paddingRight); } // padding-top String paddingTop = ele.getFoPaddingTopAttribute(); if (StringUtils.isNotEmpty(paddingTop)) { // cssStyleSheet.setCSSProperty("padding-top", paddingTop); } // text-align String textAlign = ele.getFoTextAlignAttribute(); if (StringUtils.isNotEmpty(textAlign)) { int alignment = Element.ALIGN_UNDEFINED; if ("start".equals(textAlign)) { alignment = Element.ALIGN_LEFT; } else if ("end".equals(textAlign)) { alignment = Element.ALIGN_RIGHT; } else if ("left".equals(textAlign)) { alignment = Element.ALIGN_LEFT; } else if ("right".equals(textAlign)) { alignment = Element.ALIGN_RIGHT; } else if ("center".equals(textAlign)) { alignment = Element.ALIGN_CENTER; } else if ("justify".equals(textAlign)) { alignment = Element.ALIGN_JUSTIFIED; } paragraphProperties.setAlignment(alignment); } // auto-text-indent Boolean autoTextIndent = ele.getStyleAutoTextIndentAttribute(); if (autoTextIndent != null) { paragraphProperties.setAutoTextIndent(autoTextIndent); } // text-indent String textIndent = ele.getFoTextIndentAttribute(); if (StringUtils.isNotEmpty(textIndent)) { paragraphProperties.setTextIndent(ODFUtils.getDimensionAsPoint(textIndent)); } // keep-together String keepTogether = ele.getFoKeepTogetherAttribute(); if (StringUtils.isNotEmpty(keepTogether)) { if (FoKeepTogetherAttribute.Value.ALWAYS.toString().equals(keepTogether)) { paragraphProperties.setKeepTogether(Boolean.TRUE); } else { paragraphProperties.setKeepTogether(Boolean.FALSE); } } // fo:break-before String breakBefore = ele.getFoBreakBeforeAttribute(); if (StringUtils.isNotEmpty(breakBefore)) { if (FoBreakBeforeAttribute.Value.PAGE.toString().equals(breakBefore)) { paragraphProperties.setBreakBefore(StyleBreak.createWithPageBreak()); } else if (FoBreakBeforeAttribute.Value.COLUMN.toString().equals(breakBefore)) { paragraphProperties.setBreakBefore(StyleBreak.createWithColumnBreak()); } else { paragraphProperties.setBreakBefore(StyleBreak.createWithNoBreak()); } } super.visit(ele); }
From source file:org.oscarehr.casemgmt.print.OscarChartPrinter.java
License:Open Source License
public void printDocHeaderFooter() throws DocumentException { String headerTitle = demographic.getFormattedName() + " " + demographic.getAge() + " " + demographic.getSex() + " DOB:" + demographic.getFormattedDob(); //set up document title and header ResourceBundle propResource = ResourceBundle.getBundle("oscarResources"); String title = propResource.getString("oscarEncounter.pdfPrint.title") + " " + (String) request.getAttribute("demoName") + "\n"; String gender = propResource.getString("oscarEncounter.pdfPrint.gender") + " " + (String) request.getAttribute("demoSex") + "\n"; String dob = propResource.getString("oscarEncounter.pdfPrint.dob") + " " + (String) request.getAttribute("demoDOB") + "\n"; String age = propResource.getString("oscarEncounter.pdfPrint.age") + " " + (String) request.getAttribute("demoAge") + "\n"; String mrp = propResource.getString("oscarEncounter.pdfPrint.mrp") + " " + (String) request.getAttribute("mrp") + "\n"; String[] info = new String[] { title, gender, dob, age, mrp }; ClinicData clinicData = new ClinicData(); clinicData.refreshClinicData();/*from w w w. j av a2 s. c om*/ String[] clinic = new String[] { clinicData.getClinicName(), clinicData.getClinicAddress(), clinicData.getClinicCity() + ", " + clinicData.getClinicProvince(), clinicData.getClinicPostal(), clinicData.getClinicPhone() }; if (newPage) { document.newPage(); newPage = false; } //Header will be printed at top of every page beginning with p2 Phrase headerPhrase = new Phrase(LEADING, headerTitle, boldFont); HeaderFooter header = new HeaderFooter(headerPhrase, false); header.setAlignment(HeaderFooter.ALIGN_CENTER); document.setHeader(header); getDocument().add(headerPhrase); getDocument().add(new Phrase("\n")); Paragraph p = new Paragraph("Tel:" + demographic.getPhone(), getFont()); p.setAlignment(Paragraph.ALIGN_LEFT); // getDocument().add(p); Paragraph p2 = new Paragraph("Date of Visit: ", getFont()); p2.setAlignment(Paragraph.ALIGN_RIGHT); // getDocument().add(p); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); PdfPCell cell1 = new PdfPCell(p); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(p2); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); cell2.setBorder(PdfPCell.NO_BORDER); table.addCell(cell1); table.addCell(cell2); getDocument().add(table); table = new PdfPTable(3); table.setWidthPercentage(100f); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); cell1 = new PdfPCell(getParagraph("Signed Provider:" + ((signingProvider != null) ? signingProvider : ""))); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(getParagraph("RFR:")); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBorder(PdfPCell.NO_BORDER); PdfPCell cell3 = new PdfPCell(getParagraph("Ref:")); cell3.setHorizontalAlignment(Element.ALIGN_RIGHT); cell3.setBorder(PdfPCell.NO_BORDER); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); getDocument().add(table); //Write title with top and bottom borders on p1 cb = writer.getDirectContent(); cb.setColorStroke(new Color(0, 0, 0)); cb.setLineWidth(0.5f); cb.moveTo(document.left(), document.top() - (font.getCalculatedLeading(LINESPACING) * 5f)); cb.lineTo(document.right(), document.top() - (font.getCalculatedLeading(LINESPACING) * 5f)); cb.stroke(); }