package com.lemans.builders import com.itextpdf.text.Chunk import com.itextpdf.text.Document import com.itextpdf.text.Element import com.itextpdf.text.Font import com.itextpdf.text.Image import com.itextpdf.text.PageSize import com.itextpdf.text.Paragraph import com.itextpdf.text.Phrase import com.itextpdf.text.Rectangle import com.itextpdf.text.Utilities import com.itextpdf.text.pdf.ColumnText import com.itextpdf.text.pdf.PdfContentByte import com.itextpdf.text.pdf.PdfImportedPage import com.itextpdf.text.pdf.PdfPCell import com.itextpdf.text.pdf.PdfPTable import com.itextpdf.text.pdf.PdfTemplate import com.itextpdf.text.pdf.PdfWriter import java.text.SimpleDateFormat class CommercialInvoiceBuilder extends HelperBuilder { final private ByteArrayOutputStream byteStream = new ByteArrayOutputStream() private Document document private PdfWriter writer private PdfImportedPage page private PdfContentByte content Map header List contents List contents1 List contents2 Map footer boolean isProforma Map user List collectErrors byte[] invoicePdf(Map data, boolean isProforma, Map userDetails, List errors) { try { header = data?.header[0] contents1 = data?.body1.groupBy { it.lineNumber }.collect { k,v -> v[0] + [shippedQuantity: v.shippedQuantity.sum(), amount: v.amount.sum(), backOrderQuantity: v.backOrderQuantity?.sum(), netExtendedWeight: v.netExtendedWeight?.sum(), isPromo: (v[0]?.baseDealerPrice == v[0]?.lineDiscountAmount) ? 'No Charge' : '', unitPrice: v[0]?.unitPrice !=0 ? v[0]?.unitPrice : v[0]?.baseDealerPrice] } contents2 = data?.body2 footer = data?.footer user = userDetails collectErrors = errors document = new Document(PageSize.LETTER, 31, 10, 280, 105) writer = PdfWriter.getInstance(document, byteStream) CommercialFooter rtvF = new CommercialFooter(document, writer, page, content, header, contents2, contents1, footer, byteStream, isProforma) writer.setPageEvent(rtvF) document.open() content = writer.directContentUnder addContent() addInvoiceTotals() document.add(new Chunk('')) document.newPage() document.close() byteStream.toByteArray() } catch(FileNotFoundException ffe) { collectErrors << 'file is not found' ffe.printStackTrace() } catch(Exception e) { collectErrors << 'Exception occured when creating file' e.printStackTrace() } } private addContent() { try { PdfPTable table = new PdfPTable(9) int[] sizes = [1, 1, 1, 3, 2, 1, 1, 1, 1] table.setWidths(sizes) table.setWidthPercentage(100f) table.setTotalWidth(570f) if (header.noFreightOnInvoiceInd == null || header.noFreightOnInvoiceInd == false) { contents1 += [description:"Freight", amount: header.freightCost, isPromo: ''] } contents1.each { row -> disableListOfBorders(table.addCell(getCell(row?.lineNumber?.toString(), new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))), [PdfPCell.LEFT, PdfPCell.TOP]) disableListOfBorders(table.addCell(getCell(row?.orderQuantity?.toString(), new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCell(row?.backOrderQuantity?.toString(), new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCellWithTwoValues(row?.description?.toString(), row?.harmonizeCode?.toString(), new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL), new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCellWithTwoValues(row?.partNumber?.toString(), row?.countryName?.toString(), new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL), new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCell(row?.salesUnitSymbol?.toString(), new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCell(row?.shippedQuantity?.toString(), new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCell(row?.unitPrice?.toString(), new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCell("${row?.amount} \n ${row?.isPromo}", new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))), [PdfPCell.TOP, PdfPCell.RIGHT]) } PdfPTable paragraphTable = new PdfPTable(1) paragraphTable.setWidthPercentage(100f) PdfPCell paragraphCell String paraOne = """.\nThese commodities, technology or software were exported from the United states in accordance with the Export Adminstration Regulations. Diversion contrary to U.S. law is prohibited.""" paragraphCell = createParagraph(paraOne, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLDITALIC), 30f, 20f) paragraphTable.addCell(paragraphCell) if (contents2) { contents2?.each { it -> paragraphCell = createParagraph(""".\nTariff Classification ${it?.harmonizeCode?.toString()?.substring(0, 7)} Harmonized Code ${it.harmonizeCode} ${it.harmonizeCodeDescr} NLR value of item(s) ${it.lineNumber} Made In ${it?.country}""" + ' $' + "${it.total}", new Font(Font.FontFamily.HELVETICA, 10, Font.BOLDITALIC), 30f, 40f) paragraphTable.addCell(paragraphCell) } } paragraphCell = createParagraph(""".\nTotal Value of Goods for Customs Purposes Only: ${footer?.customsTotal ?: 0}""", new Font(Font.FontFamily.HELVETICA, 10, Font.BOLDITALIC), 30f, 10f) paragraphTable.addCell(paragraphCell) if (header?.pleaseNote) { paragraphCell = createParagraph(""".\nPlease Note: ${header?.pleaseNote}""", new Font(Font.FontFamily.HELVETICA, 10, Font.BOLDITALIC), 30f, 10f) paragraphTable.addCell(paragraphCell) } if (contents2.find({ it?.harmonizeCode?.toString() == "4911.10.0080" })) { paragraphCell = createParagraph(""".\n *CATALOGS NOT FOR RESALE FOR BUSINESS USE ONLY* """, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLDITALIC), 30f, 10f) paragraphTable.addCell(paragraphCell) } String paraTwo = """.\nI hearby Certify this invoice to be true and correct to the Best of my knowledge \n \n """ paragraphCell = createParagraph(paraTwo, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLDITALIC), 30f, 10f) paragraphTable.addCell(paragraphCell) document.add(table) document.add(paragraphTable) Image image = Image.getInstance("${user?.documentUrl}") image?.scaleAbsolute(10f, 10f) image?.scaleToFit(10, 10) PdfPTable imageTable = new PdfPTable(1) imageTable.horizontalAlignment = Element.ALIGN_LEFT imageTable.setTotalWidth(80) imageTable.defaultCell.setFixedHeight(30) imageTable.defaultCell.setBorder(Rectangle.NO_BORDER) imageTable.addCell(image) imageTable.addCell(new Phrase("${user?.firstName ?: ''} ${user?.lastName ?: ''}", new Font(Font.FontFamily.HELVETICA, 10, Font.BOLDITALIC))) imageTable.addCell(new Phrase( "Tracking numbers: ${header?.trackingNumbers ?: ''}", new Font(Font.FontFamily.HELVETICA, 10, Font.BOLDITALIC))) document.add(imageTable) } catch (FileNotFoundException ffe) { collectErrors << "Signature file not found. ($ffe.message)" } catch(Exception e) { collectErrors << "Error occured while generating file ($e.message)" } } private addInvoiceTotals() { try { PdfPTable finalTable = new PdfPTable(2) finalTable.with { getDefaultCell().setBorder(Rectangle.NO_BORDER) setTotalWidth(Utilities.millimetersToPoints(100)) addCell(new Phrase('Total Exworks')) addCell(new Phrase('Us Dollars')) setLockedWidth(true) writeSelectedRows(0, -1, 100, 35, writer.getDirectContent()) } PdfPTable dealerTable = new PdfPTable(4) dealerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER) dealerTable.setTotalWidth(Utilities.millimetersToPoints(100)) dealerTable.setLockedWidth(true) dealerTable.addCell(new Phrase("${footer?.mdseTotal ?: 0}")) dealerTable.addCell(new Phrase("${footer.otherCharges}")) dealerTable.addCell(new Phrase("${footer.invoiceTotalAmount?: 0}")) dealerTable.addCell(new Phrase("${footer?.units ?: ''}")) dealerTable.writeSelectedRows(0, -1, 310, 35, writer.getDirectContent()) } catch(Exception e) { collectErrors << "Exception occured while generating file[Invoice Totals - ${e.message}]" } } } class CommercialFooter extends HelperBuilder { private Document document private PdfWriter writer private PdfImportedPage page private PdfContentByte content Map header List contents List mainData Map footer boolean isProforma ByteArrayOutputStream byteStream CommercialFooter( Document document, PdfWriter writer, PdfImportedPage page, PdfContentByte content, Map header, List contents, List mainData, Map footer, ByteArrayOutputStream byteStream, boolean isProforma ) { this.document = document this.writer = writer this.page = page this.content = content this.header = header this.contents = contents this.mainData = mainData this.footer = footer this.byteStream = byteStream this.isProforma = isProforma } PdfTemplate total void onOpenDocument(PdfWriter writer, Document document) { total = writer.getDirectContent().createTemplate(30, 30) } void addHeader() { try { companyHeader() companyAddressHeader() dealerInfo() dealerAddresses() orderInfo() lineDetailHeader() } catch(Exception e) { e.printStackTrace() } } void companyHeader() { PdfPTable companyTable = new PdfPTable(3) companyTable.with { setTotalWidth(Utilities.millimetersToPoints(200)) setLockedWidth(true) disableBorders(addCell(getCell(this.header?.name?.toString(), new Font(Font.FontFamily.HELVETICA, 15, Font.BOLD), ALIGN_LEFT))) if (writer.getPageNumber() > 1) { disableBorders(addCell(getCell('***Continued', new Font(Font.FontFamily.HELVETICA, 15, Font.BOLD), ALIGN_RIGHT))) } else { disableBorders(addCell(getCell('', new Font(Font.FontFamily.HELVETICA, 15, Font.BOLD), ALIGN_RIGHT))) } disableBorders(addCell(getCell('***Original', new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD), ALIGN_RIGHT))) writeSelectedRows(0, -1, 30, 775, writer.getDirectContent()) } } void companyAddressHeader() { if (isProforma) { PdfPTable invoiceTable = new PdfPTable(3) invoiceTable.setTotalWidth(Utilities.millimetersToPoints(250)) invoiceTable.defaultCell.setBorder(Rectangle.NO_BORDER) invoiceTable.setLockedWidth(true) PdfPCell cell cell = disableBorders(new PdfPCell().with { addElement(new Paragraph(header?.address1?.toString(), new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))) addElement(new Paragraph("PO BOX 5222", new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))) addElement(new Paragraph("${header?.city} ${header?.state} ${header?.zip}", new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))) it }) cell.setHorizontalAlignment(Element.ALIGN_LEFT) invoiceTable.addCell(cell) cell = disableBorders(new PdfPCell().with { addElement(new Paragraph("PROFORMA", new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))) it }) cell.setHorizontalAlignment(Element.ALIGN_RIGHT) invoiceTable.addCell(cell) //invoiceTable.addCell(new Phrase('PROFORMA', new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) if (header?.groupId) { cell = disableBorders(new PdfPCell().with { addElement(new Paragraph("Invoice# / Order#", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) addElement(new Paragraph("${header?.salesOrderNumber} /", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) addElement(new Paragraph("${header?.pickingRouteId}", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) addElement(new Paragraph("Group: ${header?.groupId}", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) it }) } else { cell = disableBorders(new PdfPCell().with { addElement(new Paragraph("Invoice# / Order#", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) addElement(new Paragraph("${header?.salesOrderNumber} /", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) addElement(new Paragraph("${header?.pickingRouteId}", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) it }) } cell.setHorizontalAlignment(Element.ALIGN_RIGHT) invoiceTable.addCell(cell) invoiceTable.writeSelectedRows(0, -1, 30, 760, writer.getDirectContent()) } else { PdfPTable invoiceTable = new PdfPTable(2) invoiceTable.setTotalWidth(Utilities.millimetersToPoints(350)) invoiceTable.setLockedWidth(true) PdfPCell cell cell = disableBorders(new PdfPCell().with { addElement(new Paragraph(header?.address1?.toString(), new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))) addElement(new Paragraph("PO BOX 5222", new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))) addElement(new Paragraph("${header?.city} ${header?.state} ${header?.zip}", new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL))) it }) cell.setHorizontalAlignment(Element.ALIGN_LEFT) invoiceTable.addCell(cell) if (header.groupId) { cell = disableBorders(new PdfPCell().with { addElement(new Paragraph("Invoice# / Order#", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) addElement(new Paragraph("${header?.salesOrderNumber} /", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) addElement(new Paragraph("${header?.pickingRouteId}", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) addElement(new Paragraph("Group: ${header?.groupId}", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) it }) } else { cell = disableBorders(new PdfPCell().with { addElement(new Paragraph("Invoice# / Order#", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) addElement(new Paragraph("${header?.salesOrderNumber} /", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) addElement(new Paragraph("${header?.pickingRouteId}", new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))) it }) } cell.setHorizontalAlignment(Element.ALIGN_RIGHT) invoiceTable.addCell(cell) invoiceTable.writeSelectedRows(0, -1, 30, 760, writer.getDirectContent()) } } void dealerInfo() { PdfPTable dealerTable = new PdfPTable(5) dealerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER) int[] sizes = [15, 30, 30, 30, 10] dealerTable.setWidths(sizes) dealerTable.setTotalWidth(Utilities.millimetersToPoints(200)) dealerTable.setLockedWidth(true) dealerTable.with { disableBorders(addCell(getCell(this.header?.dealerCode?.toString(), 0, new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD)))) disableBorders(addCell(getCell("Tel: ${this.header?.dealerPhoneNumber}", 0, new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL)))) disableBorders(addCell(getCell("Fax:${this.header?.dealerFaxNumber}", 0, new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL)))) writer.getPageNumber() > 1 ? disableBorders(addCell(getCell("SHIPPED FROM: ${this.header?.warehouseCode} Page: ${writer.getPageNumber()}", 4, new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL)))) : disableBorders(addCell(getCell("SHIPPED FROM: ${this.header?.warehouseCode}", 4, new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL)))) } dealerTable.writeSelectedRows(0, -1, 30, 705, writer.getDirectContent()) } void dealerAddresses() { PdfPTable addressTable = new PdfPTable(2) addressTable.setWidthPercentage(600) addressTable.setTotalWidth(300, 300) addressTable.getDefaultCell().setBorder(Rectangle.NO_BORDER) PdfPTable innerAT2 = new PdfPTable(2) innerAT2.setWidthPercentage(100) innerAT2.setTotalWidth(3, 30) PdfPCell cellAT3 cellAT3 = new PdfPCell() cellAT3.addElement(new Paragraph("S", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) cellAT3.addElement(new Paragraph("O", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) cellAT3.addElement(new Paragraph("L", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) cellAT3.addElement(new Paragraph("D", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) cellAT3.addElement(new Paragraph("", new Font(Font.FontFamily.HELVETICA, 5, Font.NORMAL))) cellAT3.addElement(new Paragraph("T", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) cellAT3.addElement(new Paragraph("O", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) cellAT3.setBorder(0) cellAT3.setColspan(0) innerAT2.addCell(cellAT3) PdfPCell cellAT4 cellAT4 = new PdfPCell() cellAT4.addElement(new Paragraph(header?.soldTo?.toString(), new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) cellAT4.addElement(new Paragraph(header?.soldToAddressLine1?.toString(), new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) if (header?.soldToAddressLine2) { cellAT4.addElement(new Paragraph(header?.soldToAddressLine2?.toString(), new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) } cellAT4.addElement(new Paragraph("${header?.soldToCity} ${header?.soldToState} ${header?.soldToPostalCode}, ${header?.soldToCountryName}", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) if (header?.extraSoldToAddressLine) { cellAT4.addElement(new Paragraph(header?.extraSoldToAddressLine?.toString(), new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) } cellAT4.setBorder(0) innerAT2.addCell(cellAT4) addressTable.addCell(innerAT2) PdfPTable innerAT1 = new PdfPTable(2) innerAT1.setWidthPercentage(100) innerAT1.setTotalWidth(3, 30) PdfPCell cellAT1 = new PdfPCell() cellAT1.identity { setBorder(0) setColspan(0) addElement(new Paragraph("S", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) addElement(new Paragraph("H", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) addElement(new Paragraph("I", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) addElement(new Paragraph("P", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) addElement(new Paragraph("", new Font(Font.FontFamily.HELVETICA, 5, Font.NORMAL))) addElement(new Paragraph("T", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) addElement(new Paragraph("O", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) } innerAT1.addCell(cellAT1) PdfPCell cellAT2 cellAT2 = new PdfPCell() if (header?.forwarderAddressLine1) { cellAT2.addElement(new Paragraph(header?.forwardTo?.toString(), new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) cellAT2.addElement(new Paragraph(header?.forwarderAddressLine1?.toString(), new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) if (header?.forwarderAddressLine2) { cellAT2.addElement(new Paragraph(header?.forwarderAddressLine2?.toString(), new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) } cellAT2.addElement(new Paragraph("${header?.forwarderCity} ${header?.forwarderState} ${header?.forwarderPostalcode}, ${header?.forwarderCountryName} ", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) } else { cellAT2.addElement(new Paragraph(header?.shipTo?.toString(), new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) cellAT2.addElement(new Paragraph(header?.shipToAddressLine1?.toString(), new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) if (header?.shipToAddressLine2) { cellAT2.addElement(new Paragraph(header?.shipToAddressLine2?.toString(), new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) } cellAT2.addElement(new Paragraph("${header?.shipToCity} ${header?.shipToState} ${header?.shipToPostalCode}, ${header?.shipToCountryName}", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) } if (header?.extraShipToAddressLine) { cellAT2.addElement(new Paragraph(header?.extraShipToAddressLine?.toString(), new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))) } cellAT2.setBorder(0) innerAT1.addCell(cellAT2) addressTable.addCell(innerAT1) addressTable.writeSelectedRows(0, -1, 30, 696, writer.getDirectContent()) } void orderInfo() { PdfPTable mainTable = new PdfPTable(10) mainTable.setTotalWidth(Utilities.millimetersToPoints(200)) mainTable.setLockedWidth(true) mainTable.getDefaultCell().setBorder(PdfPCell.NO_BORDER) mainTable.with { singleBorderDisable(addCell(getCell('DATE ORDER', this.header?.orderDate ? new SimpleDateFormat('yyyy-MM-dd')?.format(this.header?.orderDate) : '', 2, 1, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))), 4) addCell(getCell('CUST. REFERENCE', this.header?.customerReference?.toString(), 3, 1, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))) addCell(getCell('TERMS', this.header?.terms?.toString(), 1, 1, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))) addCell(getCell('TAKEN BY', this.header?.takenBy?.toString(), 0, 1, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))) singleBorderDisable(addCell(getCell('SALESPERSON', this.header?.salesman?.toString(), 3, 1, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))), 8) singleBorderDisable(addCell(getCell('WEIGHT', "${this.mainData*.grossWeight?.contains() ? '' : this.mainData*.grossWeight?.sum()}", 1, 1, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))), 4) addCell(getCell('ORDERED BY', this.header?.orderedBy?.toString(), 2, 1, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))) addCell(getCell('FREIGHT', this.header?.freight?.toString(), 2, 1, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))) addCell(getCell('VIA', this.header?.shipViaDescr?.toString(), 3, 1, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))) singleBorderDisable(addCell(getCell('DATE SHIPPED', this.header?.confirmedShippingDate ? new SimpleDateFormat('yyyy-MM-dd')?.format(this.header?.confirmedShippingDate) : '', 3, 1, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))), 8) } mainTable.writeSelectedRows(0, -1, 28, 610, writer.getDirectContent()) } void lineDetailHeader() { PdfPTable table = new PdfPTable(9) int[] sizes = [1, 1, 1, 3, 2, 1, 1,1, 1] table.setWidths(sizes) table.setWidthPercentage(100f) table.setTotalWidth(570f) table.with { PdfPCell mcell disableListOfBorders(table.addCell(getCell("ITEM NO.", 0, 2, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))), [PdfPCell.LEFT, PdfPCell.TOP]) mcell = new PdfPCell(new Phrase("QUANTITY", new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))) mcell.setColspan(2) mcell.disableBorderSide(PdfPCell.TOP) table.addCell(mcell) disableListOfBorders(table.addCell(getCell("Description", 0, 2, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCell("PartNumber", 1, 2, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCell("U/M", 0, 2, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCell("QTY SHIP", 0, 2, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCell("Unit Price", 0, 2, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))), [PdfPCell.TOP]) disableListOfBorders(table.addCell(getCell("Amount", 0, 2, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))), [PdfPCell.TOP, PdfPCell.RIGHT]) table.addCell(getCell("Order", 0, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))) table.addCell(getCell("B.O", 0, new Font(Font.FontFamily.HELVETICA, 8, Font.BOLD))) } table.writeSelectedRows(0, -1, 28, 540, writer.getDirectContent()) } void addFooter() { createPageNumberTable() createTotalsTable() } private void createPageNumberTable() { PdfPTable pageTable = new PdfPTable(2) pageTable.getDefaultCell().setBorder(Rectangle.NO_BORDER) pageTable.setWidthPercentage(100f) pageTable.setTotalWidth(49, 49) PdfPCell cell = new PdfPCell(new Phrase("Page ${writer.getPageNumber()} of", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))) cell.setMinimumHeight(0) cell.setBorder(0) cell.setHorizontalAlignment(Element.ALIGN_LEFT) pageTable.addCell(cell) cell = new PdfPCell(Image.getInstance(total)) cell.setBorder(0) cell.setMinimumHeight(0) pageTable.addCell(cell) pageTable.writeSelectedRows(0, -1, 20, 38, writer.getDirectContent()) } private void createTotalsTable() { PdfPTable dealerTable = new PdfPTable(4) dealerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER) dealerTable.setTotalWidth(Utilities.millimetersToPoints(100)) dealerTable.setLockedWidth(true) disableListOfBorders(dealerTable.addCell(getCell("MDSE TOTAL", ' ', 0, 4, new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL))), [PdfPCell.TOP, PdfPCell.BOTTOM]) disableListOfBorders(dealerTable.addCell(getCell("OTHER CHARGES", ' ', 1, 4, new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL))), [PdfPCell.TOP, PdfPCell.BOTTOM]) disableListOfBorders(dealerTable.addCell(getCell("INVOICE TOTAL ", ' ', 0, 4, new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL))), [PdfPCell.TOP, PdfPCell.BOTTOM]) disableListOfBorders(dealerTable.addCell(getCell("UNITS", ' ', 0, 4, new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL))), [PdfPCell.RIGHT, PdfPCell.TOP, PdfPCell.BOTTOM]) dealerTable.writeSelectedRows(0, -1, 310, 50, writer.getDirectContent()) } void onEndPage(PdfWriter writer, Document document) { this.writer.directContentUnder.addTemplate(writer.getDirectContent().createTemplate(30, 30), 0, 0) addHeader() addFooter() } void onCloseDocument(PdfWriter writer, Document document) { ColumnText.showTextAligned( total, Element.ALIGN_LEFT, new Phrase(String.valueOf(writer.getPageNumber() - 1), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)), -2, 17.9, 0 ) } }