List of usage examples for com.itextpdf.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.itextpdf.text Element ALIGN_LEFT.
Click Source Link
From source file:platnosci.WyszukPlatnosciController.java
public void akcjaDrukuj() { Drukowanie drukPanel = new Drukowanie(null, true); drukPanel.setLocationRelativeTo(null); drukPanel.setVisible(true);// w ww.j av a 2 s .com if (!drukPanel.isDruk()) { return; } FileOutputStream file = null; File druk = null; try { Document document = new Document(); String userPath = System.getProperty("user.home"); druk = new File(userPath + "/Baks wydruki"); if (!druk.exists()) { druk.mkdirs(); } SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); String strdate = ""; Date calendardate = new Date(); strdate = sdf.format(calendardate.getTime()); File wydruk = new File(druk + "/Platnosci - " + strdate + ".pdf"); if (!wydruk.exists()) { try { wydruk.createNewFile(); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } file = new FileOutputStream(wydruk); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(wydruk)); document.open(); PdfPTable table = new PdfPTable(4); // 3 columns. table.setWidthPercentage(100); //Width 100% table.setSpacingBefore(10f); //Space before table table.setSpacingAfter(10f); //Space after table //Set Column widths float[] columnWidths = { 1f, 1f, 1f, 1f }; table.setWidths(columnWidths); BaseFont bf = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); PdfPCell cell1 = new PdfPCell(new Paragraph("Lp", new com.itextpdf.text.Font(bf, 16))); cell1.setPaddingLeft(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(new Paragraph("Firma", new com.itextpdf.text.Font(bf, 16))); cell2.setPaddingLeft(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_LEFT); PdfPCell cell3 = new PdfPCell( new Paragraph("Data patnoci", new com.itextpdf.text.Font(bf, 16))); cell3.setPaddingLeft(10); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_LEFT); PdfPCell cell4 = new PdfPCell(new Paragraph("Kwota", new com.itextpdf.text.Font(bf, 16))); cell4.setPaddingLeft(10); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setVerticalAlignment(Element.ALIGN_LEFT); //To avoid having the cell border and the content overlap, if you are having thick cell borders cell1.setBorder(PdfPCell.NO_BORDER); cell2.setBorder(PdfPCell.NO_BORDER); cell3.setBorder(PdfPCell.NO_BORDER); cell4.setBorder(PdfPCell.NO_BORDER); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); TO_Invoice kryt = new TO_Invoice(); kryt.setDataDo(drukPanel.getDateDo()); kryt.setDataOd(drukPanel.getDateOd()); kryt.setStatus(TO_InvoiceStatus.ZAPLACONA); List<TO_Invoice> listaFaktur = getDaoFactory().getDaoInvoice().getListaInvoiceDruk(getConnection(), kryt); Integer i = 1; for (TO_Invoice item : listaFaktur) { table.addCell(getNewCell(i.toString() + ".")); table.addCell(getNewCell(item.getPaymentCompany().getName())); table.addCell(getNewCell(item.getDataZaplacenia().toString())); table.addCell(getNewCell(TO_Invoice.getWynikSumaKoszt(item.getKoszt()) + " z")); i++; } document.add(table); document.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } catch (FileNotFoundException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); BaksSessionBean.getInstance().fireMessage(widok, "Wydruk", "Pdf do ktrego chcesz zapisa wynik jest otwarty!\n Zamknij i sprbuj jeszcze raz."); } finally { try { file.close(); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); try { desktop.open(druk); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } } BaksSessionBean.getInstance().fireMessage(widok, "Zapis", "Wydruk zapisany w folderze: " + System.getProperty("user.home") + "/Baks wydruki"); }
From source file:platnosci.WyszukPlatnosciController.java
public PdfPCell getNewCell(String nazwa) { BaseFont bf = null;// w w w. j a v a 2s.c o m try { bf = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } catch (DocumentException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell cell = new PdfPCell(new Paragraph(nazwa, new com.itextpdf.text.Font(bf, 12))); cell.setPaddingLeft(10); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_LEFT); return cell; }
From source file:Print.Print.java
public void printIndex(ArrayList<String> imagesPath, String customer) { try {/*ww w.j a va2 s . c om*/ //ArrayList<Image> images = new ArrayList<Image>(); Map<Image, String> dict = new HashMap<Image, String>(); for (String path : imagesPath) { try { System.out.println("path = /home/student" + path); int index = path.lastIndexOf("/"); String photoId = path.substring(index + 1, path.length()); Image newImage = Image.getInstance("/home/student" + path); //images.add(newImage); dict.put(newImage, photoId); } catch (BadElementException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } } System.out.println("Total images = " + dict.size()); Document index = new Document(PageSize.A4.rotate()); FileOutputStream fos = new FileOutputStream("/home/student/Pictures/index.pdf"); PdfWriter writer = PdfWriter.getInstance(index, fos); writer.open(); index.open(); PdfPTable adresTable = new PdfPTable(3); PdfPCell adresCell = new PdfPCell(new Paragraph(customer)); adresCell.setColspan(3); adresTable.addCell(adresCell); adresTable.setHorizontalAlignment(Element.ALIGN_CENTER); adresTable.setWidthPercentage(100); index.add(adresTable); PdfPTable table = new PdfPTable(imagesPath.size()); for (Map.Entry<Image, String> image : dict.entrySet()) { PdfPCell cell = new PdfPCell(); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(10); table.addCell(image.getValue()); cell.addElement(image.getKey()); table.addCell(cell); } index.add(table); //index.add(adresTable); index.close(); writer.close(); System.out.println("Index printed"); // // define pdfprinter and within try clause create // PdfWriter writer = null; // FileOutputStream fos = null; // Document index = new Document(PageSize.A4.rotate()); // File file; // try { // file = new File("/home/student/Pictures/index.pdf"); // if(!file.exists()){ // file.createNewFile(); // // } // String test = "test data"; // fos = new FileOutputStream(file); // fos.write(test.getBytes()); // fos.flush(); // } catch (FileNotFoundException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } catch (IOException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } // // for (BufferedImage image : bufferedImages) { // try { // writer = PdfWriter.getInstance(index, fos); // } catch (DocumentException ex) { // System.out.println(ex.getMessage()); // } // writer.open(); // index.open(); // try { // PdfContentByte pdfCB = new PdfContentByte(writer); // Image newImage = Image.getInstance(pdfCB, image, 1); // index.add(Image.getInstance(newImage)); // } catch (DocumentException ex) { // System.out.println(ex.getMessage()); // } catch (IOException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } // } // index.close(); // writer.close(); // System.out.println("Index done."); } catch (DocumentException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:printom.PDFCreator.java
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;//from w w w .j a v a2s. c om 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); } }
From source file:printom.PDFCreator.java
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;/*w w w .j a v a2 s . co m*/ 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); } }
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 {//from w w w . j a v a2s.c o m //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:psManage.StructSheet.java
public void createPdf(String mainTitle, String subTitle, String url, String userName, //String scanType, String comment,// www . j a va2 s . com //String thisPassCode, String passCodeA, String passCodeB, String fileDir, Boolean noBarCodePrint) throws IOException, DocumentException, RuntimeException { Document document = null; try { // step 1 document = new Document(PageSize.A4, 60, 50, 50, 35); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileDir)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); /* Properties props = new Properties(); String jarPath = System.getProperty("java.class.path"); String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator)+1); FontFactory.registerDirectory("/res"); FontFactory.register("ipag.ttf"); Font ipaGothic = FontFactory.getFont("ipag", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); //10 is the size InputStream is = getClass().getResourceAsStream("/res/ipag.ttf"); */ Properties props = new Properties(); String jarPath = System.getProperty("java.class.path"); String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator) + 1); System.out.println(jarPath); System.out.println(dirPath); System.out.println(System.getProperty("user.dir")); Font ipaGothic = new Font(BaseFont.createFont(System.getProperty("user.dir") + "\\res\\ipag.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 11); Font ipaGothic14 = new Font(BaseFont.createFont(System.getProperty("user.dir") + "\\res\\ipag.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 14); //?(2) PdfPTable pdfPTable = new PdfPTable(2); pdfPTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); pdfPTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.getDefaultCell().setFixedHeight(150); pdfPTable.setWidthPercentage(100f); int pdfPTableWidth[] = { 10, 90 }; pdfPTable.setWidths(pdfPTableWidth); PdfPCell cell_1_1 = new PdfPCell(new Paragraph("??", ipaGothic)); cell_1_1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_1_1.setHorizontalAlignment(Element.ALIGN_CENTER); cell_1_1.setFixedHeight(50); PdfPCell cell_1_2 = new PdfPCell(new Paragraph(mainTitle, ipaGothic)); cell_1_2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_1_2.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell_2_1 = new PdfPCell(new Paragraph("", ipaGothic)); cell_2_1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_2_1.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell_2_2 = new PdfPCell(new Paragraph(subTitle, ipaGothic)); cell_2_2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_2_2.setHorizontalAlignment(Element.ALIGN_CENTER); cell_2_2.setFixedHeight(50); pdfPTable.addCell(cell_1_1); pdfPTable.addCell(cell_1_2); pdfPTable.addCell(cell_2_1); pdfPTable.addCell(cell_2_2); PdfPCell cellUrlKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellUrlKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlKey.setRowspan(2); pdfPTable.addCell(cellUrlKey); PdfPCell cellUrlValue = new PdfPCell(new Paragraph(url, ipaGothic)); Chunk chunk = new Chunk(url, ipaGothic); // ?????????????? System.out.println("??" + chunk.getWidthPoint()); cellUrlValue.setVerticalAlignment(Element.ALIGN_MIDDLE); if (chunk.getWidthPoint() > 410) { // ?????????? cellUrlValue.setHorizontalAlignment(Element.ALIGN_LEFT); } else { // ????????? cellUrlValue.setHorizontalAlignment(Element.ALIGN_CENTER); } cellUrlValue.setFixedHeight(50); pdfPTable.addCell(cellUrlValue); if (url.length() != 0 && !noBarCodePrint) { /* ? BarcodeQRCode qr = new BarcodeQRCode(url, 50, 50, null); PdfPCell cellUrlValueQr = new PdfPCell(qr.getImage()); cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlValueQr.setFixedHeight(80); pdfPTable.addCell(cellUrlValueQr); */ Image image = ZxingUti.getQRCode(url); // SHIFT_JIS com.itextpdf.text.Image iTextImage = com.itextpdf.text.Image.getInstance(image, null); PdfPCell cell = new PdfPCell(iTextImage); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setFixedHeight(100); pdfPTable.addCell(cell); // SIFT_JIS } else { PdfPCell cellUrlValueQr = new PdfPCell(new Paragraph("", ipaGothic)); cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlValueQr.setFixedHeight(80); pdfPTable.addCell(cellUrlValueQr); } PdfPCell cellUserNameKey = new PdfPCell(new Paragraph("", ipaGothic)); cellUserNameKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameKey.setRowspan(2); pdfPTable.addCell(cellUserNameKey); PdfPCell cellUserNameValue = new PdfPCell(new Paragraph(userName, ipaGothic14)); cellUserNameValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValue.setFixedHeight(30); pdfPTable.addCell(cellUserNameValue); if (userName.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(userName); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellUserNameValueBc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValueBc.setFixedHeight(80); pdfPTable.addCell(cellUserNameValueBc); } else { PdfPCell cellUserNameValueBc = new PdfPCell(new Paragraph("---", ipaGothic)); cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValueBc.setFixedHeight(80); pdfPTable.addCell(cellUserNameValueBc); } PdfPCell cellPassCodeKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellPassCodeKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeKey.setRowspan(3); pdfPTable.addCell(cellPassCodeKey); PdfPCell cellPassCodeValue = new PdfPCell(new Paragraph(passCodeA + passCodeB, ipaGothic14)); cellPassCodeValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeValue.setFixedHeight(30); pdfPTable.addCell(cellPassCodeValue); if (passCodeA.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(passCodeA); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellPassCodeA_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeA_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeA_Bc); } else { PdfPCell cellPassCodeA_Bc = new PdfPCell(new Paragraph("---", ipaGothic)); cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeA_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeA_Bc); } if (passCodeB.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(passCodeB); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellPassCodeB_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeB_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeB_Bc); } else { PdfPCell cellPassCodeB_Bc = new PdfPCell(new Paragraph("---", ipaGothic)); cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeB_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeB_Bc); } PdfPCell cellCommentKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellCommentKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellCommentKey.setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.addCell(cellCommentKey); PdfPCell cellCommentValue = new PdfPCell(new Paragraph(comment, ipaGothic)); cellCommentValue.setVerticalAlignment(Element.ALIGN_TOP); cellCommentValue.setHorizontalAlignment(Element.ALIGN_LEFT); cellCommentValue.setFixedHeight(150); pdfPTable.addCell(cellCommentValue); PdfPCell cellIssueKey = new PdfPCell(new Paragraph("", ipaGothic)); cellIssueKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellIssueKey.setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.addCell(cellIssueKey); Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm"); String strDate = sdf.format(cal.getTime()); PdfPCell cellIssueValue = new PdfPCell(new Paragraph(strDate, ipaGothic)); cellIssueValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellIssueValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellIssueValue.setFixedHeight(20); pdfPTable.addCell(cellIssueValue); //?? document.add(pdfPTable); /* // CODE 128 document.add(new Paragraph("?? : " + mainTitle, ipaGothic)); document.add(new Paragraph(" : " + subTitle, ipaGothic)); document.add(new Paragraph("-------------------------------------------------------")); document.add(new Paragraph(" " + strDate)); document.add(new Paragraph("-------------------------------------------------------")); BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.EMBEDDED); Font font = new Font(bf, 12); document.add(new Paragraph("", ipaGothic)); document.add(new Paragraph(url, ipaGothic)); code128.setCode(url); code128.setFont(bf); code128.setX(1); //document.add(code128.createImageWithBarcode(cb, null, null)); document.add(new Paragraph("USER", ipaGothic)); if (userName.length() != 0) { document.add(new Paragraph(userName, ipaGothic)); code128.setCode(userName); code128.setFont(bf); code128.setBarHeight(40f); document.add(code128.createImageWithBarcode(cb, null, null)); } document.add(new Paragraph("CODE", ipaGothic)); if (passCode.length() != 0) { document.add(new Paragraph(passCode, ipaGothic)); code128.setCode(passCode); code128.setFont(bf); document.add(code128.createImageWithBarcode(cb, null, null)); } document.add(new Paragraph("?", ipaGothic)); document.add(new Paragraph(comment, ipaGothic)); */ // step 5 document.close(); } catch (RuntimeException ex) { document.close(); throw ex; } }
From source file:Report.RelatorioCurso.java
/** * Funo para gerar o stream do relatrio anual de atividades * * @param proforiseparada/*w w w . jav a2 s . co m*/ * @param sm * @param sa * @param am * @param aa * @param dtinicial * @param dtfinal * @param ano * @param cursoNome * @param coordenador * @param campus * @return ByteArrayOutputStream */ public ByteArrayOutputStream relatorioAnualDeAtividades(ArrayList<Professororientacaoseparada> proforiseparada, ArrayList<Sumariomatricula> sm, ArrayList<Sumarioaprovado> sa, ArrayList<Alunomatriculado> am, ArrayList<Alunoaprovado> aa, Date dtinicial, Date dtfinal, String ano, String cursoNome, Professor coordenador, Campus campus) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); FacesContext faces = FacesContext.getCurrentInstance(); // pega o contexto da aplicacao realPath = faces.getExternalContext().getRealPath("/"); //realPath = "C:/Users/Alessandro/Desktop/TCC2/SisGES/build/web"; try { BaseFont fHelvetica = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false); BaseFont fHelveticaBOLD = BaseFont.createFont(BaseFont.HELVETICA_BOLD, "Cp1252", false); //---------------------------------------------------------------------- // creation of the document with a certain size and certain margins // may want to use PageSize.LETTER instead Document document = new Document(PageSize.A4, 40, 40, 20, 50); document.addAuthor("SisGES"); // optional document.addSubject("Relatrio"); // opcional document.addKeywords("SisGES"); document.addCreator("iText"); //---------------------------------------------------------------------- // creation of the different writers //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("web/resources/report/alunosMatriculados.pdf")); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setBoxSize("header", new Rectangle(36, 54, 559, 788)); //---------------------------------------------------------------------- // ADICIONA HEADER E FOOTER //---------------------------------------------------------------------- HeaderFooter headerFooter = new HeaderFooter(); writer.setPageEvent(headerFooter); //---------------------------------------------------------------------- // ABRE DOCUMENTO PARA ESCRITA //---------------------------------------------------------------------- document.open(); //---------------------------------------------------------------------- //ADICIONAR LOGO NO DOCUMENTO //---------------------------------------------------------------------- Image logoUfu = Image.getInstance(realPath + "/resources/images/logoUFU.png"); logoUfu.scaleAbsolute(57, 56);//(largura,altura) logoUfu.isImgTemplate(); //add no template //logoUfu.setAbsolutePosition(30, 745); //x ,y por referencia do rodape document.add(logoUfu); Image logoFacom = Image.getInstance(realPath + "/resources/images/logoFacom.png"); logoFacom.scaleAbsolute(62, 55);//(largura,altura) logoFacom.setAbsolutePosition(92, 767); //x ,y por referencia do rodape //logoFacom.isImgTemplate(); //add no template document.add(logoFacom); //---------------------------------------------------------------------- //ADICIONAR CABEALHO //---------------------------------------------------------------------- PdfContentByte univ = writer.getDirectContentUnder(); univ.beginText(); univ.setFontAndSize(fHelvetica, 10); univ.setTextMatrix(349, 805); // x e y univ.showText("UNIVERSIDADE FEDERAL DE UBERLNDIA"); univ.setTextMatrix(405, 790); // x e y univ.showText("FACULDADE DE COMPUTAO"); univ.setTextMatrix(403, 775); // x e y univ.showText("COORDENADORIA DE ESTGIO "); univ.endText(); String info = "Campus Universitrio - " + campus.getNomecampus() + " - CEP " + campus.getCep() + " - " + campus.getCidade() + " - " + campus.getEstadosigla().toUpperCase(); Chunk txtCampus = new Chunk(info); Paragraph paragraph0 = new Paragraph(); paragraph0.setSpacingBefore(-10); paragraph0.setFont(new Font(fHelvetica, 7)); paragraph0.add(txtCampus); paragraph0.setAlignment(Element.ALIGN_RIGHT); document.add(paragraph0); info = "Telefone: " + coordenador.getTelefone() + " Email: " + coordenador.getEmail(); Chunk txtCoordenador = new Chunk(info); Paragraph paragraph1 = new Paragraph(); paragraph1.setSpacingBefore(-5); paragraph1.setSpacingAfter(10); paragraph1.setFont(new Font(fHelvetica, 7)); paragraph1.add(txtCoordenador); paragraph1.setAlignment(Element.ALIGN_RIGHT); document.add(paragraph1); //---------------------------------------------------------------------- //ADICIONAR TITULO //---------------------------------------------------------------------- PdfContentByte t1 = writer.getDirectContentUnder(); t1.beginText(); t1.setFontAndSize(fHelveticaBOLD, 12); t1.setTextMatrix(175, 700); // x e y t1.showText("RELATRIO ANUAL DE ATIVIDADES - " + ano); t1.endText(); PdfContentByte t2 = writer.getDirectContentUnder(); t2.beginText(); t2.setFontAndSize(fHelveticaBOLD, 12); t2.setTextMatrix(160, 680); // x e y if (cursoNome.contains("sistema") || cursoNome.contains("Sistemas") || cursoNome.contains("Sistema")) { t2.showText("BACHARELADO EM SISTEMAS DE INFORMAO"); cursoNome = "Sistemas de Informao"; } else if (cursoNome.contains("cincia") || cursoNome.contains("Cincias") || cursoNome.contains("Cincia")) { t2.showText("BACHARELADO EM CINCIA DA COMPUTAO"); cursoNome = "Cincia da Computao"; } else { t2.showText("BACHARELADO EM " + cursoNome.toUpperCase()); } t2.endText(); Paragraph p0 = new Paragraph("1. Introduo"); p0.setSpacingBefore(95); p0.getFont().setStyle(Font.BOLD); p0.getFont().setSize(12); document.add(p0); //---------------------------------------------------------------------- String textoIntro = "Este documento tem o objetivo de apresentar as atividades da coordenao de estgio " + "supervisionado da Faculdade de Computao da Universidade Federal de Uberlndia. As principais " + "atividades desenvolvidas foram:"; Chunk chunk1 = new Chunk(textoIntro); Paragraph paragraph = new Paragraph(); paragraph.setSpacingBefore(20); paragraph.setSpacingAfter(10); paragraph.setFont(new Font(fHelvetica, 12)); paragraph.add(chunk1); paragraph.setAlignment(Element.ALIGN_JUSTIFIED); document.add(paragraph); //lista List overview = new List(false, 10); overview.setAutoindent(true); overview.add("Aprovao dos documentos de matricula do estgio supervisionado;"); overview.add("Alocao de professores orientadores de estgio;"); overview.add( "Matrcula de alunos do curso de " + cursoNome + " na disciplina de estgio supervisionado;"); overview.add("Acompanhamento das atividades do estagirio na empresa;"); overview.add("Aprovao do Relatrio parcial/final do estagirio."); document.add(overview); String textoIntro2 = "Os resultados das atividades listadas so apresentados nas prximas sees."; Chunk chunk2 = new Chunk(textoIntro2); Paragraph paragraph2 = new Paragraph(); paragraph2.setSpacingBefore(10); paragraph2.setSpacingAfter(10); paragraph2.setFont(new Font(fHelvetica, 12)); paragraph2.add(chunk2); paragraph2.setAlignment(Element.ALIGN_JUSTIFIED); document.add(paragraph2); Paragraph p01 = new Paragraph("2. Sumrio das Atividades"); p01.setSpacingBefore(5); p01.getFont().setStyle(Font.BOLD); p01.getFont().setSize(12); document.add(p01); //---------------------------------------------------------------------- //FAZER SUMARIO //---------------------------------------------------------------------- PdfPTable tabelaSumario = new PdfPTable(4); tabelaSumario.setTotalWidth(100f); tabelaSumario.setWidthPercentage(100); float[] widths = { 40, 20, 20, 20 };//largura das colunas tabelaSumario.setWidths(widths); tabelaSumario.setHeaderRows(1); Paragraph l1 = new Paragraph(" "); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); PdfPCell cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.WHITE); cell1.setBorderColor(BaseColor.WHITE); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaSumario.addCell(cell1); l1 = new Paragraph("Matrculas"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); PdfPCell cell2 = new PdfPCell(l1); // celula cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); cell2.setBorderColor(BaseColor.LIGHT_GRAY); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaSumario.addCell(cell2); l1 = new Paragraph("Aprovaes"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); PdfPCell cell3 = new PdfPCell(l1); // celula cell3.setBackgroundColor(BaseColor.LIGHT_GRAY); cell3.setBorderColor(BaseColor.LIGHT_GRAY); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaSumario.addCell(cell3); l1 = new Paragraph("Reprovaes"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); PdfPCell cell4 = new PdfPCell(l1); // celula cell4.setBackgroundColor(BaseColor.LIGHT_GRAY); cell4.setBorderColor(BaseColor.LIGHT_GRAY); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaSumario.addCell(cell4); int i = 0; for (Sumariomatricula m : sm) { Sumarioaprovado a = sa.get(i); Paragraph texto = new Paragraph(m.getTipoestagio()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); if (m.getMatriculas() != null) { texto = new Paragraph(String.valueOf(m.getMatriculas())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } else { texto = new Paragraph(String.valueOf(0)); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } if (m.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio") && a.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio")) { if (a.getAprovados() != null) { //aprovados texto = new Paragraph(String.valueOf(a.getAprovados())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } else { texto = new Paragraph(String.valueOf(0)); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } //reprovados texto = new Paragraph(String.valueOf(0)); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } else if (m.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatrio") && a.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatrio")) { if (a.getAprovados() != null) { //aprovados texto = new Paragraph(String.valueOf(a.getAprovados())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } else { texto = new Paragraph(String.valueOf(0)); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } //reprovados texto = new Paragraph(String.valueOf(0)); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } i++; } tabelaSumario.setSpacingBefore(20); tabelaSumario.setSpacingAfter(20); tabelaSumario.completeRow(); document.add(tabelaSumario); //---------------------------------------------------------------------- //ALUNOS MATRICULADOS //---------------------------------------------------------------------- Paragraph p1 = new Paragraph("3. Alunos Matriculados"); p1.setSpacingBefore(5); p1.getFont().setStyle(Font.BOLD); p1.getFont().setSize(12); document.add(p1); p01 = new Paragraph("Estgio Obrigatrio"); p01.setSpacingBefore(5); p01.getFont().setStyle(Font.BOLD); p01.getFont().setSize(10); document.add(p01); //---------------------------------------------------------------------- //FAZER TABELA ALUNOS MATRICULADOS ESTAGIO OBRIGATORIO //---------------------------------------------------------------------- PdfPTable tabelaAlunoMatriculadoEO = new PdfPTable(4); tabelaAlunoMatriculadoEO.setTotalWidth(100f); tabelaAlunoMatriculadoEO.setWidthPercentage(100); float[] widthsEO = { 20, 30, 30, 20 };//largura das colunas tabelaAlunoMatriculadoEO.setWidths(widthsEO); tabelaAlunoMatriculadoEO.setHeaderRows(1); l1 = new Paragraph("Matrculas"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoEO.addCell(cell1); l1 = new Paragraph("Nome"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoEO.addCell(cell1); l1 = new Paragraph("Orientador"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoEO.addCell(cell1); l1 = new Paragraph("Data de Matrcula"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoEO.addCell(cell1); for (int j = 0; j < am.size(); j++) { Alunomatriculado amat = am.get(j); if (amat.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio") || amat.getTipoestagio().equalsIgnoreCase("Estgio Obrigatorio") || amat.getTipoestagio().equalsIgnoreCase("Estagio Obrigatorio")) { Paragraph texto = new Paragraph(amat.getMatricula()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoEO.addCell(cell1); texto = new Paragraph(amat.getNome()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoEO.addCell(cell1); texto = new Paragraph(amat.getOrientador()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoEO.addCell(cell1); texto = new Paragraph(CalendarFormat.getDataBRtoDate(amat.getDatamatricula())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoEO.addCell(cell1); } } tabelaAlunoMatriculadoEO.setSpacingBefore(20); tabelaAlunoMatriculadoEO.setSpacingAfter(20); tabelaAlunoMatriculadoEO.completeRow(); document.add(tabelaAlunoMatriculadoEO); //---------------------------------------------------------------------- //FAZER TABELA ALUNOS MATRICULADOS ESTAGIO NO OBRIGATORIO //---------------------------------------------------------------------- p01 = new Paragraph("Estgio No Obrigatrio"); p01.setSpacingBefore(5); p01.getFont().setStyle(Font.BOLD); p01.getFont().setSize(10); document.add(p01); PdfPTable tabelaAlunoMatriculadoENO = new PdfPTable(4); tabelaAlunoMatriculadoENO.setTotalWidth(100f); tabelaAlunoMatriculadoENO.setWidthPercentage(100); float[] widthsENO = { 20, 30, 30, 20 };//largura das colunas tabelaAlunoMatriculadoENO.setWidths(widthsENO); tabelaAlunoMatriculadoENO.setHeaderRows(1); l1 = new Paragraph("Matrculas"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoENO.addCell(cell1); l1 = new Paragraph("Nome"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoENO.addCell(cell1); l1 = new Paragraph("Orientador"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoENO.addCell(cell1); l1 = new Paragraph("Data de Matrcula"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoENO.addCell(cell1); for (int k = 0; k < am.size(); k++) { Alunomatriculado amat = am.get(k); if (amat.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatrio") || amat.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatorio") || amat.getTipoestagio().equalsIgnoreCase("Estagio No Obrigatorio")) { Paragraph texto = new Paragraph(amat.getMatricula()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoENO.addCell(cell1); texto = new Paragraph(amat.getNome()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoENO.addCell(cell1); texto = new Paragraph(amat.getOrientador()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoENO.addCell(cell1); texto = new Paragraph(CalendarFormat.getDataBRtoDate(amat.getDatamatricula())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoENO.addCell(cell1); } } tabelaAlunoMatriculadoENO.setSpacingBefore(20); tabelaAlunoMatriculadoENO.setSpacingAfter(20); tabelaAlunoMatriculadoENO.completeRow(); document.add(tabelaAlunoMatriculadoENO); //add nova pagina //document.newPage(); //---------------------------------------------------------------------- //ALUNOS APROVADOS EM ESTAGIO OBRIGATORIO //---------------------------------------------------------------------- p1 = new Paragraph("4. Alunos Aprovados em Estgio Obrigatrio"); p1.setSpacingBefore(20); p1.getFont().setStyle(Font.BOLD); p1.getFont().setSize(12); document.add(p1); PdfPTable tabelaAlunoAprovadoEO = new PdfPTable(5); tabelaAlunoAprovadoEO.setTotalWidth(100f); tabelaAlunoAprovadoEO.setWidthPercentage(100); float[] widthsAprovadoEO = { 20, 30, 30, 10, 10 };//largura das colunas tabelaAlunoAprovadoEO.setWidths(widthsAprovadoEO); tabelaAlunoAprovadoEO.setHeaderRows(1); l1 = new Paragraph("Matrculas"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoAprovadoEO.addCell(cell1); l1 = new Paragraph("Nome"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoAprovadoEO.addCell(cell1); l1 = new Paragraph("Orientador"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoAprovadoEO.addCell(cell1); l1 = new Paragraph("Data de Matrcula"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoAprovadoEO.addCell(cell1); l1 = new Paragraph("Data de Finalizao"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoAprovadoEO.addCell(cell1); for (int t = 0; t < aa.size(); t++) { Alunoaprovado aprov = aa.get(t); if (aprov.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio") || aprov.getTipoestagio().equalsIgnoreCase("Estgio Obrigatorio") || aprov.getTipoestagio().equalsIgnoreCase("Estagio Obrigatorio")) { Paragraph texto = new Paragraph(aprov.getMatricula()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoAprovadoEO.addCell(cell1); texto = new Paragraph(aprov.getNome()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoAprovadoEO.addCell(cell1); texto = new Paragraph(aprov.getOrientador()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoAprovadoEO.addCell(cell1); texto = new Paragraph(CalendarFormat.getDataBRtoDate(aprov.getDatamatricula())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoAprovadoEO.addCell(cell1); texto = new Paragraph(CalendarFormat.getDataBRtoDate(aprov.getDatafinalizacao())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoAprovadoEO.addCell(cell1); } } tabelaAlunoAprovadoEO.setSpacingBefore(20); tabelaAlunoAprovadoEO.setSpacingAfter(20); tabelaAlunoAprovadoEO.completeRow(); document.add(tabelaAlunoAprovadoEO); //---------------------------------------------------------------------- //ALUNOS APROVADOS EM ESTAGIO OBRIGATORIO //---------------------------------------------------------------------- p1 = new Paragraph("5. Participao dos professores FACOM"); p1.setSpacingBefore(20); p1.getFont().setStyle(Font.BOLD); p1.getFont().setSize(12); document.add(p1); // PdfPTable tabelaProfOriSeparada = new PdfPTable(3); tabelaProfOriSeparada.setTotalWidth(100f); tabelaProfOriSeparada.setWidthPercentage(100); float[] widths0 = { 60, 20, 20 };//largura das colunas tabelaProfOriSeparada.setWidths(widths0); tabelaProfOriSeparada.setHeaderRows(1); l1 = new Paragraph("Professor"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaProfOriSeparada.addCell(cell1); l1 = new Paragraph("Orientaes Estgio Obrigatrio"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaProfOriSeparada.addCell(cell1); l1 = new Paragraph("Orientaes Estgio No Obrigatrio"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaProfOriSeparada.addCell(cell1); for (int ii = 0; ii < proforiseparada.size(); ii++) { Professororientacaoseparada profoe = proforiseparada.get(ii); Paragraph texto = new Paragraph(profoe.getNome()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); texto.getFont().setSize(8); tabelaProfOriSeparada.addCell(cell1); texto = new Paragraph(profoe.getOrientacoesestobrigatorio().toString()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaProfOriSeparada.addCell(cell1); texto = new Paragraph(profoe.getOrientacoesestnaoobrigatorio().toString()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaProfOriSeparada.addCell(cell1); } tabelaProfOriSeparada.setSpacingBefore(20); tabelaProfOriSeparada.setSpacingAfter(20); tabelaProfOriSeparada.completeRow(); document.add(tabelaProfOriSeparada); //---------------------------------------------------------------------- p1 = new Paragraph("6. Observaes e Consideraes Finais"); p1.setSpacingBefore(20); p1.getFont().setStyle(Font.BOLD); p1.getFont().setSize(12); document.add(p1); String text6 = "O processo de matrcula, acompanhamento, composio de bancas e " + "defesas ocorreu sem nenhum problema ou acontecimento excepcional."; chunk1 = new Chunk(text6); paragraph = new Paragraph(); paragraph.setSpacingBefore(20); paragraph.setSpacingAfter(10); paragraph.setFont(new Font(fHelvetica, 12)); paragraph.add(chunk1); paragraph.setAlignment(Element.ALIGN_JUSTIFIED); document.add(paragraph); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); //----------------------------------------------------- Paragraph paragraphCab = new Paragraph(); paragraphCab.setSpacingBefore(25); paragraphCab.add("Uberlndia, " + CalendarFormat.getDataPorExtenso(CalendarFormat.getDataSO()) + "."); paragraphCab.setAlignment(Element.ALIGN_JUSTIFIED); document.add(paragraphCab); document.add(Chunk.NEWLINE); //----------------------------------------------------- // distancia do fim da pagina float y = 120f; float x = 160f; //----------------------------------------------------- //linha PdfContentByte linha = writer.getDirectContentUnder(); linha.setLineWidth(1f); // mostrar linha linha.setGrayStroke(0.5f); // 0 = preto, 1 = branco linha.moveTo(x, y); linha.lineTo(450f, y); // ate onde a linha vai linha.stroke(); //assinatura PdfContentByte a0 = writer.getDirectContentUnder(); a0.beginText(); a0.setFontAndSize(fHelvetica, 10); a0.setTextMatrix(x + 50, y - 15); // x e y a0.showText("Prof. " + coordenador.getNome()); a0.endText(); PdfContentByte a1 = writer.getDirectContentUnder(); a1.beginText(); a1.setFontAndSize(fHelvetica, 10); a1.setTextMatrix(x + 50, y - 30); // x e y a1.showText("Coordenao de Estgio Supervisionado"); a1.endText(); //assinatura PdfContentByte a2 = writer.getDirectContentUnder(); a2.beginText(); a2.setFontAndSize(fHelvetica, 10); a2.setTextMatrix(x + 50, y - 45); // x e y a2.showText("SIAPE: " + coordenador.getSiape()); a2.endText(); //---------------------------------------------------------------------- //FIM DO DOCUMENTO //add nova pagina document.newPage(); //close document document.close(); //---------------------------------------------------------------------- } catch (DocumentException | IOException ex) { Logger.getLogger(RelatorioAluno.class.getName()).log(Level.SEVERE, null, ex); } //return stream return baos; }
From source file:reporteFertilizacion.ReporteResultadoLaboratorio.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . j a va 2s . co 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:reportes.ServletIntegral.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); ServletConfig config = getServletConfig(); ServletContext context = config.getServletContext(); String path = context.getContextPath(); String realPath = context.getRealPath("/"); response.setContentType("application/pdf"); //Para descargar el PDF response.setHeader("Content-Disposition", "attachment; filename=\"ResultadoIntegral.pdf\""); // step 1: creation of a document-object try {// w w w.j a v a2 s .co m Document document = new Document(PageSize.LETTER); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a temporary buffer ByteArrayOutputStream buffer = new ByteArrayOutputStream(); PdfWriter.getInstance(document, buffer); // step 3: we open the document document.open(); // step 4: we add content to the document Paragraph title = new Paragraph( (session.getAttribute("nEmpresa") != null) ? session.getAttribute("nEmpresa").toString() : "Empresa"); title.setAlignment(Element.ALIGN_CENTER); title.setFont(NORMAL); document.add(title); title = new Paragraph("Estado de resultado integral del 01 de Enero al 31 de Diciembre del " + (new Date().getYear() + 1900)); title.setAlignment(Element.ALIGN_CENTER); title.setFont(NORMAL); document.add(title); title = new Paragraph("Cifras en miles de pesos"); title.setAlignment(Element.ALIGN_CENTER); title.setFont(NORMAL); document.add(title); for (int i = 0; i < 2; i++) { document.add(new Paragraph(" ")); } PdfPTable table = new PdfPTable(2); //Obtenemos los datos de la clase ResultadoIntegral ResultadoIntegral r = new ResultadoIntegral(); r.calculaResultado(Integer.parseInt(session.getAttribute("Empresa").toString())); for (int i = 0; i < r.getSaldos().size(); i++) { PdfPCell dato = new PdfPCell(); if (i == 2 || i == 7 || i == 12 || i == 14 || i == 16 || i == 18 || i == 19 || i == 17) { Chunk ch = new Chunk(descripciones[i]); ch.setFont(BOLD_Tot); Phrase ph = new Phrase(ch); dato.setPhrase(ph); } else { Phrase ph = new Phrase(descripciones[i]); dato.setPhrase(ph); } dato.setBorder(Rectangle.NO_BORDER); dato.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(dato); if (r.getValores().size() > 0) { Chunk ch = new Chunk(); if (r.getSaldos().get(i) < 0) { String valor = "(" + (r.getSaldos().get(i) * (-1)) + ")"; ch.append(valor); ch.setFont(NORMAL_Negative); } else { dato.setPhrase(new Phrase("" + r.getSaldos().get(i))); } } else { dato.setPhrase(new Phrase("0.0")); } if (i == 1 || i == 6 || i == 11 || i == 13 || i == 15 || i == 17 || i == 18) { dato.setBorder(Rectangle.BOTTOM); } else { dato.setBorder(Rectangle.NO_BORDER); } dato.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(dato); } document.add(table); document.add(new Paragraph("")); // step 5: we close the document document.close(); // step 6: we output the writer as bytes to the response output DataOutputStream output = new DataOutputStream(response.getOutputStream()); byte[] bytes = buffer.toByteArray(); response.setContentLength(bytes.length); for (int i = 0; i < bytes.length; i++) { output.writeByte(bytes[i]); } output.close(); response.getOutputStream(); //session.removeAttribute("bean"); //session.removeAttribute("producto"); } catch (Exception ex) { ex.printStackTrace(); } }