List of usage examples for com.itextpdf.text Image scalePercent
public void scalePercent(final float percent)
From source file:pdfTemplates.Drillpdf.java
public void PrintPressed(jugada selectedPlay, File fileSavePath) throws DocumentException, IOException { // step 1//from w ww . ja v a 2s . c o m Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(fileSavePath.getPath())); // step 3 document.open(); // step 4 document.add(new Paragraph(messages.getString("Name") + ": " + selectedPlay.getNombreJugada())); document.add(new Paragraph(messages.getString("Type") + ": " + selectedPlay.getTipoJugada())); document.add(new Paragraph(messages.getString("Subtype") + ": " + selectedPlay.getSubtipoJugada())); document.add(new Paragraph(" ")); int contador = 1; while (contador < selectedPlay.getContadorJugada() + 1) { document.add(new Paragraph(messages.getString("Diagram") + " " + contador)); document.add(new Paragraph(" ")); Image image2 = Image.getInstance(selectedPlay.getNombreJugada() + "-" + selectedPlay.getTipoJugada() + "-" + selectedPlay.getSubtipoJugada() + "_" + contador); image2.scalePercent(50); PdfPTable table = new PdfPTable(2); table.addCell(image2); table.addCell(textPdf.textPdf(contador, selectedPlay.getDescripcionJugada(), selectedPlay.getContadorJugada())); document.add(table); contador++; } document.close(); }
From source file:printInv.GenerateInvoice.java
public void generateLayout(Document doc, PdfContentByte cb) { try {/*w w w .ja v a 2s .c o m*/ cb.setLineWidth(1f); // Invoice Header box layout cb.rectangle(420, 700, 150, 60); cb.moveTo(420, 720); cb.lineTo(570, 720); cb.moveTo(420, 740); cb.lineTo(570, 740); cb.moveTo(480, 700); cb.lineTo(480, 760); cb.stroke(); // Invoice Header box Text Headings createHeadings(cb, 422, 743, "Invoice No."); createHeadings(cb, 422, 723, "Name"); createHeadings(cb, 422, 703, "Invoice Date"); // Invoice Detail box layout cb.rectangle(20, 50, 550, 600); cb.moveTo(20, 630); cb.lineTo(570, 630); cb.moveTo(50, 50); cb.lineTo(50, 650); cb.moveTo(360, 50); cb.lineTo(360, 650); cb.moveTo(430, 50); cb.lineTo(430, 650); cb.moveTo(500, 50); cb.lineTo(500, 650); cb.stroke(); // Invoice Detail box Text Headings createHeadings(cb, 22, 633, "SNo."); createHeadings(cb, 52, 633, "Product ID"); createHeadings(cb, 362, 633, "Quantity"); createHeadings(cb, 432, 633, "Unit Price"); createHeadings(cb, 502, 633, "Line Total"); //add the images Image companyLogo = Image.getInstance("src/image/icon.png"); companyLogo.setAbsolutePosition(25, 700); companyLogo.scalePercent(25); doc.add(companyLogo); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:printom.PDFCreator.java
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 {/* w ww . ja v a 2 s.c om*/ //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); } }
From source file:reporteFertilizacion.ReporteResultadoLaboratorio.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww.j a v a 2 s .c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); try { Font font9BoldWhite = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.BOLD, BaseColor.WHITE); Font font7Bold = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.BOLD); Font font7Normal = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.NORMAL); Font font8Bold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD); Font font8Normal = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL); Font font9Bold = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.BOLD); Font font9Normal = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL); Font font10Bold = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD); Font font10Normal = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL); Font font12Bold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); Font font12Normal = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); Font font14Bold = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD); Font font14Normal = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL); Font font18Bold = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD); Font font22Bold = FontFactory.getFont(FontFactory.HELVETICA, 22, Font.BOLD); //obtencion parametros ********************************************************* FacesContext facesContext = FacesContext.getCurrentInstance(); Map params = facesContext.getExternalContext().getRequestParameterMap(); ObjectId parametroObtenido = new ObjectId(params.get("idMuestra").toString()); ResultadoLaboratorio resLab = ResultadoLaboratorio.getResultadoLaboratorioById(parametroObtenido); MuestraLaboratorio muestra = MuestraLaboratorio.getMuestraLaboratorioById(resLab.getMuestra()); Cliente cli = Cliente.getClienteById( Hacienda.getHaciendaById(muestra.getSiembraCultivo().getIdHacienda()).getIdCliente()); Hacienda hac = Hacienda .getHaciendaById(Hacienda.getHaciendaById(muestra.getSiembraCultivo().getIdHacienda()).getId()); //Lote lot = Lote.getLoteById(muestra.getLote()); //String lot = muestra.getLote(); Cultivo cul = Cultivo.getCultivoById(muestra.getSiembraCultivo().getIdCultivo()); String cliente = cli.getNombre().toUpperCase(); String ubicacion = Canton.getCantonById(cli.getCanton()).getNombre() + " - " + Canton.getCantonById(cli.getCanton()).getLeyendaProvincia() + " - " + Canton.getCantonById(cli.getCanton()).getLeyendaPais(); String codigMuestra = muestra.getCodigo(); String hacienda = hac.getNombre(); String cultivo = cul.getNombre(); //String varie = Variedad.getVariedadById(lot.getIdVariedad()).getNombre(); String varie = muestra.getSiembraCultivo().getLeyendaVariedad(); //String estacionMonitoreo = lot.getEstacion().get(0).getCodigo(); String estacionMonitoreo = muestra.getSiembraCultivo().getUnidadManejo(); //String estacionMonitoreo = muestra.getLoteCompleto().getListadoMonitoreo().get(0).getCodigo(); String tituloProyecto = "Anlisis" + resLab.getLeyendaMatriz(); String tipoMuestra = resLab.getLeyendaMatriz(); String numeroMuestra = Integer.toString( MuestraLaboratorio.getNumberMuestraLaboratorio(muestra.getId(), muestra.getIdSiembraCultivo())); String numeroMonitoreo = numeroMuestra; //String lote = lot.getCodigo(); String lote = ""; int nn = muestra.getSiembraCultivo().getListaLotesSiembra().size(); for (int i = 0; i < nn; i++) { lote = lote.concat(muestra.getSiembraCultivo().getListaLotesSiembra().get(i).getLeyendaLote()); } String muestreador = muestra.getMuestreador(); String fechaMuestreo = muestra.getFechaFormatMuestreo(); String fechaRecepcionMuestra = muestra.getFechaFormatEnvio(); String fechaResultado = resLab.getFechaFormatResultado(); String periodoPrueba = resLab.getFechaFormatRecepcion() + " al " + resLab.getFechaFormatResultado(); String contenidoHoja1 = TextoReporteResultadoLaboratorio.getByReferencia("HOJA 1 TEXTO INFORME") .getDescripcion(); String responsableTecnico = TextoReporteResultadoLaboratorio.getByReferencia("RESPONSABLE TECNICO") .getDescripcion(); String datosLaboratorio = TextoReporteResultadoLaboratorio.getByReferencia("DATOS LABORATORIO") .getDescripcion(); String piePagina = TextoReporteResultadoLaboratorio.getByReferencia("PIE DE PAGINA").getDescripcion(); String contenidoHoja2 = TextoReporteResultadoLaboratorio.getByReferencia("HOJA 2 OBSERVACION") .getDescripcion(); //fin obtencion parametros ***************************************************** /* TODO output your page here. You may use following sample code. */ float left = 60; float right = 30; float top = 0; float bottom = 0; Document document = new Document(PageSize.A4, left, right, top, bottom); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); //FOOTER TABLE ***************************************************************** PdfPTable table = new PdfPTable(1); table.setTotalWidth(550); PdfPCell cell = new PdfPCell(new Phrase(piePagina, font8Normal)); cell.setBackgroundColor(BaseColor.GREEN); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("www.agrorum.com.ec", font9BoldWhite)); cell.setBackgroundColor(BaseColor.ORANGE); cell.setBorder(PdfPCell.NO_BORDER); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); table.addCell(cell); FooterTable event = new FooterTable(table); writer.setPageEvent(event); //FIN FOOTER TABLE ***************************************************************** document.open(); //HOJA 1 ********************************************************************************************************************************* //IMAGE ********************************************************************************** String relativeWebPathAg = "/images/agrorum.png"; String absoluteDiskPathAg = getServletContext().getRealPath(relativeWebPathAg); Image logoAg = Image.getInstance(absoluteDiskPathAg); logoAg.setAbsolutePosition(10f, 750f); logoAg.scalePercent(80f); document.add(logoAg); String relativeWebPathEu = "/images/eurofins.png"; String absoluteDiskPathEu = getServletContext().getRealPath(relativeWebPathEu); Image logoEu = Image.getInstance(absoluteDiskPathEu); logoEu.setAbsolutePosition(500f, 770f); logoEu.scalePercent(60f); document.add(logoEu); //FIN IMAGE ******************************************************************************** //CLIENTE UBICACION MUESTRA***************************************************************** Paragraph parphRepor = new Paragraph("Reporte de anlisis 1/2", font10Normal); parphRepor.setAlignment(Element.ALIGN_RIGHT); parphRepor.setSpacingBefore(90f); Paragraph parphCli = new Paragraph(cliente, font10Bold); parphCli.setAlignment(Element.ALIGN_LEFT); parphCli.setSpacingBefore(15f); Paragraph parphUbi = new Paragraph(ubicacion, font10Bold); parphUbi.setAlignment(Element.ALIGN_LEFT); parphUbi.setSpacingBefore(15f); //PARRAFO combinado con frases******************************************** Phrase p1 = new Phrase("Cdigo de la Muestra: ", font10Normal); Phrase p2 = new Phrase(codigMuestra, font10Bold); Paragraph parphMue = new Paragraph(p1); parphMue.add(p2); parphMue.setAlignment(Element.ALIGN_LEFT); parphMue.setSpacingBefore(15f); //FIN PARRAFO combinado*************************************************** document.add(parphRepor); document.add(parphCli); document.add(parphUbi); document.add(parphMue); //FIN CLIENTE UBICACION MUESTRA************************************************************* //TABLA *********************************************************************************** PdfPTable tableDatos = new PdfPTable(new float[] { 0.20f, 0.80f }); tableDatos.setWidthPercentage(100); tableDatos.addCell(getCell("Propiedad:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(hacienda, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.addCell(getCell("Cultivo Actual:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(cultivo, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.addCell(getCell("Estacin Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(estacionMonitoreo, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.addCell(getCell("Ttulo Proyecto:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(tituloProyecto, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.addCell(getCell("Tipo Muestra:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(tipoMuestra, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.addCell(getCell("Nmero Muestra:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(numeroMuestra, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.addCell(getCell("Nmero Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(numeroMonitoreo, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.addCell(getCell("Lote:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(lote, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.addCell(getCell("Muestreador:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(muestreador.toUpperCase(), PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.addCell(getCell("Fecha Muestreo:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(fechaMuestreo, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.addCell(getCell("Recepcin Muestra:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(fechaRecepcionMuestra, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.addCell(getCell("Perodo de Prueba:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatos.addCell(getCell(periodoPrueba, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatos.setSpacingBefore(20f); document.add(tableDatos); //FIN TABLA ******************************************************************************** //CONTENIDO ******************************************************************************** Paragraph parphCont = new Paragraph(contenidoHoja1, font8Normal); parphCont.setAlignment(Element.ALIGN_JUSTIFIED); parphCont.setSpacingBefore(20f); Paragraph parphLLeida = new Paragraph("LLeida, " + fechaResultado, font8Normal); parphLLeida.setAlignment(Element.ALIGN_LEFT); parphLLeida.setSpacingBefore(20f); Paragraph parphTecnico = new Paragraph(responsableTecnico, font9Bold); parphTecnico.setAlignment(Element.ALIGN_LEFT); parphTecnico.setSpacingBefore(20f); Paragraph parphResponsable = new Paragraph("Responsable Tcnico", font8Normal); parphResponsable.setAlignment(Element.ALIGN_LEFT); parphResponsable.setSpacingBefore(1f); Paragraph parphLaboratorio = new Paragraph(datosLaboratorio, font8Bold); parphLaboratorio.setAlignment(Element.ALIGN_LEFT); parphLaboratorio.setSpacingBefore(30f); document.add(parphCont); document.add(parphLLeida); document.add(parphTecnico); document.add(parphResponsable); document.add(parphLaboratorio); //FIN CONTENIDO **************************************************************************** //FIN HOJA 1 ***************************************************************************************************************************** document.newPage(); //HOJA 2 ********************************************************************************************************************************* //IMAGE ********************************************************************************** String relativeWebPathAg1 = "/images/agrorum.png"; String absoluteDiskPathAg1 = getServletContext().getRealPath(relativeWebPathAg1); Image logoAg1 = Image.getInstance(absoluteDiskPathAg1); logoAg1.setAbsolutePosition(10f, 750f); logoAg1.scalePercent(80f); document.add(logoAg1); String relativeWebPathEu1 = "/images/eurofins.png"; String absoluteDiskPathEu1 = getServletContext().getRealPath(relativeWebPathEu1); Image logoEu1 = Image.getInstance(absoluteDiskPathEu1); logoEu1.setAbsolutePosition(500f, 770f); logoEu1.scalePercent(60f); document.add(logoEu1); Paragraph ini = new Paragraph("", font12Bold); ini.setAlignment(Element.ALIGN_CENTER); ini.setSpacingBefore(100f); PdfPTable cabT = new PdfPTable(new float[] { 1f }); cabT.setWidthPercentage(100); PdfPCell cellCab = new PdfPCell(new Phrase("Informe de Prueba", font12Bold)); cellCab.setPadding(2f); cellCab.setHorizontalAlignment(Element.ALIGN_CENTER); cabT.addCell(cellCab); Paragraph parphRep = new Paragraph("Reporte de anlisis 2/2", font10Normal); parphRep.setAlignment(Element.ALIGN_RIGHT); document.add(ini); document.add(cabT); document.add(parphRep); //TABLA *********************************************************************************** PdfPTable tableDatosH2 = new PdfPTable(new float[] { 0.20f, 0.80f }); tableDatosH2.setWidthPercentage(100); tableDatosH2.addCell(getCell("Cliente:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(cliente, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.addCell(getCell(" ", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(" ", PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.addCell(getCell("Propiedad:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(hacienda, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.addCell(getCell("Estacin Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(estacionMonitoreo, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.addCell(getCell("Nmero Monitoreo:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(numeroMuestra, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.addCell(getCell("Codigo Muestra:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(codigMuestra, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.addCell(getCell("Matriz:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(tipoMuestra, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.addCell(getCell("Cultivo:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(cultivo, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.addCell(getCell("Variedad:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(varie, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.addCell(getCell("Fecha Muestreo:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(fechaMuestreo, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.addCell(getCell("Recepcin Muestra:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(fechaRecepcionMuestra, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.addCell(getCell("Perodo de Prueba:", PdfPCell.ALIGN_LEFT, font8Normal)); tableDatosH2.addCell(getCell(periodoPrueba, PdfPCell.ALIGN_LEFT, font8Bold)); tableDatosH2.setSpacingBefore(20f); document.add(tableDatosH2); //FIN TABLA ******************************************************************************** Paragraph parphCont1 = new Paragraph(contenidoHoja2, font8Normal); parphCont1.setAlignment(Element.ALIGN_JUSTIFIED); parphCont1.setSpacingBefore(20f); PdfPTable tableDatosH3 = new PdfPTable(new float[] { 0.30f, 0.70f }); tableDatosH3.setWidthPercentage(100); tableDatosH3.addCell(getCell(datosLaboratorio, PdfPCell.ALIGN_LEFT, font8Bold)); PdfPTable subTable = new PdfPTable(new float[] { 1f }); subTable.setWidthPercentage(100); subTable.addCell(getCell("LLeida, " + fechaResultado, PdfPCell.ALIGN_CENTER, font8Normal)); subTable.addCell(getCell(" ", PdfPCell.ALIGN_CENTER, font8Normal)); subTable.addCell(getCell(" ", PdfPCell.ALIGN_CENTER, font8Normal)); subTable.addCell(getCell(" ", PdfPCell.ALIGN_CENTER, font8Normal)); subTable.addCell(getCell(responsableTecnico, PdfPCell.ALIGN_CENTER, font9Bold)); subTable.addCell(getCell("Responsable Tcnico", PdfPCell.ALIGN_CENTER, font8Normal)); PdfPCell cellsub = new PdfPCell(subTable); cellsub.setBorder(PdfPCell.NO_BORDER); cellsub.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); tableDatosH3.addCell(cellsub); tableDatosH3.setSpacingBefore(20f); document.add(parphCont1); document.add(tableDatosH3); //FIN IMAGE ******************************************************************************** //FIN HOJA 2 ***************************************************************************************************************************** document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } }
From source file:seguimientoprogramatico.GUI.java
private void PDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PDFActionPerformed String Nombre = JOptionPane.showInputDialog("Cmo se llamar el documento?"); BufferedImage img = new BufferedImage(jPanel1.getWidth(), jPanel1.getHeight(), BufferedImage.TYPE_INT_RGB); jPanel1.print(img.getGraphics());// w w w . j a v a 2 s . c o m try { File folder = new File("C:/Documentos/"); if (!folder.exists()) { folder.mkdir(); } ImageIO.write(img, "png", new File("C:/Documentos/" + Nombre + ".png")); } catch (IOException ex) { Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); } Document document = new Document(new com.itextpdf.text.Rectangle(1340, 1739), 0, 0, 0, 0); try { PdfWriter.getInstance(document, new FileOutputStream("C:/Documentos/" + Nombre + ".pdf")); document.open(); Image image1 = Image.getInstance("C:/Documentos/" + Nombre + ".png"); image1.scalePercent(100f); document.add(image1); File imagen = new File("C:/Documentos/" + Nombre + ".png"); imagen.delete(); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Servlets.GenerarPinesGrupo.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String[] idEstudiante = req.getParameterValues("imprimir"); resp.setContentType("application/pdf"); OutputStream out = resp.getOutputStream(); String foto = getServletContext().getRealPath("/recursos/img/logoColegio.png"); req.setCharacterEncoding("UTF-8"); try {/*from w ww . jav a 2 s .c o m*/ try { Document documento = new Document(); PdfWriter.getInstance(documento, out); documento.open(); Paragraph par1 = new Paragraph(); Font fontit = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.GRAY); par1.add(new Phrase("Pin de Acceso HeartsTics", fontit)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); // Image image = Image.getInstance("E:\\ArchivosVarios\\logoColegio.png"); // image.scalePercent(50); Image image = Image.getInstance(foto); image.scalePercent(60); Font fuentetabla = FontFactory.getFont("Arial", 8, Font.BOLD, BaseColor.BLACK); Font fuentetablaPin = FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK); Font fuentetablaHeader = FontFactory.getFont("Arial", 9, Font.BOLD, BaseColor.BLACK); Servicio controlador = new Servicio(); for (int i = 0; i < idEstudiante.length; i++) { int idEst = Integer.parseInt(idEstudiante[i]); Pin estudiante = controlador.pinEstudiante(idEst); PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(60); PdfPCell celdaHeader = new PdfPCell( new Paragraph("COLEGIO SAGRADOS CORAZONES", fuentetablaHeader)); celdaHeader.setVerticalAlignment(Element.ALIGN_MIDDLE); celdaHeader.setHorizontalAlignment(Element.ALIGN_CENTER); celdaHeader.setColspan(3); tabla.addCell(celdaHeader); PdfPCell celda01 = new PdfPCell(image); //PdfPCell celda01 = new PdfPCell(new Paragraph("imagen")); celda01.setHorizontalAlignment(Element.ALIGN_CENTER); celda01.setVerticalAlignment(Element.ALIGN_MIDDLE); celda01.setRowspan(2); celda01.setBorder(Rectangle.NO_BORDER); celda01.setBorder(Rectangle.LEFT); tabla.addCell(celda01); PdfPCell celda1 = new PdfPCell(new Paragraph( "Estudiante: " + estudiante.getNombres() + " " + estudiante.getApellidos(), fuentetabla)); PdfPCell celda2 = new PdfPCell(new Paragraph("Pin: " + estudiante.getIdPin(), fuentetablaPin)); PdfPCell celda3 = new PdfPCell( new Paragraph("Fecha creacion: " + estudiante.getInicio(), fuentetabla)); PdfPCell celda4 = new PdfPCell( new Paragraph("Fecha vencimiento: " + estudiante.getFin(), fuentetabla)); celda1.setHorizontalAlignment(Element.ALIGN_CENTER); celda1.setVerticalAlignment(Element.ALIGN_MIDDLE); celda1.setColspan(2); celda1.setBorder(Rectangle.NO_BORDER); celda1.setBorder(Rectangle.RIGHT); celda2.setHorizontalAlignment(Element.ALIGN_CENTER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); celda2.setColspan(2); celda2.setBorder(Rectangle.NO_BORDER); celda2.setBorder(Rectangle.RIGHT); PdfPTable tableFecha = new PdfPTable(2); tableFecha.setWidthPercentage(60); celda3.setHorizontalAlignment(Element.ALIGN_CENTER); celda4.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda1); tabla.addCell(celda2); tableFecha.addCell(celda3); tableFecha.addCell(celda4); Paragraph par2 = new Paragraph(); par2.add(new Phrase(Chunk.NEWLINE)); documento.add(par2); documento.add(tabla); documento.add(tableFecha); } documento.close(); } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:Servlets.GenerarPinEstudiante.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { int idEstudiante = Integer.parseInt(req.getParameter("idEst")); resp.setContentType("application/pdf"); OutputStream out = resp.getOutputStream(); String foto = getServletContext().getRealPath("/recursos/img/logoColegio.png"); req.setCharacterEncoding("UTF-8"); try {/*ww w. j a va 2 s . c om*/ try { Document documento = new Document(); PdfWriter.getInstance(documento, out); documento.open(); Paragraph par1 = new Paragraph(); Font fontit = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.GRAY); par1.add(new Phrase("Pin de Acceso HeartsTics", fontit)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); // Image image = Image.getInstance("E:\\ArchivosVarios\\logoColegio.png"); // image.scalePercent(50); Image image = Image.getInstance(foto); image.scalePercent(60); Font fuentetabla = FontFactory.getFont("Arial", 8, Font.BOLD, BaseColor.BLACK); Font fuentetablaPin = FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK); Font fuentetablaHeader = FontFactory.getFont("Arial", 9, Font.BOLD, BaseColor.BLACK); Servicio controlador = new Servicio(); Pin estudiante = controlador.pinEstudiante(idEstudiante); PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(60); PdfPCell celdaHeader = new PdfPCell(new Paragraph("COLEGIO SAGRADOS CORAZONES", fuentetablaHeader)); celdaHeader.setVerticalAlignment(Element.ALIGN_MIDDLE); celdaHeader.setHorizontalAlignment(Element.ALIGN_CENTER); celdaHeader.setColspan(3); tabla.addCell(celdaHeader); PdfPCell celda01 = new PdfPCell(image); //PdfPCell celda01 = new PdfPCell(new Paragraph("imagen")); celda01.setHorizontalAlignment(Element.ALIGN_CENTER); celda01.setVerticalAlignment(Element.ALIGN_MIDDLE); celda01.setRowspan(2); celda01.setBorder(Rectangle.NO_BORDER); celda01.setBorder(Rectangle.LEFT); tabla.addCell(celda01); PdfPCell celda1 = new PdfPCell(new Paragraph( "Estudiante: " + estudiante.getNombres() + " " + estudiante.getApellidos(), fuentetabla)); PdfPCell celda2 = new PdfPCell(new Paragraph("Pin: " + estudiante.getIdPin(), fuentetablaPin)); PdfPCell celda3 = new PdfPCell( new Paragraph("Fecha creacion: " + estudiante.getInicio(), fuentetabla)); PdfPCell celda4 = new PdfPCell( new Paragraph("Fecha vencimiento: " + estudiante.getFin(), fuentetabla)); celda1.setHorizontalAlignment(Element.ALIGN_CENTER); celda1.setVerticalAlignment(Element.ALIGN_MIDDLE); celda1.setColspan(2); celda1.setBorder(Rectangle.NO_BORDER); celda1.setBorder(Rectangle.RIGHT); celda2.setHorizontalAlignment(Element.ALIGN_CENTER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); celda2.setColspan(2); celda2.setBorder(Rectangle.NO_BORDER); celda2.setBorder(Rectangle.RIGHT); PdfPTable tableFecha = new PdfPTable(2); tableFecha.setWidthPercentage(60); celda3.setHorizontalAlignment(Element.ALIGN_CENTER); celda4.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda1); tabla.addCell(celda2); tableFecha.addCell(celda3); tableFecha.addCell(celda4); Paragraph par2 = new Paragraph(); par2.add(new Phrase(Chunk.NEWLINE)); documento.add(par2); documento.add(tabla); documento.add(tableFecha); documento.close(); } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:sistemacontrole.MainWindow.java
public void GerarPDFFuncao() throws BadElementException, IOException { try {/*from w w w . ja v a 2 s.com*/ //Define as fontes Font fontOBS = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL); Font fontTITULO2 = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL); Font fontTITULO = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD); fontTITULO.setColor(BaseColor.RED); Font fontDADO = new Font(Font.FontFamily.TIMES_ROMAN, 9, Font.NORMAL); Document doc = new Document(PageSize.A4.rotate()); // adiciona imagem ao pdf Image Logotipo = Image.getInstance("./src/Imagens/imagem_pdf.png"); Logotipo.scalePercent((float) 47.5); PdfPTable tabelaGrfico = new PdfPTable(2); for (int i = 1; i < this.registro; i++) { Image LogotipoI = Image.getInstance("./Raw_Data/PainelEntrada" + i + ".jpg"); Image LogotipoI2 = Image.getInstance("./Raw_Data/PainelSaida" + i + ".jpg"); tabelaGrfico.addCell(LogotipoI); tabelaGrfico.addCell(LogotipoI2); } int count = this.tabelaDetalhes.getRowCount(); PdfWriter.getInstance(doc, new FileOutputStream(TelaPDF.CampoNome.getText() + ".pdf")); doc.open(); PdfPTable pdfTable = new PdfPTable(this.tabelaDetalhes.getColumnCount()); //adding table headers for (int i = 0; i < 15; i++) { pdfTable.addCell(new Paragraph(this.tabelaDetalhes.getColumnName(i), fontTITULO)); } PdfPTable pdfTableAuxiliar = new PdfPTable(this.tabelaDetalhes.getColumnCount()); String[][] valores = new String[15][15]; for (int i = 0; i < 15; i++) { for (int j = 0; j < 15; j++) { valores[i][j] = ""; } } Object[] obj = null; int contador = 1; for (int i = 0; i < count; i++) { for (int j = 0; j < 15; j++) { try { System.out.println("Valor: " + tabelaDetalhes.getModel().getValueAt(i, j).toString() + "Contado: " + contador); valores[i][j] = tabelaDetalhes.getModel().getValueAt(i, j).toString(); } catch (Exception e) { System.out.println("ERRO DEU contador: " + contador); contador++; } } } for (int i = 0; i < count; i++) { for (int j = 0; j < 15; j++) { pdfTableAuxiliar.addCell(new Paragraph(valores[i][j], fontDADO)); } } Paragraph title = new Paragraph("Sistema de Controle de Tanques - TC Control" + "\n\n", fontTITULO2); title.setAlignment(Paragraph.ALIGN_CENTER); Calendar calendar = new GregorianCalendar(); Date trialTime = new Date(); calendar.setTime(trialTime); Paragraph DIA = new Paragraph("Data: " + calendar.get(Calendar.DATE) + "/" + (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.YEAR)); Paragraph HORA = new Paragraph("Hora: " + calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND)); DIA.setAlignment(Paragraph.ALIGN_RIGHT); HORA.setAlignment(Paragraph.ALIGN_RIGHT); Paragraph espaco = new Paragraph("\n"); Paragraph aviso = new Paragraph("\nGraficos dos Testes ordenados:"); aviso.setAlignment(Paragraph.ALIGN_CENTER); Paragraph autores = new Paragraph( "\n" + "Desenvolvedores: @AlexandeLUZ - @AndersonDIAS - @HigoBESSA - @JaimeDANTAS", fontDADO); autores.setAlignment(Paragraph.ALIGN_CENTER); Paragraph obs = new Paragraph("\n" + "Observaes: " + TelaPDF.observacoes.getText(), fontOBS); obs.setAlignment(Paragraph.ALIGN_CENTER); //PARTE DO CASCATA DO TANQUE 1 Paragraph cascataTitulo = new Paragraph("Parmetros do Tanque 1 (Escravo): ", fontTITULO2); cascataTitulo.setAlignment(Paragraph.ALIGN_CENTER); //PdfPTable pdfTableCascata = new PdfPTable(5); // if(cascata){ // // Paragraph KP = new Paragraph("\n" + // "Kp" ,fontTITULO); // pdfTableCascata.addCell(KP); // Paragraph KD = new Paragraph("\n" + // "Kd" ,fontTITULO); // pdfTableCascata.addCell(KD); // Paragraph KI = new Paragraph("\n" + // "Ki" ,fontTITULO); // pdfTableCascata.addCell(KI); // Paragraph TI = new Paragraph("\n" + // "Ti" ,fontTITULO); // pdfTableCascata.addCell(TI); // Paragraph TD = new Paragraph("\n" + // "Td" ,fontTITULO); // pdfTableCascata.addCell(TD); // Paragraph KP_VALOR = new Paragraph((this.kp_t1),fontDADO); // Paragraph KD_VALOR = new Paragraph((this.kd_t1),fontDADO); // Paragraph KI_VALOR = new Paragraph((this.ki_t1),fontDADO); // Paragraph TI_VALOR = new Paragraph((this.ti_t1),fontDADO); // Paragraph TD_VALOR = new Paragraph((this.td_t1),fontDADO); // pdfTableCascata.addCell(KP_VALOR); // pdfTableCascata.addCell(KD_VALOR); // pdfTableCascata.addCell(KI_VALOR); // pdfTableCascata.addCell(TI_VALOR); // pdfTableCascata.addCell(TD_VALOR); // // } doc.add(Logotipo); doc.add(title); doc.add(pdfTable); doc.add(pdfTableAuxiliar); if (cascata) { doc.add(cascataTitulo); doc.add(espaco); doc.add(pdfTableCascata); } doc.add(obs); doc.add(aviso); //doc.add(espaco); doc.add(tabelaGrfico); doc.add(espaco); doc.add(espaco); doc.add(DIA); doc.add(HORA); doc.add(autores); doc.close(); System.out.println("done"); mostrarAviso("Arquivo criado com sucesso!"); TelaPDF.setVisible(false); } catch (DocumentException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); mostrarErro("Erro ao gerar PDF!"); } catch (FileNotFoundException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); mostrarErro("Erro ao gerar PDF!"); } }
From source file:tn.esprit.twin1.brogrammers.eventify.Eventify.util.TicketGenerator.java
public static void GenerateTicket(Ticket ticket) { Document document = new Document(); try {/*from www . j av a 2s .co m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE)); Rectangle pagesize = new Rectangle(700, 300); document.open(); Paragraph emptyline = new Paragraph(); emptyline.add(new Paragraph(" ")); document.setPageSize(pagesize); document.newPage(); //PIC PdfContentByte canvas = writer.getDirectContentUnder(); Image image = Image.getInstance(IMAGE); //image.scaleAbsolute(pagesize.rotate()); image.setAbsolutePosition(0, 0); canvas.addImage(image); //PIC document.addTitle("Your Access To" + ticket.getEvent().getTitle()); document.addSubject(ticket.getEvent().getTheme()); document.addKeywords(ticket.getEvent().getTitle() + "Ticket"); document.addAuthor("Mohamed Firas Ouertani"); document.addCreator("Mohamed Firas Ouertani"); Paragraph prefacetitle = new Paragraph(); prefacetitle.add(new Paragraph("Your Ticket For " + ticket.getEvent().getTitle(), bigFont)); document.add(prefacetitle); document.add(emptyline); Paragraph prefacetime = new Paragraph(); prefacetime.add(new Paragraph(ticket.getEvent().getStartTime().toString(), greyFont)); document.add(prefacetime); document.add(emptyline); document.add(emptyline); Paragraph prefacetype = new Paragraph(); prefacetype.add(new Paragraph("You Reserved For: " + ticket.getTypeTicket(), catFont)); document.add(prefacetype); //QR BarcodeQRCode qrcode = new BarcodeQRCode( "REF:#" + ticket.getEvent().getId() + "" + ticket.getEvent().getTitle().trim(), 1, 1, null); Image qrcodeImage = qrcode.getImage(); qrcodeImage.setAbsolutePosition(520, 70); qrcodeImage.scalePercent(400); document.add(qrcodeImage); //QR //Bar PdfContentByte cb = writer.getDirectContent(); Barcode128 code128 = new Barcode128(); BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCode("REF:#" + ticket.getEvent().getId() + "" + ticket.getEvent().getTitle().trim()); codeEAN.setCodeType(BarcodeEAN.EAN13); Image codeEANImage = code128.createImageWithBarcode(cb, null, null); codeEANImage.setAbsolutePosition(10, 10); codeEANImage.scalePercent(125); document.add(codeEANImage); //Bar document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:tn.esprit.twin1.brogrammers.eventify.Eventify.util.TicketGenerator.java
public static void qr(Document document) { BarcodeQRCode qrcode = new BarcodeQRCode("fdf".trim(), 30, 30, null); Image qrcodeImage = null; try {//w ww . ja v a 2 s . c o m qrcodeImage = qrcode.getImage(); } catch (BadElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } qrcodeImage.setAbsolutePosition(10, 500); qrcodeImage.scalePercent(800); try { document.add(qrcodeImage); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }