Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package printom; // library imports import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.Phrase; import com.itextpdf.text.pdf.ColumnText; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfStamper; import com.itextpdf.text.pdf.PdfWriter; import java.awt.Desktop; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Angel */ public class PDFCreator { /** * A resulting PDF file. */ private static final String CTNLABEL = "label.pdf"; public static final String RESULTLABEL = "newLabel.pdf"; private static final String REPORT = "report.pdf"; public static final String RESULTREPORT = "newReport.pdf"; public static void createLabel(int aLabelType, int aJobNum, char aJobIdentifier, String aCustName, String aItemName, String aItemCode, String aDate, String aPOrderNum, int aInputPcs) { String myJobNum = String.valueOf(aJobNum); char myJobIdentifier = aJobIdentifier; String myCustName = aCustName; String myItemName = aItemName; String myItemCode = aItemCode; String myDate = aDate; String myPOrderNum = aPOrderNum; String myInputPcs = String.valueOf(aInputPcs); try { String src = ""; if (aLabelType == 1) { src = CTNLABEL; } String dest = RESULTLABEL; Font timesJob = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.WHITE); Font timesDef = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK); PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); PdfContentByte canvas = stamper.getOverContent(1); for (int k = 0; k < 3; k++) { //Positions int[] x = { 298, 350, 125, 80, 80, 80, 80, 120 }; int[] y = { 562, 562, 518, 498, 479, 459, 440, 420 }; if (k == 1) { for (int j = 0; j < 8; j++) { y[j] = y[j] - 186; } } if (k == 2) { for (int j = 0; j < 8; j++) { y[j] = y[j] - 372; } } for (int i = 0; i < 2; i++) { if (i == 1) { for (int j = 0; j < 8; j++) { x[j] = x[j] + 372; } } ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myJobNum, timesJob), x[0], y[0], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(String.valueOf(myJobIdentifier), timesDef), x[1], y[1], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myCustName, timesDef), x[2], y[2], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myItemName, timesDef), x[3], y[3], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myItemCode, timesDef), x[4], y[4], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myDate, timesDef), x[5], y[5], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myPOrderNum, timesDef), x[6], y[6], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myInputPcs, timesDef), x[7], y[7], 0); } } stamper.close(); reader.close(); } catch (IOException | DocumentException ex) { Logger.getLogger(PDFCreator.class.getName()).log(Level.SEVERE, null, ex); } } public static void createReport(int aJobNum, char aJobIdentifier, String aCustName, String aItemName, String aItemCode, String aDate, String aPOrderNum, int aInputPcs, int aQtyWithOvers, int aNumContainers, String aInputContainer) { String myJobNum = String.valueOf(aJobNum); char myJobIdentifier = aJobIdentifier; String myCustName = aCustName; String myItemName = aItemName; String myItemCode = aItemCode; String myDate = aDate; String myPOrderNum = aPOrderNum; String myInputPcs = String.valueOf(aInputPcs); int myQtyWithOvers = aQtyWithOvers; int myNumContainers = aNumContainers; String myInputContainer = aInputContainer; double amount = myQtyWithOvers; DecimalFormat formatter = new DecimalFormat("#,###"); String myStrQtyWithOvers = formatter.format(amount); try { String src = REPORT; String dest = RESULTREPORT; Font timesJob = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD, BaseColor.WHITE); Font timesDef = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK); PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); PdfContentByte canvas = stamper.getOverContent(1); int[] x = { 441, 510, 426, 87, 87, 87, 426, 307, 218, 325, 426 }; int[] y = { 547, 547, 473, 450, 428, 473, 450, 325, 385, 385, 428 }; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myJobNum, timesJob), x[0], y[0], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(String.valueOf(myJobIdentifier), timesDef), x[1], y[1], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myCustName, timesDef), x[2], y[2], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myItemName, timesDef), x[3], y[3], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myItemCode, timesDef), x[4], y[4], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myDate, timesDef), x[5], y[5], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myPOrderNum, timesDef), x[6], y[6], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myInputPcs, timesDef), x[7], y[7], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myStrQtyWithOvers, timesDef), x[8], y[8], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("(" + String.valueOf(myNumContainers) + " cases with overs)", timesDef), x[9], y[9], 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myInputContainer, timesDef), x[10], y[10], 0); stamper.close(); reader.close(); } catch (IOException | DocumentException ex) { Logger.getLogger(PDFCreator.class.getName()).log(Level.SEVERE, null, ex); } } public static void createBOL(ArrayList<Shipment> aShipmentList, int aTemplate) { ArrayList<Shipment> shipmentList = aShipmentList; Order chosenOrder = shipmentList.get(0).getChosenOrder(); String bolCode = shipmentList.get(0).getBolCode(); String bolFileName = bolCode + ".pdf"; String myCustName = Customer.getCustomerName(chosenOrder.getCustID()); String myShipDate = Prompter.dateString(shipmentList.get(0).getDateShipped()); String myCarrier = shipmentList.get(0).getCarrier(); String myInstructs = shipmentList.get(0).getInstructions(); Address myAddress = Address.retAddress(shipmentList.get(0).getChosenOrder().getShipAddressID()); try { //BaseFont bf1 = BaseFont.createFont("c:/windows/fonts/consola.ttf", //BaseFont.WINANSI, BaseFont.EMBEDDED); Font timesJob = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD, BaseColor.WHITE); Font timesDef = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK); Font courierNorm = new Font(Font.FontFamily.COURIER, 11, Font.NORMAL, BaseColor.BLACK); Font courierSBig = new Font(Font.FontFamily.COURIER, 13, Font.NORMAL, BaseColor.BLACK); // step 1 Document document = new Document(PageSize.LETTER, 18, 18, 126, 54); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(bolFileName)); // step 3 document.open(); // step 4 // we set the compression to 0 so that we can read the PDF syntax writer.setCompressionLevel(0); // writes something to the direct content using a convenience method PdfContentByte canvas = writer.getDirectContentUnder(); // Graphic Letterheard Image image = Image.getInstance("AresLH.jpg"); image.scalePercent(50f); image.setAbsolutePosition(43, 680); if (aTemplate == 1) document.add(image); // 11" = 792 // 8.5 = 612 // TEXT SIZE = 11 // LINE SPACING = 11 // PARAGRAPH SPACE = 3 * 11 int myPageWidth = 612; int myPageHeight = 792; int myTopMargin = 655; int myTopSubMargin = 622; int myPageLeftMargin = 54; // HEADER LINES ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ARES BOL# " + bolCode, courierNorm), myPageLeftMargin, myTopMargin, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("DATE: " + myShipDate, courierNorm), myPageWidth - myPageLeftMargin, myTopMargin, 0); // CONSIGNEE ADDRESS int myAddressStartY = myTopSubMargin; int myCurrentY = myTopSubMargin; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CONSIGNEE", courierNorm), myPageLeftMargin, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ADDRESS:", courierNorm), myPageLeftMargin, myCurrentY, 0); myCurrentY = myAddressStartY; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myAddress.getAttention(), courierNorm), 125, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myAddress.getAddress1(), courierNorm), 125, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myAddress.getCity() + ", " + myAddress.getState() + " " + myAddress.getZipCode(), courierNorm), 125, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myAddress.getLastLine(), courierNorm), 125, myCurrentY, 0); // FROM ADDRESS myCurrentY = myAddressStartY; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("FROM:", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Ares Printing & Packaging", courierNorm), 98 + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("63 Flushing Ave, Bldg 5", courierNorm), 98 + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Brooklyn Navy Yard", courierNorm), 98 + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Brooklyn, NY 11205", courierNorm), 98 + 288, myCurrentY, 0); // CARRIER, FOB AND SPECIAL INSTRUCTIONS myCurrentY -= 33; int myItemStartY = myCurrentY; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CARRIER: " + myCarrier, courierNorm), myPageLeftMargin, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("FOB: Brooklyn", courierNorm), myPageLeftMargin, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("SPECIAL INSTRUCTIONS: " + myInstructs, courierNorm), myPageLeftMargin, myCurrentY, 0); int myBOLTPallets = 0; int myBOLTCases = 0; int myBOLTPieces = 0; myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); // Start Item/ShipLine Information for (Shipment shipment : shipmentList) { ArrayList<Inventory> shipInventoryList = shipment.getInvenList(); ArrayList<Inventory.InventoryLine> invenLineList = new ArrayList<>(); Item item = new Item(shipInventoryList.get(0).getItemID()); String apo = ""; for (int i = 0; i < shipInventoryList.size(); i++) { if (i == 0) { apo += shipInventoryList.get(i).getJobNum(); } else { apo += ", " + shipInventoryList.get(i).getJobNum(); } invenLineList.addAll(shipInventoryList.get(i).getInvenLines()); } //START ITEM myCurrentY -= 22; if (myCurrentY < 100) { document.newPage(); if (aTemplate == 1) { document.add(image); } myCurrentY = myTopSubMargin; } ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM NAME: " + item.getItemName(), courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CUSTOMER PO#: " + chosenOrder.getPOrderNum(), courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM CODE: " + item.getItemCode(), courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("APO: " + apo, courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // ITEM 1 myCurrentY -= 12; int myItemTPallets = 0; int myItemTCases = 0; int myItemTPieces = 0; for (Inventory.InventoryLine invenLine : invenLineList) { ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase(String.valueOf(invenLine.getPallets()), courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase(String.valueOf(invenLine.getCases()), courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase(String.valueOf(invenLine.getPieces()), courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // LINE 2 myCurrentY -= 11; myItemTPallets += invenLine.getPallets(); myItemTCases += invenLine.getPallets() * invenLine.getCases(); myItemTPieces += invenLine.getPallets() * invenLine.getCases() * invenLine.getPieces(); myBOLTPallets += myItemTPallets; myBOLTCases += myItemTCases; myBOLTPieces += myItemTPieces; } myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned( canvas, Element.ALIGN_LEFT, new Phrase(" PALLETS: " + myItemTPallets + " CASES: " + myItemTCases + " QUANTITY: " + myItemTPieces, courierNorm), myPageLeftMargin + 95, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* //START ITEM myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // ITEM 1 myCurrentY -= 12; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // LINE 2 myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 33; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(" PALLETS: 12 CASES: 282 QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); ////////////// //END ITEM ////////////// myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 6; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); ////////////// //END ITEM ////////////// myCurrentY -= 12; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // LINE 2 myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 1; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); myCurrentY -= 33; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(" PALLETS: 12 CASES: 282 QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0); myCurrentY -= 11; ////////////// //START ITEM ////////////// ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); //START ITEM myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 6; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); // ITEM 1 myCurrentY -= 12; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // LINE 2 myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 1; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); myCurrentY -= 33; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(" PALLETS: 12 CASES: 282 QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); ////////////// //END ITEM ////////////// */ ////////////// //START FOOTER ////////////// myCurrentY -= 33; if (myCurrentY < 85) { document.newPage(); myCurrentY = myTopSubMargin; } ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("SHIPMENT RECEIVED IN GOOD CONDITION BY:", courierNorm), myPageLeftMargin + 128, myCurrentY, 0); myCurrentY -= 33; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("______________________________________", courierNorm), myPageLeftMargin + 128, myCurrentY, 0); myCurrentY -= 16; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("(SIGNATURE) (DATE & TIME)", courierNorm), myPageLeftMargin + 128, myCurrentY, 0); myCurrentY += 49; ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("TOTAL PALLETS: " + myBOLTPallets, courierSBig), myPageLeftMargin + 500, myCurrentY, 0); myCurrentY -= 13; ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("TOTAL CASES: " + myBOLTCases, courierSBig), myPageLeftMargin + 500, myCurrentY, 0); myCurrentY -= 13; ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("TOTAL WEIGHT: ~" + ((myBOLTCases * 25) + (myBOLTPallets * 40)) + " lbs", courierSBig), myPageLeftMargin + 500, myCurrentY, 0); ////////////// //END FOOTER ////////////// /* document.newPage(); myCurrentY = myTopSubMargin; ////////////// //START ITEM ////////////// ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); //START ITEM myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 6; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); // ITEM 1 myCurrentY -= 12; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // LINE 2 myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 1; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); myCurrentY -= 33; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(" PALLETS: 12 CASES: 282 QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); ////////////// //END ITEM ////////////// */ // step 5 document.close(); if (Desktop.isDesktopSupported()) { try { File f = new File(bolFileName); Desktop.getDesktop().open(f); } catch (IOException ex) { // no application registered for PDFs } } } catch (IOException | DocumentException ex) { Logger.getLogger(PDFCreator.class.getName()).log(Level.SEVERE, null, ex); } } }