List of usage examples for com.itextpdf.text.pdf PdfPTable setWidthPercentage
public void setWidthPercentage(final float widthPercentage)
From source file:rs.marko.helper.Kreiranje.java
public static File createPdfStatistika(List<Stavkadnevneberbe> stavke, Date pocetak, Date kraj) { Document document = new Document(); File yourFile = null;/* w ww . j a v a2 s . c om*/ try { yourFile = new File(System.getProperty("user.home") + "/Desktop/" + pocetak + "_" + kraj + ".pdf"); if (!yourFile.exists()) { yourFile.createNewFile(); } FileOutputStream oFile = new FileOutputStream(yourFile, false); document.setPageSize(PageSize.A4.rotate()); PdfWriter.getInstance(document, oFile); document.open(); // String text = ""; // for (int i = 0; i < 10000; i++) { // text += "test"; // , } // String jmbg = stavke.get(0).getDobavljac().getJmbg(); PdfPTable table = new PdfPTable( new float[] { 300f, 150f, 150f, 150f, 150f, 150f, 150f, 150f, 150f, 150f, 150f, 150f, 150f }); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.setSpacingAfter(0f); Paragraph p = new Paragraph("Od: " + pocetak + " do: " + kraj); p.add(new Paragraph(" ")); document.add(p); PdfPCell c = new PdfPCell(new Phrase("")); // PdfPCell c1 = new PdfPCell(new Phrase("Sifra")); // c1.setHorizontalAlignment(Element.ALIGN_CENTER); // c1.setRowspan(2); // c1.setColspan(2); // table.addCell(c1); PdfPCell c1 = new PdfPCell(new Phrase("Dobavljac")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setVerticalAlignment(Element.ALIGN_MIDDLE); c1.setRowspan(2); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("Tacne")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("I Klasa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("II Klasa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("III Klasa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase("Svega")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(3); table.addCell(c1); c1 = new PdfPCell(new Phrase("Kol")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Iznos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Kol")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Iznos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Kol")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Iznos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Kol")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Iznos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Kol")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cena")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Iznos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); Font font = new Font(BaseFont.createFont(), 10, Font.NORMAL); // table.setHeaderRows(3); List<String> jmbgovi = new ArrayList<>(); Map<Double, Double> kt = new HashMap<>(); Map<Double, Double> k1 = new HashMap<>(); Map<Double, Double> k2 = new HashMap<>(); Map<Double, Double> k3 = new HashMap<>(); Map<Double, Double> ukupnoTacneVrednost = new HashMap<>(); Map<Double, Double> ukupnoPrvaKlasaVrednost = new HashMap<>(); Map<Double, Double> ukupnoDrugaKlasaVrednost = new HashMap<>(); Map<Double, Double> ukupnoTrecaKlasaVrednost = new HashMap<>(); for (Stavkadnevneberbe stavkaDnevneBerbe : stavke) { if (!jmbgovi.contains(stavkaDnevneBerbe.getDnevnaberba().getDobavljac().getJmbg())) { jmbgovi.add(stavkaDnevneBerbe.getDnevnaberba().getDobavljac().getJmbg()); } } Double ukupnoKolicinaTacne = 0.0; Double ukupnoKolicinaPrvaKlasa = 0.0; Double ukupnoKolicinaDrugaKlasa = 0.0; Double ukupnoKolicinaTrecaKlasa = 0.0; Double ukupnoCenaTacne = 0.0; Double ukupnoCenaPrvaKlasa = 0.0; Double ukupnoCenaDrugaKlasa = 0.0; Double ukupnoCenaTrecaKlasa = 0.0; Double ukupanIznosSvih = 0.0; for (String j : jmbgovi) { String imeDobavljaca = null; for (Stavkadnevneberbe stavkaDnevneBerbe : stavke) { if (stavkaDnevneBerbe.getDnevnaberba().getDobavljac().getJmbg().equals(j)) { if (imeDobavljaca == null) { imeDobavljaca = stavkaDnevneBerbe.getDnevnaberba().getDobavljac().getIme() + " " + stavkaDnevneBerbe.getDnevnaberba().getDobavljac().getPrezime(); } if (!kt.containsKey(stavkaDnevneBerbe.getCenatacne()) && stavkaDnevneBerbe.getTacne() != 0) { kt.put(stavkaDnevneBerbe.getCenatacne(), new Double(0)); } if (!k1.containsKey(stavkaDnevneBerbe.getCenaprvaklasa()) && stavkaDnevneBerbe.getCenaprvaklasa() != 0) { k1.put(stavkaDnevneBerbe.getCenaprvaklasa(), new Double(0)); } if (!k2.containsKey(stavkaDnevneBerbe.getCenadrugaklasa()) && stavkaDnevneBerbe.getCenadrugaklasa() != 0) { k2.put(stavkaDnevneBerbe.getCenadrugaklasa(), new Double(0)); } if (!k3.containsKey(stavkaDnevneBerbe.getCenatrecaklasa()) && stavkaDnevneBerbe.getCenatrecaklasa() != 0) { k3.put(stavkaDnevneBerbe.getCenatrecaklasa(), new Double(0)); } } } for (Stavkadnevneberbe s : stavke) { if (s.getDnevnaberba().getDobavljac().getJmbg().equals(j)) { if (kt.containsKey(s.getCenatacne())) { kt.put(s.getCenatacne(), kt.get(s.getCenatacne()) + s.getTacne()); } if (k1.containsKey(s.getCenaprvaklasa())) { k1.put(s.getCenaprvaklasa(), k1.get(s.getCenaprvaklasa()) + s.getPrvaklasa()); } if (k2.containsKey(s.getCenadrugaklasa())) { k2.put(s.getCenadrugaklasa(), k2.get(s.getCenadrugaklasa()) + s.getDrugaklasa()); } if (k3.containsKey(s.getCenatrecaklasa())) { k3.put(s.getCenatrecaklasa(), k3.get(s.getCenatrecaklasa()) + s.getTrecaklasa()); } } } c1 = new PdfPCell(new Phrase(imeDobavljaca)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); Iterator it = kt.entrySet().iterator(); Double ukupnoKolicinaT = 0.0; Double ukupnoCenaT = 0.0; Double ukupanIznos = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoKolicinaT += (Double) pair.getValue(); ukupnoCenaT += (Double) pair.getKey(); ukupanIznos += ((Double) pair.getValue() * (Double) pair.getKey()); //ukupno vrednost if (ukupnoTacneVrednost.containsKey((Double) pair.getKey())) { ukupnoTacneVrednost.put((Double) pair.getKey(), ukupnoTacneVrednost.get((Double) pair.getKey()) + ((Double) pair.getKey() * (Double) pair.getValue())); } else { ukupnoTacneVrednost.put((Double) pair.getKey(), (Double) pair.getKey() * (Double) pair.getValue()); } } c1 = new PdfPCell(new Phrase(round(ukupnoKolicinaT, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupanIznos, 2) + "", font)); table.addCell(c1); it = k1.entrySet().iterator(); Double ukupnoKolicinaP = 0.0; Double ukupnoCenaP = 0.0; Double ukupanIznosP = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoKolicinaP += (Double) pair.getValue(); ukupnoCenaP += (Double) pair.getKey(); ukupanIznosP += ((Double) pair.getValue() * (Double) pair.getKey()); if (ukupnoPrvaKlasaVrednost.containsKey((Double) pair.getKey())) { ukupnoPrvaKlasaVrednost.put((Double) pair.getKey(), ukupnoPrvaKlasaVrednost.get((Double) pair.getKey()) + ((Double) pair.getKey() * (Double) pair.getValue())); } else { ukupnoPrvaKlasaVrednost.put((Double) pair.getKey(), (Double) pair.getKey() * (Double) pair.getValue()); } } c1 = new PdfPCell(new Phrase(round(ukupnoKolicinaP, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupanIznosP, 2) + "", font)); table.addCell(c1); it = k2.entrySet().iterator(); Double ukupnoKolicinaD = 0.0; Double ukupnoCenaD = 0.0; Double ukupanIznosD = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoKolicinaD += (Double) pair.getValue(); ukupnoCenaD += (Double) pair.getKey(); ukupanIznosD += ((Double) pair.getValue() * (Double) pair.getKey()); if (ukupnoDrugaKlasaVrednost.containsKey((Double) pair.getKey())) { ukupnoDrugaKlasaVrednost.put((Double) pair.getKey(), ukupnoDrugaKlasaVrednost.get((Double) pair.getKey()) + ((Double) pair.getKey() * (Double) pair.getValue())); } else { ukupnoDrugaKlasaVrednost.put((Double) pair.getKey(), (Double) pair.getKey() * (Double) pair.getValue()); } } c1 = new PdfPCell(new Phrase(round(ukupnoKolicinaD, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupanIznosD, 2) + "", font)); table.addCell(c1); it = k3.entrySet().iterator(); Double ukupnoKolicinaTr = 0.0; Double ukupnoCenaTr = 0.0; Double ukupanIznosT = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoKolicinaTr += (Double) pair.getValue(); ukupnoCenaTr += (Double) pair.getKey(); ukupanIznosT += ((Double) pair.getValue() * (Double) pair.getKey()); if (ukupnoTrecaKlasaVrednost.containsKey((Double) pair.getKey())) { ukupnoTrecaKlasaVrednost.put((Double) pair.getKey(), ukupnoTrecaKlasaVrednost.get((Double) pair.getKey()) + ((Double) pair.getKey() * (Double) pair.getValue())); } else { ukupnoTrecaKlasaVrednost.put((Double) pair.getKey(), (Double) pair.getKey() * (Double) pair.getValue()); } } c1 = new PdfPCell(new Phrase(round(ukupnoKolicinaTr, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupanIznosT, 2) + "", font)); table.addCell(c1); Double ukupnoKolicina = ukupnoKolicinaT + ukupnoKolicinaP + ukupnoKolicinaD + ukupnoKolicinaTr; Double ukupnoVrednost = ukupanIznos + ukupanIznosP + ukupanIznosD + ukupanIznosT; Double ukupnoCena = ukupnoVrednost / ukupnoKolicina; c1 = new PdfPCell(new Phrase(round(ukupnoKolicina, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupnoCena, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupnoVrednost, 2) + "", font)); table.addCell(c1); ukupanIznosSvih += ukupnoVrednost; ukupnoKolicinaTacne += ukupnoKolicinaT; ukupnoKolicinaPrvaKlasa += ukupnoKolicinaP; ukupnoKolicinaDrugaKlasa += ukupnoKolicinaD; ukupnoKolicinaTrecaKlasa += ukupnoKolicinaTr; ukupnoCenaTacne += ukupanIznos; ukupnoCenaPrvaKlasa += ukupanIznosP; ukupnoCenaDrugaKlasa += ukupanIznosD; ukupnoCenaTrecaKlasa += ukupanIznosT; kt.clear(); k1.clear(); k2.clear(); k3.clear(); } c1 = new PdfPCell(new Phrase("UKUPNO")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoKolicinaTacne + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoCenaTacne + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoKolicinaPrvaKlasa + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoCenaPrvaKlasa + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoKolicinaDrugaKlasa + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoCenaDrugaKlasa + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoKolicinaTrecaKlasa + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(ukupnoCenaTrecaKlasa + "", font)); table.addCell(c1); Double ukupnoKolicinaSve = ukupnoKolicinaTacne + ukupnoKolicinaPrvaKlasa + ukupnoKolicinaDrugaKlasa + ukupnoKolicinaTrecaKlasa; Double prosecnaCena = ukupanIznosSvih / ukupnoKolicinaSve; c1 = new PdfPCell(new Phrase(round(ukupnoKolicinaSve, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(prosecnaCena, 2) + "", font)); table.addCell(c1); c1 = new PdfPCell(new Phrase(round(ukupanIznosSvih, 2) + "", font)); table.addCell(c1); //PDV c1 = new PdfPCell(new Phrase("PDV")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); table.addCell(c); Iterator it = ukupnoTacneVrednost.entrySet().iterator(); Double ukupnoTacnePdv = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); if ((Double) pair.getKey() == 110) { ukupnoTacnePdv += (((Double) pair.getValue() / (Double) pair.getKey()) * 106); } else { ukupnoTacnePdv += (Double) pair.getValue(); } } c1 = new PdfPCell(new Phrase(round(ukupnoTacnePdv * (110.0f / 100.0f), 2) + "", font)); table.addCell(c1); table.addCell(c); it = ukupnoPrvaKlasaVrednost.entrySet().iterator(); Double ukupnoPrvaKlasaPdv = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoPrvaKlasaPdv += (Double) pair.getValue(); } c1 = new PdfPCell(new Phrase(round(ukupnoPrvaKlasaPdv * (110.0f / 100.0f), 2) + "", font)); table.addCell(c1); table.addCell(c); it = ukupnoDrugaKlasaVrednost.entrySet().iterator(); Double ukupnoDrugaKlasaPdv = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoDrugaKlasaPdv += (Double) pair.getValue(); } c1 = new PdfPCell(new Phrase(round(ukupnoDrugaKlasaPdv * (110.0f / 100.0f), 2) + "", font)); table.addCell(c1); table.addCell(c); it = ukupnoTrecaKlasaVrednost.entrySet().iterator(); Double ukupnoTrecaKlasaPdv = 0.0; while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); ukupnoTrecaKlasaPdv += (Double) pair.getValue(); } c1 = new PdfPCell(new Phrase(round(ukupnoTrecaKlasaPdv * (110.0f / 100.0f), 2) + "", font)); table.addCell(c1); c = new PdfPCell(new Phrase("")); c.setColspan(2); table.addCell(c); Double ukupnoSvePDV = ukupnoTacnePdv + ukupnoPrvaKlasaPdv + ukupnoDrugaKlasaPdv + ukupnoTrecaKlasaPdv; c1 = new PdfPCell(new Phrase(round(ukupnoSvePDV * (110.0f / 100.0f), 2) + "", font)); table.addCell(c1); c = new PdfPCell(new Phrase("")); c.setColspan(10); table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); // table.addCell(c); c1 = new PdfPCell(new Phrase("DOBITAK")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setColspan(2); table.addCell(c1); c1 = new PdfPCell( new Phrase(round((ukupnoSvePDV * (110.0f / 100.0f)) - ukupanIznosSvih, 2) + "", font)); table.addCell(c1); document.add(table); document.add(new Paragraph(" ")); } catch (DocumentException ex) { Logger.getLogger(Kreiranje.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(Kreiranje.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Kreiranje.class.getName()).log(Level.SEVERE, null, ex); } document.close(); return yourFile; }
From source file:ru.trett.cis.services.PDFBuilderImpl.java
License:Open Source License
@Override public String createPDF() throws IOException, DocumentException, ApplicationException { try {/*from ww w .j av a2s.c om*/ String templatePath = servletContext.getRealPath("WEB-INF/resources/template-settings.xml"); Map<String, List<String>> data = TemplateParser.parse(new File(templatePath)); String regularFontPath = servletContext.getRealPath("WEB-INF/resources/fonts/OpenSans-Regular.ttf"); if (regularFontPath == null) throw new ApplicationException("Regular Font file was not found"); BaseFont bfr = BaseFont.createFont(regularFontPath, BaseFont.IDENTITY_H, true); String boldFontPath = servletContext.getRealPath("WEB-INF/resources/fonts/OpenSans-Bold.ttf"); if (boldFontPath == null) throw new ApplicationException("Bold Font file was not found"); BaseFont bfb = BaseFont.createFont(boldFontPath, BaseFont.IDENTITY_H, true); regularFont = new Font(bfr); regularFont.setSize(10); boldFont = new Font(bfb); boldFont.setSize(10); File file = File.createTempFile("order", ".pdf"); Document doc = new Document(PageSize.A4); Chunk glue = new Chunk(new VerticalPositionMark()); PdfWriter.getInstance(doc, new FileOutputStream(file)); doc.open(); doc.newPage(); //title Paragraph p = new Paragraph(data.get("header").get(0), boldFont); p.setAlignment(Element.ALIGN_CENTER); doc.add(p); doc.add(Chunk.NEWLINE); //body for (String text : data.get("text")) { p = new Paragraph(text, regularFont); doc.add(p); } //table doc.add(Chunk.NEWLINE); List<String> cols = data.get("cols"); PdfPTable table = new PdfPTable(cols.size()); table.setWidthPercentage(100); cols.forEach(x -> table.addCell(getCell(x, PdfPCell.ALIGN_CENTER, boldFont))); for (Asset asset : assets) { table.addCell(getCell(String.format("%s %s %s", asset.getDeviceModel().getDeviceType().getType(), asset.getDeviceModel().getDeviceBrand().getBrand(), asset.getDeviceModel().getModel()), PdfPCell.ALIGN_CENTER, regularFont)); table.addCell(getCell(asset.getSerialNumber(), PdfPCell.ALIGN_CENTER, regularFont)); table.addCell(getCell(asset.getInventoryNumber(), PdfPCell.ALIGN_CENTER, regularFont)); } table.getRows(); doc.add(table); doc.add(Chunk.NEWLINE); doc.add(Chunk.NEWLINE); //signers Phrase phrase = new Phrase(new Chunk(data.get("signers").get(0) + " ", regularFont)); phrase.add(Chunk.NEWLINE); phrase.add(new Chunk(issuer.getFirstName() + " " + issuer.getLastName() + " \\__________________", regularFont)); phrase.add(Chunk.NEWLINE); phrase.add(Chunk.NEWLINE); phrase.add(new Chunk(data.get("signers").get(1) + " ", regularFont)); phrase.add(Chunk.NEWLINE); phrase.add(new Chunk(employee.getFirstName() + " " + employee.getLastName() + " \\__________________", regularFont)); doc.add(phrase); //date doc.add(Chunk.NEWLINE); doc.add(Chunk.NEWLINE); p = new Paragraph(data.get("place").get(0), regularFont); p.add(new Chunk(glue)); p.add(date.format(dateFormat)); doc.add(p); doc.close(); return file.getPath(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:sandbox.columntext.DropTablePart.java
public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open();//from ww w . j av a 2s.c om Rectangle column = new Rectangle(36, 36, 559, 806); ColumnText ct = new ColumnText(writer.getDirectContent()); ct.setSimpleColumn(column); for (int i = 0; i < 4;) { PdfPTable table = new PdfPTable(new float[] { 0.25f, 0.25f, 0.25f, 0.25f }); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100); PdfPCell cell = new PdfPCell(new Phrase("inner table " + (++i))); cell.setColspan(4); table.addCell(cell); for (int j = 0; j < 18; j++) { table.addCell(new Phrase("test Data " + (j + 1) + ".1")); table.addCell(new Phrase("test Data " + (j + 1) + ".1")); table.addCell(new Phrase("test Data " + (j + 1) + ".1")); table.addCell(new Phrase("test Data " + (j + 1) + ".1")); } ct.addElement(table); if (ColumnText.hasMoreText(ct.go())) { document.newPage(); ct = new ColumnText(writer.getDirectContent()); ct.setSimpleColumn(column); } } document.close(); }
From source file:se.inera.intyg.rehabstod.service.export.pdf.PdfExportServiceImpl.java
License:Open Source License
private PdfPTable createSjukfallTable(List<SjukfallEnhet> sjukfallList, Urval urval, boolean showPatientId, boolean showSrsRisk) throws DocumentException { // Setup column widths (relative to each other) PdfPTable table = createTableColumns(urval, showPatientId, showSrsRisk); table.setWidthPercentage(100.0f); table.getDefaultCell().setBackgroundColor(TABLE_HEADER_BASE_COLOR); table.getDefaultCell().setBorderColor(TABLE_HEADER_BASE_COLOR); table.getDefaultCell().setNoWrap(true); table.getDefaultCell().setPadding(3f); table.getDefaultCell().setPaddingLeft(2f); addCell(table, TABLEHEADER_NR, PdfExportConstants.TABLE_HEADER_FONT); if (showPatientId) { addCell(table, TABLEHEADER_PERSONNUMMER, PdfExportConstants.TABLE_HEADER_FONT); }//from www .j av a2s . co m addCell(table, TABLEHEADER_ALDER, PdfExportConstants.TABLE_HEADER_FONT); if (showPatientId) { addCell(table, TABLEHEADER_NAMN, PdfExportConstants.TABLE_HEADER_FONT); } addCell(table, TABLEHEADER_KON, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_NUVARANDE_DIAGNOS, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_STARTDATUM, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_SLUTDATUM, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_SJUKSKRIVNINGSLANGD, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_ANTAL, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_SJUKSKRIVNINGSGRAD, PdfExportConstants.TABLE_HEADER_FONT); if (Urval.ALL.equals(urval)) { addCell(table, TABLEHEADER_NUVARANDE_LAKARE, PdfExportConstants.TABLE_HEADER_FONT); } if (showSrsRisk) { addCell(table, TABLEHEADER_SRS_RISK, PdfExportConstants.TABLE_HEADER_FONT); } // Set cell styles for the non-header cells following hereafter table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY); table.getDefaultCell().setNoWrap(false); table.getDefaultCell().setPadding(2f); table.setHeaderRows(1); int rowNumber = 1; for (SjukfallEnhet is : sjukfallList) { if (rowNumber % 2 == 0) { table.getDefaultCell().setBackgroundColor(TABLE_EVEN_ROW_COLOR); } else { table.getDefaultCell().setBackgroundColor(TABLE_ODD_ROW_COLOR); } addCell(table, String.valueOf(rowNumber)); if (showPatientId) { addCell(table, getPersonnummerColumn(is)); } addCell(table, is.getPatient().getAlder()); if (showPatientId) { addCell(table, is.getPatient().getNamn()); } addCell(table, is.getPatient().getKon().getDescription()); addCell(table, getCompoundDiagnoseText(is, showPatientId)); addCell(table, is.getStart() != null ? YearMonthDateFormatter.print(is.getStart()) : "?"); addCell(table, is.getSlut() != null ? YearMonthDateFormatter.print(is.getSlut()) : "?"); addCell(table, getlangdText(is)); addCell(table, is.getIntyg()); addCell(table, getGrader(is)); if (Urval.ALL.equals(urval)) { addCell(table, is.getLakare().getNamn()); } if (showSrsRisk) { addCell(table, getRiskKategoriDesc(is.getRiskSignal())); } rowNumber++; } return table; }
From source file:server.kartu.tik.iText.java
public String createPDF(String tanggal, ArrayList kegiatan, String divisi) { ArrayList<Kegiatan> list = new ArrayList<>(kegiatan); String output = System.getProperty("user.dir") + "\\src\\data\\pdf\\" + tanggal + " " + getNamalengkap() + "-" + getTglnoktp() + ".pdf"; String namaDivisi = ""; switch (divisi) { case "1": namaDivisi = "Ekonomi"; break;/*from w w w . ja v a2 s . c o m*/ case "2": namaDivisi = "Politik"; break; case "3": namaDivisi = "Sosial Budaya"; break; case "4": namaDivisi = "Keamanan"; break; } Document document = new Document(PageSize.A4); try { PdfWriter.getInstance(document, new FileOutputStream(output)); document.open(); //------------------------------------------------------------------------------------- TITLE PdfPTable title = new PdfPTable(1); title.setWidthPercentage(100); Font f = new Font(FontFamily.HELVETICA, 14, Font.NORMAL, GrayColor.GRAYWHITE); PdfPCell celltitle = new PdfPCell(new Phrase("KARTU TIK (" + namaDivisi + ")", f)); celltitle.setMinimumHeight(20); celltitle.setBackgroundColor(GrayColor.GRAYBLACK); celltitle.setHorizontalAlignment(Element.ALIGN_CENTER); celltitle.setColspan(3); title.addCell(celltitle); document.add(title); //-------------------------------------------------------------------------------------- END //------------------------------------------------------------------------------------- NAMA + ALIAS float[] columnWidths = { 8, 2 }; PdfPTable tabel1 = new PdfPTable(columnWidths); tabel1.setWidthPercentage(100); PdfPTable innerTable1 = new PdfPTable(1); innerTable1.setWidthPercentage(100); PdfPTable innerTable2 = new PdfPTable(1); innerTable2.setWidthPercentage(100); PdfPCell cell; innerTable1.addCell( "1. a. Nama Lengkap : " + getNamalengkap() + " \n\n b. Alias : " + getAlias() + " \n\n"); innerTable1.addCell("2. Kebangsaan \n a. Tgl. No. KTP : " + getTglnoktp() + " \n\n b. Tgl. No. Pasport : " + getTglnopasport() + "\n\n"); innerTable1.addCell("3. Agama : " + getAgama()); cell = new PdfPCell(innerTable1); cell.setMinimumHeight(135); tabel1.addCell(cell); if (getUrlfoto().equalsIgnoreCase("") || getUrlfoto().isEmpty() || getUrlfoto() == null) { } else { Image image = Image.getInstance(getUrlfoto()); cell = new PdfPCell(image, false); if (image.getWidth() < 90) { cell.setPaddingLeft(8); } else { cell.setPaddingLeft(3); } } cell.setMinimumHeight(135); tabel1.addCell(cell); cell = new PdfPCell(); cell.setColspan(14); tabel1.addCell(cell); document.add(tabel1); //------------------------------------------------------------------------------------- NAMA + ALIAS END //------------------------------------------------------------------------------------- TGL LAHIR + TEMPAT PdfPTable tabel4 = new PdfPTable(1); tabel4.setWidthPercentage(100); Paragraph pTglLahirnTempat = new Paragraph(); pTglLahirnTempat.add("4. a. Tgl. Lahir/ Umur : " + getTgllahir()); pTglLahirnTempat.add("\n\n b. Tempat Lahir : " + getTempatlahir()); pTglLahirnTempat.setLeading(0, 1); PdfPCell cTglLahirnTempat = new PdfPCell(); cTglLahirnTempat.setMinimumHeight(45); cTglLahirnTempat.addElement(pTglLahirnTempat); tabel4.addCell(cTglLahirnTempat); document.add(tabel4); //------------------------------------------------------------------------------------- TGL LAHIR + TEMPAT END //------------------------------------------------------------------------------------- ALAMAT + PINDAHAN PdfPTable tabel5 = new PdfPTable(1); tabel5.setWidthPercentage(100); Paragraph pAlamat = new Paragraph(); pAlamat.add("5. Alamat : "); pAlamat.add(alamat); pAlamat.setLeading(0, 1); PdfPCell cAlamat = new PdfPCell(); cAlamat.setMinimumHeight(18); cAlamat.addElement(pAlamat); tabel5.addCell(cAlamat); document.add(tabel5); PdfPTable tabel51 = new PdfPTable(1); tabel51.setWidthPercentage(100); Paragraph pAlamatUbah = new Paragraph(); pAlamatUbah.add("6. Perubahan Alamat :"); pAlamatUbah.add("\n\n 1. "); pAlamatUbah.add("\n\n 2. "); pAlamatUbah.add("\n\n 3. "); pAlamatUbah.add("\n\n"); pAlamatUbah.setLeading(0, 1); PdfPCell cAlamatUbah = new PdfPCell(); cAlamatUbah.addElement(pAlamatUbah); tabel51.addCell(cAlamatUbah); document.add(tabel51); //------------------------------------------------------------------------------------- ALAMAT + PINDAHAN END //------------------------------------------------------------------------------------- KEDUDUKAN KELUARGA PdfPTable tabel6 = new PdfPTable(1); tabel6.setWidthPercentage(100); Paragraph pKedudukanKeluarga = new Paragraph(); pKedudukanKeluarga.add("7. Kedudukan dalam Keluarga : "); pKedudukanKeluarga.setLeading(0, 1); PdfPCell cKedudukanKeluarga = new PdfPCell(); cKedudukanKeluarga.setMinimumHeight(20); cKedudukanKeluarga.addElement(pKedudukanKeluarga); tabel6.addCell(cKedudukanKeluarga); document.add(tabel6); PdfPTable tabel61 = new PdfPTable(1); tabel61.setWidthPercentage(100); Paragraph pNamaBapakIbu = new Paragraph(); pNamaBapakIbu.add("8. a. Nama Bapak : "); pNamaBapakIbu.add("\n\n Nama Ibu : "); pNamaBapakIbu.add("\n\n b. Alamat : "); pNamaBapakIbu.setLeading(0, 1); PdfPCell cNamaBapakIbu = new PdfPCell(); cNamaBapakIbu.setMinimumHeight(70); cNamaBapakIbu.addElement(pNamaBapakIbu); tabel61.addCell(cNamaBapakIbu); document.add(tabel61); //------------------------------------------------------------------------------------- KEDUDUKAN END //------------------------------------------------------------------------------------- PEKERJAAN PdfPTable tabel7 = new PdfPTable(2); tabel7.setWidthPercentage(100); Paragraph pPekerjaan = new Paragraph(); pPekerjaan.add("9. a. Pekerjaan : " + getPekerjaan()); pPekerjaan.setLeading(0, 1); PdfPCell cPekerjaan = new PdfPCell(); cPekerjaan.setMinimumHeight(20); cPekerjaan.addElement(pPekerjaan); tabel7.addCell(cPekerjaan); Paragraph pJabatan = new Paragraph(); pJabatan.add(" b. Jabatan : " + getJabatan()); pJabatan.setLeading(0, 1); PdfPCell cJabatan = new PdfPCell(); cJabatan.setMinimumHeight(20); cJabatan.addElement(pJabatan); tabel7.addCell(cJabatan); document.add(tabel7); //------------------------------------------------------------------------------------- PEKERJAAN END //------------------------------------------------------------------------------------- INSTANSI DLL PdfPTable tabel8 = new PdfPTable(1); tabel8.setWidthPercentage(100); Paragraph pInstansi = new Paragraph(); pInstansi.add(" c. Instansi/Lembaga/Kantor : " + getInstansilembagakantor()); pInstansi.setLeading(0, 1); PdfPCell cInstansi = new PdfPCell(); cInstansi.setMinimumHeight(20); cInstansi.addElement(pInstansi); tabel8.addCell(cInstansi); document.add(tabel8); //------------------------------------------------------------------------------------- INSTANSI DLL END //------------------------------------------------------------------------------------- NAMA ISTRI float[] colomn = { 7, 1, 2 }; PdfPTable tabel9 = new PdfPTable(colomn); tabel9.setWidthPercentage(100); Paragraph pNamaIstriBapakIbu = new Paragraph(); pNamaIstriBapakIbu.add("10."); pNamaIstriBapakIbu.add("\n a. Nama Istri : "); pNamaIstriBapakIbu.add("\n\n b. Nama Bapak Istri : "); pNamaIstriBapakIbu.add("\n\n c. Nama Ibu Istri : "); pNamaIstriBapakIbu.add("\n\n d. Alamat : "); pNamaIstriBapakIbu.setLeading(0, 1); PdfPCell cNamaIstriBapakIbu = new PdfPCell(); cNamaIstriBapakIbu.setMinimumHeight(110); cNamaIstriBapakIbu.addElement(pNamaIstriBapakIbu); tabel9.addCell(cNamaIstriBapakIbu); Paragraph pUmurIstriBapakIbu = new Paragraph(); pUmurIstriBapakIbu.add(" Umur :"); pUmurIstriBapakIbu.setLeading(0, 1); PdfPCell cUmurIstriBapakIbu = new PdfPCell(); cUmurIstriBapakIbu.setMinimumHeight(110); cUmurIstriBapakIbu.addElement(pUmurIstriBapakIbu); tabel9.addCell(cUmurIstriBapakIbu); Paragraph pPekerjaanIstriBapakIbu = new Paragraph(); pPekerjaanIstriBapakIbu.add(" Pekerjaan :"); pPekerjaanIstriBapakIbu.setLeading(0, 1); PdfPCell cPekerjaanIstriBapakIbu = new PdfPCell(); cPekerjaanIstriBapakIbu.setMinimumHeight(110); cPekerjaanIstriBapakIbu.addElement(pPekerjaanIstriBapakIbu); tabel9.addCell(cPekerjaanIstriBapakIbu); document.add(tabel9); //------------------------------------------------------------------------------------- NAMA ISTRI END //------------------------------------------------------------------------------------- SANAK SAUDARA PdfPTable tabel10 = new PdfPTable(colomn); tabel10.setWidthPercentage(100); Paragraph pSanakSaudara = new Paragraph(); pSanakSaudara.add("11. Nama Sanak/Saudara yang menjadi Tanggungan : \n 1.\n 2."); pSanakSaudara.setLeading(0, 1); PdfPCell cSanakSaudara = new PdfPCell(); cSanakSaudara.addElement(pSanakSaudara); tabel10.addCell(cSanakSaudara); Paragraph pSanakSaudara1 = new Paragraph(); pSanakSaudara1.add(""); pSanakSaudara1.setLeading(0, 1); PdfPCell cSanakSaudara1 = new PdfPCell(); cSanakSaudara1.addElement(pSanakSaudara1); tabel10.addCell(cSanakSaudara1); Paragraph pSanakSaudara2 = new Paragraph(); pSanakSaudara2.add(""); pSanakSaudara2.setLeading(0, 1); PdfPCell cSanakSaudara2 = new PdfPCell(); cSanakSaudara2.addElement(pSanakSaudara2); tabel10.addCell(cSanakSaudara2); document.add(tabel10); //------------------------------------------------------------------------------------- SANAK SAUDARA END //------------------------------------------------------------------------------------- ANAK2 PdfPTable tabel11 = new PdfPTable(colomn); tabel11.setWidthPercentage(100); Paragraph pAnak2 = new Paragraph(); pAnak2.add("12. Anak-anak : "); pAnak2.add("\n\n 1. "); pAnak2.add("\n\n 2. "); pAnak2.add("\n\n 3. "); pAnak2.add("\n\n 4. "); pAnak2.add("\n\n 5. "); pAnak2.add("\n\n 6. "); pAnak2.add("\n"); pAnak2.setLeading(0, 1); PdfPCell cAnak2 = new PdfPCell(); cAnak2.setMinimumHeight(165); cAnak2.addElement(pAnak2); tabel11.addCell(cAnak2); Paragraph pUmurAnak2 = new Paragraph(); pUmurAnak2.add(" Umur : "); pUmurAnak2.setLeading(0, 1); PdfPCell cUmurAnak2 = new PdfPCell(); cUmurAnak2.setMinimumHeight(165); cUmurAnak2.addElement(pUmurAnak2); tabel11.addCell(cUmurAnak2); Paragraph pPekarjaanAnak2 = new Paragraph(); pPekarjaanAnak2.add(" Pekerjaan : "); pPekarjaanAnak2.setLeading(0, 1); PdfPCell cPekerjaanAnak2 = new PdfPCell(); cPekerjaanAnak2.setMinimumHeight(165); cPekerjaanAnak2.addElement(pPekarjaanAnak2); tabel11.addCell(cPekerjaanAnak2); document.add(tabel11); //------------------------------------------------------------------------------------- ANAK2 END //------------------------------------------------------------------------------------- CIRI-CIRI PdfPTable tabel12 = new PdfPTable(1); tabel12.setWidthPercentage(100); Paragraph pCiri2 = new Paragraph(); pCiri2.add("13. Ciri-ciri badan : "); pCiri2.add("\n\n 1. Rambut : " + getRambut()); for (int i = 0; i < (35 - getRambut().length()); i++) { pCiri2.add(" "); } pCiri2.add("2. Muka : " + getMuka()); for (int i = 0; i < (35 - getMuka().length()); i++) { pCiri2.add(" "); } pCiri2.add("3. Kulit : " + getKulit()); pCiri2.setLeading(0, 1); PdfPCell cCiri2 = new PdfPCell(); cCiri2.setMinimumHeight(45); cCiri2.addElement(pCiri2); tabel12.addCell(cCiri2); document.add(tabel12); //------------------------------------------------------------------------------------- CIRI-CIRI END //------------------------------------------------------------------------------------- LANJUTAN CIRI2 PdfPTable tabel13 = new PdfPTable(1); tabel13.setWidthPercentage(100); Paragraph pCiri2Lanjutan = new Paragraph(); for (int i = 0; i < 20; i++) { pCiri2Lanjutan.add(" "); } pCiri2Lanjutan.add("4. Tinggi : " + getTinggi()); for (int i = 0; i < (35 - getTinggi().length()); i++) { pCiri2Lanjutan.add(" "); } pCiri2Lanjutan.add("5. Tanda Istimewa : " + getTandaistimewa()); pCiri2Lanjutan.setLeading(0, 1); PdfPCell cCiri2Lanjutan = new PdfPCell(); cCiri2Lanjutan.setMinimumHeight(20); cCiri2Lanjutan.addElement(pCiri2Lanjutan); tabel13.addCell(cCiri2Lanjutan); document.add(tabel13); //------------------------------------------------------------------------------------- LANJUTAN CIRI2 //------------------------------------------------------------------------------------- RUMUS SIDIK JARI PdfPTable tabel14 = new PdfPTable(1); tabel14.setWidthPercentage(100); Paragraph pSidikJari = new Paragraph(); pSidikJari.add("14. Rumus Sidik Jari : " + getRumussidikjari()); pSidikJari.setLeading(0, 1); PdfPCell cSidikJari = new PdfPCell(); cSidikJari.setMinimumHeight(20); cSidikJari.addElement(pSidikJari); tabel14.addCell(cSidikJari); document.add(tabel14); //------------------------------------------------------------------------------------- RUMUS SIDIK JARI END //------------------------------------------------------------------------------------- RIWAYAT SEKOLAH float[] colom = { 8, 2 }; PdfPTable tabel15 = new PdfPTable(colom); tabel15.setWidthPercentage(100); Paragraph pRiwayatSekolah = new Paragraph(); pRiwayatSekolah.add("15. Riwayat Sekolah : "); pRiwayatSekolah.add("\n\n 1. "); pRiwayatSekolah.add("\n\n 2. "); pRiwayatSekolah.add("\n\n 3. "); pRiwayatSekolah.add("\n\n 4. "); pRiwayatSekolah.add("\n\n 5. "); pRiwayatSekolah.add("\n\n 6. "); pRiwayatSekolah.setLeading(0, 1); PdfPCell cRiwayatSekolah = new PdfPCell(); cRiwayatSekolah.setMinimumHeight(165); cRiwayatSekolah.addElement(pRiwayatSekolah); tabel15.addCell(cRiwayatSekolah); Paragraph pTahunLulus = new Paragraph(); pTahunLulus.add("Tahun Lulus"); pTahunLulus.setLeading(0, 1); PdfPCell cTahunLulus = new PdfPCell(); cTahunLulus.setMinimumHeight(165); cTahunLulus.addElement(pTahunLulus); tabel15.addCell(cTahunLulus); document.add(tabel15); //------------------------------------------------------------------------------------- RIWAYAT SEKOLAH END //------------------------------------------------------------------------------------- KESENANGAN/KEGEMARAN/HOBI PdfPTable tabel16 = new PdfPTable(1); tabel16.setWidthPercentage(100); Paragraph pKesenenanganKegemaranHobi = new Paragraph(); pKesenenanganKegemaranHobi.add("16. Kesenangan/Kegemaran/Hobi : " + getHobi()); pKesenenanganKegemaranHobi.setLeading(0, 1); PdfPCell cKesenenanganKegemaranHobi = new PdfPCell(); cKesenenanganKegemaranHobi.setMinimumHeight(20); cKesenenanganKegemaranHobi.addElement(pKesenenanganKegemaranHobi); tabel16.addCell(cKesenenanganKegemaranHobi); document.add(tabel16); //------------------------------------------------------------------------------------- KESENANGAN/KEGEMARAN/HOBI END //------------------------------------------------------------------------------------- CATATAN KRIMINAL PdfPTable tabel17 = new PdfPTable(1); tabel17.setWidthPercentage(100); Paragraph pCatatanKriminal = new Paragraph(); pCatatanKriminal.add("17. Catatan kriminal yang ada : "); pCatatanKriminal.add("\n\n 1. " + getCatatankriminal1()); pCatatanKriminal.add("\n\n 2. " + getCatatankriminal2()); pCatatanKriminal.add("\n\n 3. " + getCatatankriminal3()); pCatatanKriminal.setLeading(0, 1); PdfPCell cCatatanKriminal = new PdfPCell(); cCatatanKriminal.setMinimumHeight(95); cCatatanKriminal.addElement(pCatatanKriminal); tabel17.addCell(cCatatanKriminal); document.add(tabel17); //------------------------------------------------------------------------------------- CATATAN KRIMINAL END //------------------------------------------------------------------------------------- KETERANGAN DLL PdfPTable tabel18 = new PdfPTable(1); tabel18.setWidthPercentage(100); Paragraph pDataKeteranganLain2 = new Paragraph(); pDataKeteranganLain2.add("18. Data Keterangan dan lain2 : "); pDataKeteranganLain2.add("\n\n\n"); pDataKeteranganLain2.setLeading(0, 1); PdfPCell cDataKeteranganLain2 = new PdfPCell(); cDataKeteranganLain2.addElement(pDataKeteranganLain2); if (list.size() > 0) { float[] kolomkegiatan = { 8, 2 }; PdfPTable nestedTable = new PdfPTable(kolomkegiatan); nestedTable.addCell(new Paragraph("Kegiatan")); nestedTable.addCell(new Paragraph("Tanggal")); for (int i = 0; i < list.size(); i++) { nestedTable.addCell(new Paragraph(list.get(i).getNamakegiatan())); nestedTable.addCell(new Paragraph(list.get(i).getTanggal())); } cDataKeteranganLain2.addElement(nestedTable); cDataKeteranganLain2.setPaddingBottom(20f); tabel18.addCell(cDataKeteranganLain2); } document.add(tabel18); //------------------------------------------------------------------------------------- KETERANGAN DLL END document.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return output; }
From source file:servlet.AdministrarRestriccion.java
public void genDocTren(HttpServletRequest request, HttpServletResponse response) throws Exception { int linea = Integer.parseInt(request.getParameter("idLinea")); //PrintWriter salida = response.getWriter(); HttpSession session = request.getSession(); // PrintWriter out = response.getWriter(); Usuario usr = (Usuario) session.getAttribute("usuario"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/*from w w w . j av a 2 s . c o m*/ String nota = new String(request.getParameter("nota").getBytes(), "UTF-8"); String nota2 = new String(request.getParameter("nota2").getBytes(), "UTF-8"); MaterialRodanteJpaController mrjc = new MaterialRodanteJpaController(Conex.getEmf()); MaterialRodante mr = mrjc .findMaterialRodante(Integer.parseInt(request.getParameter("materialRodante"))); String comunicaciones = new String(request.getParameter("comunicaciones").getBytes(), "UTF-8"); String instrucciones = new String(request.getParameter("instrucciones").getBytes(), "UTF-8"); String precauciones = new String(request.getParameter("precauciones").getBytes(), "UTF-8"); String nombre = new String(request.getParameter("nombre").getBytes(), "UTF-8"); String vigencia = request.getParameter("vigencia"); String[] fecha = vigencia.split("-"); LineaJpaController ljc = new LineaJpaController(Conex.getEmf()); Linea l = ljc.findLinea(linea); Document documento = new Document(PageSize.A4); com.itextpdf.text.Font arialNegrita = FontFactory.getFont("arial", 9, Font.BOLD); com.itextpdf.text.Font arial = FontFactory.getFont("arial", 9, Font.PLAIN); com.itextpdf.text.Font saltoDeLinea = FontFactory.getFont("arial", 5, Font.BOLD); Paragraph parrafo = new Paragraph(); int numResAs = 0; int numResDes = 0; RestriccionJpaController rjc = new RestriccionJpaController(Conex.getEmf()); List<Restriccion> restDes = rjc.buscarIdLineaDescendenteDocTren(linea, l.getVelocidadLinea()); List<Restriccion> restAsc = rjc.buscarIdLineaAscendenteDocTren(linea, l.getVelocidadLinea()); int restAscTotal = restAsc.size() - 1; int restDescTotal = restDes.size() - 1; System.out.println(restAscTotal); System.out.println(restDescTotal); PdfWriter.getInstance(documento, baos); documento.open(); do { try { URL url = getClass().getResource("/img/cintillo_s1.png"); Image foto = Image.getInstance(url); foto.scaleToFit(500, 70); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph("DOCUMENTO DE TREN: " + nombre, arialNegrita)); documento.add(new Paragraph( "L?NEA: " + l.getNombreLinea() + " : Documento Vlido Para Todos Los Trenes", arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable tabla = new PdfPTable(1); tabla.setHorizontalAlignment(10); tabla.setWidthPercentage(100f); tabla.addCell(new Paragraph("Operaciones Del Tren: circular a una velocidad no mayor de " + l.getVelocidadLinea() + " Km/h", arial)); tabla.addCell(new Paragraph("Nota: " + nota, arial)); //tabla.getDefaultCell().setBorder(2); if (numResAs < restAscTotal) { tabla.getDefaultCell().setBorderWidthBottom(0); tabla.addCell(new Paragraph("Restricciones Ascendentes ", arialNegrita)); } tabla.getDefaultCell().setBorderColorBottom(BaseColor.WHITE); int c = 0; for (int i = numResAs; i <= restAscTotal; i++) { if (c > 30) { break; } // System.out.println("imrimiento asc: "+numResAs); int pkI = (int) (restAsc.get(numResAs).getProgInicio() / 1000); int pkI1 = (int) (((restAsc.get(numResAs).getProgInicio() / 1000) - pkI) * 1000); int pkF = (int) (restAsc.get(numResAs).getProgFinal() / 1000); int pkF1 = (int) (((restAsc.get(numResAs).getProgFinal() / 1000) - pkF) * 1000); tabla.getDefaultCell().setBorder(14); tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); tabla.addCell(new Paragraph("*PK " + pkI + "+" + pkI1 + " al " + pkF + "+" + pkF1 + " circular a una velocidad no mayor de " + restAsc.get(numResAs).getVelocidadMaxAscendente() + " " + restAsc.get(numResAs).getObservacion(), arial)); numResAs++; c++; } if (c < 30) { tabla.getDefaultCell().setBorderWidthBottom(1); tabla.getDefaultCell().setBorderWidthTop(1); tabla.getDefaultCell().setBorder(14); tabla.addCell(new Paragraph("Restricciones Descendentes ", arialNegrita)); } int d = c; if (c < 30) { for (int i = numResDes; i <= restDescTotal; i++) { if (d > 30) { break; } tabla.getDefaultCell().setBorder(14); tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); int pkI = (int) (restDes.get(numResDes).getProgFinal() / 1000); int pkI1 = (int) (((restDes.get(numResDes).getProgFinal() / 1000) - pkI) * 1000); int pkF = (int) (restDes.get(numResDes).getProgInicio() / 1000); int pkF1 = (int) (((restDes.get(numResDes).getProgInicio() / 1000) - pkF) * 1000); tabla.addCell(new Paragraph("*PK " + pkI + "+" + pkI1 + " al " + pkF + "+" + pkF1 + " circular a una velocidad no mayor de " + restDes.get(numResDes).getVelocidadMaxDescendente() + " " + restDes.get(numResDes).getObservacion(), arial)); numResDes++; d++; } } int espacios = d; while (espacios < 30) { tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); tabla.addCell(new Paragraph(" ", arial)); espacios++; } tabla.getDefaultCell().setBorder(15); tabla.getDefaultCell().setBorderWidthBottom(1); tabla.getDefaultCell().setBorderWidthTop(1); tabla.getDefaultCell().setMinimumHeight(50f); tabla.addCell(new Paragraph("Instrucciones: " + instrucciones, arial)); tabla.addCell(new Paragraph("Comunicaciones: " + comunicaciones, arial)); tabla.addCell(new Paragraph("Precauciones: " + precauciones, arial)); tabla.getDefaultCell().setMinimumHeight(10f); tabla.addCell(new Paragraph("Vigencia A Partir De: " + fecha[0] + "/" + fecha[1] + "/" + fecha[2], arial)); tabla.getDefaultCell().setBorder(1); Paragraph preface = new Paragraph(Paragraph.ALIGN_CENTER, "Realizado Por: " + usr.toString() + " - Gerencia de Gestin de Trfico", arialNegrita); preface.setAlignment(Element.ALIGN_CENTER); tabla.addCell(preface); tabla.getDefaultCell().setBorder(0); tabla.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER); preface = new Paragraph(Paragraph.ALIGN_CENTER, "EL NO CUMPLIR CON LAS LIMITACIONES PRESCRITAS EN ESTE" + " DOCUMENTO VA EN CONTRA DE LA SEGURIDAD EN LA CIRCULACIN, POR LO TANTO SER? MOTIVO DE SANCIN", FontFactory.getFont("arial", 8f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "Nota: Informacin sustentada con el informe tcnico " + "de limitaciones de velocidad, emitido por el CCF (Centro de Control de Fallas)", FontFactory.getFont("arial", 8f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "Sentido Ascendente: Sentido en el cual aumenta la progresiva ej: 0+0 -> 41+000 -- Sentido Descendente: Sentido en el cual disminuye la progresiva ej: 41+000 -> 0+0 ", FontFactory.getFont("arial", 6f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "En la lnea Caracas-Cua el sentido ASCENDENTE corresponde a la V?A PAR y el DESCENDENTE a la V?A IMPAR", FontFactory.getFont("arial", 6f)); tabla.addCell(preface); documento.add(tabla); if (numResAs < restAscTotal || numResDes < restDescTotal) { documento.newPage(); } } while (numResAs < restAscTotal || numResDes < restDescTotal); System.out.println("Termine"); //CARACTER?STICAS DE MATERIAL RODANTE documento.newPage(); try { URL url = getClass().getResource("/img/cintillo_s1.png"); Image foto = Image.getInstance(url); foto.scaleToFit(500, 70); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph("DOCUMENTO DE TREN: " + nombre, arialNegrita)); documento.add(new Paragraph( "L?NEA: " + l.getNombreLinea() + " : Documento Vlido Para Todos Los Trenes", arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add( new Paragraph("CARACTER?STICAS DE LA UNIDAD: " + mr.getNombreMaterialRodante(), arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable tablaMT = new PdfPTable(2); tablaMT.addCell(new Paragraph("ITEM", arialNegrita)); tablaMT.addCell(new Paragraph("DESCRIPCIN", arialNegrita)); tablaMT.addCell(new Paragraph("Nmero de Unidades Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getNumeroRemolque() + " Unidades", arial)); tablaMT.addCell(new Paragraph("Nmero de Unidades Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getNumeroMotriz() + " Unidades", arial)); tablaMT.addCell(new Paragraph("Longitud Total", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudTotal() + " m", arial)); tablaMT.addCell(new Paragraph("Longitud Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudRemolque() + " m", arial)); tablaMT.addCell(new Paragraph("Longitud Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudMotriz() + " m", arial)); tablaMT.addCell(new Paragraph("Alto x Ancho Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getAltoXAnchoMotriz() + " m", arial)); tablaMT.addCell(new Paragraph("Alto x Ancho Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getAltoXAnchoRemolque() + " m", arial)); tablaMT.addCell(new Paragraph("Masa o Tara Total", arial)); tablaMT.addCell(new Paragraph(mr.getMasa() + " t", arial)); tablaMT.addCell(new Paragraph("Masa Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getMasaRemolque() + " t", arial)); tablaMT.addCell(new Paragraph("Masa Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getMasaMotriz() + " t", arial)); tablaMT.addCell(new Paragraph("Frenado", arial)); tablaMT.addCell(new Paragraph(mr.getFrenadoDescripcion() + "", arial)); tablaMT.addCell(new Paragraph("Trocha", arial)); tablaMT.addCell(new Paragraph(l.getTrocha() + " m", arial)); tablaMT.addCell(new Paragraph("Velocidad Comercial", arial)); tablaMT.addCell(new Paragraph(mr.getVelocidadOperativa() + " Km/h", arial)); tablaMT.addCell(new Paragraph("Aceleracin Mx.", arial)); tablaMT.addCell(new Paragraph(mr.getAceleracionMax() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Desaceleracin de Servicio", arial)); tablaMT.addCell(new Paragraph(mr.getDesaceleracionMax() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Desaceleracion de Emergencia", arial)); tablaMT.addCell(new Paragraph(mr.getDesaceleracionEmergencia() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Voltaje", arial)); tablaMT.addCell(new Paragraph(mr.getVoltaje() + " V", arial)); tablaMT.addCell(new Paragraph("Voltaje de Bateras", arial)); tablaMT.addCell(new Paragraph(mr.getVoltajeBateria() + " V", arial)); tablaMT.addCell(new Paragraph("Presin de Trabajo", arial)); tablaMT.addCell(new Paragraph(mr.getPresionTrabajo() + "", arial)); if (mr.getSubTipo().equals("Tren de Viajeros")) { tablaMT.addCell(new Paragraph("Capacidad Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadRemolque() + " pasajeros", arial)); tablaMT.addCell(new Paragraph("Capacidad Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadMotriz() + " pasajeros", arial)); tablaMT.addCell(new Paragraph("Capacidad Total", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadPasajeros() + " pasajeros", arial)); } else { tablaMT.addCell(new Paragraph("Capacidad Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadRemolque() + " t", arial)); tablaMT.addCell(new Paragraph("Capacidad Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadMotriz() + " t", arial)); tablaMT.addCell(new Paragraph("Capacidad Total", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadPasajeros() + " t", arial)); } documento.add(tablaMT); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); try { URL url = getClass().getResource("/img/" + request.getParameter("materialRodante") + ".jpg"); Image foto = Image.getInstance(url); foto.scaleToFit(300, 300); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable t = new PdfPTable(1); t.setWidthPercentage(100f); t.addCell("Nota: " + nota2); documento.add(t); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); Paragraph preface = new Paragraph(Paragraph.ALIGN_CENTER, "Realizado Por: " + usr.toString(), arialNegrita); documento.add(preface); documento.close(); response.addHeader("Content-Disposition", "attachment; filename=DocumentoDeTren.pdf"); response.addHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.addHeader("Pragma", "public"); response.setContentType("application/pdf"); DataOutput output = new DataOutputStream(response.getOutputStream()); byte[] bytes = baos.toByteArray(); response.setContentLength(bytes.length); for (int i = 0; i < bytes.length; i++) { output.writeByte(bytes[i]); } } catch (Exception e) { e.printStackTrace(); // salida.print("http://localhost:8084/MODULO2.3/img/error.png"); } }
From source file:servlet.GenerarPDF.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w .jav a2s .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("text/html;charset=UTF-8"); Document document = new Document(); try { ConexionDB sqlite = new ConexionDB(); java.sql.Connection cn = sqlite.Conectar(); Statement st = cn.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM mascotas;"); response.setContentType("APPLICATION/download"); response.setHeader("Content-Disposition", "filename=Mascotas.pdf"); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); Image image = Image.getInstance( "C:/Users/Cristian/Documents/NetBeansProjects/adopc-mascotas/web/imagenes/logo9.png"); image.scaleAbsolute(100, 100); document.add(image); Paragraph preface = new Paragraph("LOVE MY PET"); preface.setAlignment(Element.ALIGN_CENTER); document.add(preface); PdfPTable table = new PdfPTable(5); // 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, 1f }; table.setWidths(columnWidths); PdfPCell cellusuario = new PdfPCell(new Paragraph("usario")); cellusuario.setBorderColor(BaseColor.BLUE); cellusuario.setPaddingLeft(10); cellusuario.setHorizontalAlignment(Element.ALIGN_CENTER); cellusuario.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell celltipo = new PdfPCell(new Paragraph("tipo")); celltipo.setBorderColor(BaseColor.BLUE); celltipo.setPaddingLeft(10); celltipo.setHorizontalAlignment(Element.ALIGN_CENTER); celltipo.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cellnombre = new PdfPCell(new Paragraph("nombre")); cellnombre.setBorderColor(BaseColor.BLUE); cellnombre.setPaddingLeft(10); cellnombre.setHorizontalAlignment(Element.ALIGN_CENTER); cellnombre.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cellraza = new PdfPCell(new Paragraph("raza")); cellraza.setBorderColor(BaseColor.BLUE); cellraza.setPaddingLeft(10); cellraza.setHorizontalAlignment(Element.ALIGN_CENTER); cellraza.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell celledad = new PdfPCell(new Paragraph("edad")); celledad.setBorderColor(BaseColor.BLUE); celledad.setPaddingLeft(10); celledad.setHorizontalAlignment(Element.ALIGN_CENTER); celledad.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cellusuario); table.addCell(celltipo); table.addCell(cellnombre); table.addCell(cellraza); table.addCell(celledad); while (rs.next()) { PdfPCell cell1 = new PdfPCell(new Paragraph(rs.getString(1))); cell1.setPaddingLeft(1); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell1); PdfPCell cell2 = new PdfPCell(new Paragraph(rs.getString(2))); cell2.setPaddingLeft(2); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Paragraph(rs.getString(3))); cell3.setPaddingLeft(3); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setBackgroundColor(BaseColor.LIGHT_GRAY); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell3); PdfPCell cell4 = new PdfPCell(new Paragraph(rs.getString(4))); cell4.setPaddingLeft(4); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setBackgroundColor(BaseColor.LIGHT_GRAY); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell4); PdfPCell cell5 = new PdfPCell(new Paragraph(rs.getString(5))); cell5.setPaddingLeft(5); cell5.setHorizontalAlignment(Element.ALIGN_CENTER); cell5.setBackgroundColor(BaseColor.LIGHT_GRAY); cell5.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell5); } document.add(table); //Add more content here cn.close(); } catch (Exception e) { e.printStackTrace(); } document.close(); }
From source file:servlet.SalesReportPDF.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . ja v a 2 s . c om*/ * * @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 { try { Document document = new Document(); List<ArrayList> data = productSession.getEventList(); List<ArrayList> sessions = getAllProductDetailsLocal.getAllSessions(); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); //get current date time with Date() Date date = new Date(); //System.out.println(dateFormat.format(date)); @SuppressWarnings("unused") PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream("C:/Users/Yong Jing Ying/Desktop/EventRecords.pdf")); document.open(); document.add(new Paragraph("Management Report", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.BLUE))); document.add(new Paragraph("PDF created on " + dateFormat.format(date).toString() + "\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); document.add(new Paragraph( "------------------------------------------------------------------------------------", FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.BLACK))); for (int i = 0; i < data.size(); i++) { document.add(new Paragraph(data.get(i).get(1).toString() + " Event Details ", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); document.add(new Paragraph("Event Type : " + data.get(i).get(4).toString() + "\nStart Date : " + data.get(i).get(2).toString() + "\nEnd Date : " + data.get(i).get(3).toString() + "\nProperty Name : " + data.get(i).get(5).toString() + "\nNo of Category : " + data.get(i).get(6).toString() + "\nPromotions : " + data.get(i).get(7).toString() + "\n\n")); document.add(new Paragraph("Session", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); PdfPTable table = new PdfPTable(6); //table.addCell("item1"); table.setSpacingBefore(5); table.setSpacingAfter(5); table.setWidths(new int[] { 1, 2, 3, 3, 3, 3 }); table.setWidthPercentage(100); PdfPCell cell; cell = new PdfPCell(new Phrase("No:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.CYAN); table.addCell(cell); cell = new PdfPCell(new Phrase("Name:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.CYAN); table.addCell(cell); cell = new PdfPCell(new Phrase("Description:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.CYAN); table.addCell(cell); cell = new PdfPCell(new Phrase("Start:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.CYAN); table.addCell(cell); cell = new PdfPCell(new Phrase("End:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.CYAN); table.addCell(cell); cell = new PdfPCell(new Phrase("TicketPrices:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.CYAN); table.addCell(cell); for (int j = 0; j < sessions.size(); j++) { if (sessions.get(j).get(1).toString().equals(data.get(i).get(4).toString()) && sessions.get(j).get(0).toString().equals(data.get(i).get(0).toString())) { cell = new PdfPCell(new Phrase(sessions.get(j).get(8).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); cell = new PdfPCell(new Phrase(sessions.get(j).get(4).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); cell = new PdfPCell(new Phrase(sessions.get(j).get(5).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); cell = new PdfPCell(new Phrase(sessions.get(j).get(6).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); cell = new PdfPCell(new Phrase(sessions.get(j).get(7).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); cell = new PdfPCell(new Phrase(sessions.get(j).get(9).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); } } document.add(table); document.add(new Paragraph("\n")); document.add(new Paragraph("Alert", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); table = new PdfPTable(6); //table.addCell("item1"); table.setSpacingBefore(5); table.setSpacingAfter(5); table.setWidths(new int[] { 1, 2, 2, 3, 3, 3 }); table.setWidthPercentage(100); cell = new PdfPCell(new Phrase("No:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.GREEN); table.addCell(cell); cell = new PdfPCell(new Phrase("Alert Type:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.GREEN); table.addCell(cell); cell = new PdfPCell(new Phrase("Below Sales:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.GREEN); table.addCell(cell); cell = new PdfPCell(new Phrase("In-Charged Email:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.GREEN); table.addCell(cell); cell = new PdfPCell(new Phrase("Start:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.GREEN); table.addCell(cell); cell = new PdfPCell(new Phrase("End:", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK))); cell.setBackgroundColor(BaseColor.GREEN); table.addCell(cell); for (int j = 0; j < sessions.size(); j++) { if (sessions.get(j).get(1).toString().equals(data.get(i).get(4).toString()) && sessions.get(j).get(0).toString().equals(data.get(i).get(0).toString()) && sessions.get(j).size() == 15) { cell = new PdfPCell(new Phrase(sessions.get(j).get(8).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); cell = new PdfPCell(new Phrase(sessions.get(j).get(10).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); cell = new PdfPCell(new Phrase(sessions.get(j).get(11).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); cell = new PdfPCell(new Phrase(sessions.get(j).get(12).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); cell = new PdfPCell(new Phrase(sessions.get(j).get(13).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); cell = new PdfPCell(new Phrase(sessions.get(j).get(14).toString())); cell.setBackgroundColor(BaseColor.WHITE); table.addCell(cell); } } document.add(table); document.add(new Paragraph("\n\n")); } document.close(); Thread.sleep(1000); PrintWriter out = response.getWriter(); String fileName = "EventRecords.pdf"; String filePath = "C:/Users/Yong Jing Ying/Desktop/"; response.setContentType("APPLICATION/OCTET-STREAM"); response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\""); FileInputStream fi = new FileInputStream("C:/Users/Yong Jing Ying/Desktop/EventRecords.pdf"); int i; while ((i = fi.read()) != -1) { out.write(i); } out.close(); fi.close(); } catch (Exception ex) { Logger.getLogger(SalesReportPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Servlets.GenerarPinesGrupo.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String[] idEstudiante = req.getParameterValues("imprimir"); resp.setContentType("application/pdf"); OutputStream out = resp.getOutputStream(); String foto = getServletContext().getRealPath("/recursos/img/logoColegio.png"); req.setCharacterEncoding("UTF-8"); try {//from w w w. j av a2 s. co m try { Document documento = new Document(); PdfWriter.getInstance(documento, out); documento.open(); Paragraph par1 = new Paragraph(); Font fontit = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.GRAY); par1.add(new Phrase("Pin de Acceso HeartsTics", fontit)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); // Image image = Image.getInstance("E:\\ArchivosVarios\\logoColegio.png"); // image.scalePercent(50); Image image = Image.getInstance(foto); image.scalePercent(60); Font fuentetabla = FontFactory.getFont("Arial", 8, Font.BOLD, BaseColor.BLACK); Font fuentetablaPin = FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK); Font fuentetablaHeader = FontFactory.getFont("Arial", 9, Font.BOLD, BaseColor.BLACK); Servicio controlador = new Servicio(); for (int i = 0; i < idEstudiante.length; i++) { int idEst = Integer.parseInt(idEstudiante[i]); Pin estudiante = controlador.pinEstudiante(idEst); PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(60); PdfPCell celdaHeader = new PdfPCell( new Paragraph("COLEGIO SAGRADOS CORAZONES", fuentetablaHeader)); celdaHeader.setVerticalAlignment(Element.ALIGN_MIDDLE); celdaHeader.setHorizontalAlignment(Element.ALIGN_CENTER); celdaHeader.setColspan(3); tabla.addCell(celdaHeader); PdfPCell celda01 = new PdfPCell(image); //PdfPCell celda01 = new PdfPCell(new Paragraph("imagen")); celda01.setHorizontalAlignment(Element.ALIGN_CENTER); celda01.setVerticalAlignment(Element.ALIGN_MIDDLE); celda01.setRowspan(2); celda01.setBorder(Rectangle.NO_BORDER); celda01.setBorder(Rectangle.LEFT); tabla.addCell(celda01); PdfPCell celda1 = new PdfPCell(new Paragraph( "Estudiante: " + estudiante.getNombres() + " " + estudiante.getApellidos(), fuentetabla)); PdfPCell celda2 = new PdfPCell(new Paragraph("Pin: " + estudiante.getIdPin(), fuentetablaPin)); PdfPCell celda3 = new PdfPCell( new Paragraph("Fecha creacion: " + estudiante.getInicio(), fuentetabla)); PdfPCell celda4 = new PdfPCell( new Paragraph("Fecha vencimiento: " + estudiante.getFin(), fuentetabla)); celda1.setHorizontalAlignment(Element.ALIGN_CENTER); celda1.setVerticalAlignment(Element.ALIGN_MIDDLE); celda1.setColspan(2); celda1.setBorder(Rectangle.NO_BORDER); celda1.setBorder(Rectangle.RIGHT); celda2.setHorizontalAlignment(Element.ALIGN_CENTER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); celda2.setColspan(2); celda2.setBorder(Rectangle.NO_BORDER); celda2.setBorder(Rectangle.RIGHT); PdfPTable tableFecha = new PdfPTable(2); tableFecha.setWidthPercentage(60); celda3.setHorizontalAlignment(Element.ALIGN_CENTER); celda4.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda1); tabla.addCell(celda2); tableFecha.addCell(celda3); tableFecha.addCell(celda4); Paragraph par2 = new Paragraph(); par2.add(new Phrase(Chunk.NEWLINE)); documento.add(par2); documento.add(tabla); documento.add(tableFecha); } documento.close(); } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:Servlets.GenerarPinEstudiante.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { int idEstudiante = Integer.parseInt(req.getParameter("idEst")); resp.setContentType("application/pdf"); OutputStream out = resp.getOutputStream(); String foto = getServletContext().getRealPath("/recursos/img/logoColegio.png"); req.setCharacterEncoding("UTF-8"); try {/*from w w w . j a va 2 s . c o m*/ try { Document documento = new Document(); PdfWriter.getInstance(documento, out); documento.open(); Paragraph par1 = new Paragraph(); Font fontit = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.GRAY); par1.add(new Phrase("Pin de Acceso HeartsTics", fontit)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); // Image image = Image.getInstance("E:\\ArchivosVarios\\logoColegio.png"); // image.scalePercent(50); Image image = Image.getInstance(foto); image.scalePercent(60); Font fuentetabla = FontFactory.getFont("Arial", 8, Font.BOLD, BaseColor.BLACK); Font fuentetablaPin = FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK); Font fuentetablaHeader = FontFactory.getFont("Arial", 9, Font.BOLD, BaseColor.BLACK); Servicio controlador = new Servicio(); Pin estudiante = controlador.pinEstudiante(idEstudiante); PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(60); PdfPCell celdaHeader = new PdfPCell(new Paragraph("COLEGIO SAGRADOS CORAZONES", fuentetablaHeader)); celdaHeader.setVerticalAlignment(Element.ALIGN_MIDDLE); celdaHeader.setHorizontalAlignment(Element.ALIGN_CENTER); celdaHeader.setColspan(3); tabla.addCell(celdaHeader); PdfPCell celda01 = new PdfPCell(image); //PdfPCell celda01 = new PdfPCell(new Paragraph("imagen")); celda01.setHorizontalAlignment(Element.ALIGN_CENTER); celda01.setVerticalAlignment(Element.ALIGN_MIDDLE); celda01.setRowspan(2); celda01.setBorder(Rectangle.NO_BORDER); celda01.setBorder(Rectangle.LEFT); tabla.addCell(celda01); PdfPCell celda1 = new PdfPCell(new Paragraph( "Estudiante: " + estudiante.getNombres() + " " + estudiante.getApellidos(), fuentetabla)); PdfPCell celda2 = new PdfPCell(new Paragraph("Pin: " + estudiante.getIdPin(), fuentetablaPin)); PdfPCell celda3 = new PdfPCell( new Paragraph("Fecha creacion: " + estudiante.getInicio(), fuentetabla)); PdfPCell celda4 = new PdfPCell( new Paragraph("Fecha vencimiento: " + estudiante.getFin(), fuentetabla)); celda1.setHorizontalAlignment(Element.ALIGN_CENTER); celda1.setVerticalAlignment(Element.ALIGN_MIDDLE); celda1.setColspan(2); celda1.setBorder(Rectangle.NO_BORDER); celda1.setBorder(Rectangle.RIGHT); celda2.setHorizontalAlignment(Element.ALIGN_CENTER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); celda2.setColspan(2); celda2.setBorder(Rectangle.NO_BORDER); celda2.setBorder(Rectangle.RIGHT); PdfPTable tableFecha = new PdfPTable(2); tableFecha.setWidthPercentage(60); celda3.setHorizontalAlignment(Element.ALIGN_CENTER); celda4.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda1); tabla.addCell(celda2); tableFecha.addCell(celda3); tableFecha.addCell(celda4); Paragraph par2 = new Paragraph(); par2.add(new Phrase(Chunk.NEWLINE)); documento.add(par2); documento.add(tabla); documento.add(tableFecha); documento.close(); } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }