List of usage examples for com.itextpdf.text Image scalePercent
public void scalePercent(final float percent)
From source file:de.tuttas.servlets.DokuServlet.java
private Document createBetriebsListe(MyTableDataModel mo, String kopf, OutputStream out) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);//from w w w.ja v a 2s . co m htmlString.append( "<br></br><table align='center' width='100%' style=\"border: 2px solid black; border-collapse: collapse;\">"); htmlString.append( "<tr><td width='25%' style=\"padding:5px;font-size: 14;border: 1px solid black;\"><b>Name</b></td>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(1, 0) + "</td>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(2, 0) + "</td>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(3, 0) + "</td>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(4, 0) + "</td>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(5, 0) + "</td>"); htmlString.append("</tr>"); for (int y = 1; y < mo.getRows(); y++) { htmlString.append("<tr>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(0, y) + "</td>"); for (int x = 1; x < mo.getCols(); x++) { htmlString.append("<td style=\"font-size: 10;padding:5px;border: 1px solid black;\">" + mo.getData(x, y) + "</td>"); } htmlString.append("</tr>"); } htmlString.append("</table>"); document.open(); // Dokument erzeugen InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createNotenliste(MyTableDataModel mo, String kopf, OutputStream out, String schuljahrName) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);//from ww w . ja v a 2 s . com htmlString.append("<h3 align=\"center\">" + schuljahrName + "</h3>"); htmlString.append( "<table align='center' width='100%' style=\"border: 2px solid black; border-collapse: collapse;\">"); htmlString.append( "<tr><td width='25%' style=\"padding:5px;font-size: 14;border: 1px solid black;\"><b>Name</b></td>"); for (int x = 1; x < mo.getCols(); x++) { htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(x, 0) + "</td>"); } htmlString.append("</tr>"); for (int y = 1; y < mo.getRows(); y++) { htmlString.append("<tr>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(0, y) + "</td>"); for (int x = 1; x < mo.getCols(); x++) { htmlString .append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(x, y) + "</td>"); } htmlString.append("</tr>"); } htmlString.append("</table>"); document.open(); // Dokument erzeugen InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createStundenplan(Klasse kl, String kopf, Date parsedFrom, Date parsedTo, OutputStream out) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);//from w ww. ja v a 2 s . co m htmlString.append(StundenplanUtil.getInstance().getPlan(kl.getKNAME(), PlanType.STDPlanSchueler)); document.open(); // Dokument erzeugen InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createVertretungsplan(Klasse kl, String kopf, Date parsedFrom, Date parsedTo, OutputStream out) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);/* ww w . ja v a 2s . c o m*/ htmlString.append(StundenplanUtil.getInstance().getPlan(kl.getKNAME(), PlanType.VERTRPlanSchueler)); document.open(); // Dokument erzeugen InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createFehlzeiten(Klasse kl, String kopf, Date parsedFrom, Date parsedTo, OutputStream out) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);/*w ww.j a va2s.c o m*/ TypedQuery<AnwesenheitEintrag> query = em.createNamedQuery("findAnwesenheitbyKlasse", AnwesenheitEintrag.class); query.setParameter("paramKName", kl.getKNAME()); query.setParameter("paramFromDate", new java.sql.Date(parsedFrom.getTime())); query.setParameter("paramToDate", new java.sql.Date(parsedTo.getTime())); Log.d("setze From auf " + new java.sql.Date(parsedFrom.getTime())); List<AnwesenheitObjekt> anwesenheit = getData(query); Log.d("Result List:" + anwesenheit); document.open(); String tagZeile = ""; tagZeile += "<table align='center' width='100%' style=\"border: 2px solid black; border-collapse: collapse;\">\n"; tagZeile += AnwesenheitObjekt.getTRHead(); for (AnwesenheitObjekt ao : anwesenheit) { VerspaetungsUtil.parse(ao); if (ao.getAnzahlVerspaetungen() != 0 || ao.getSummeFehltage() != 0) { Schueler s = em.find(Schueler.class, ao.getId_Schueler()); Log.d("Fehltage fr Schuler " + s); tagZeile += ao.toHTML(s.getVNAME() + " " + s.getNNAME()); } } tagZeile += "</table>"; htmlString.append(tagZeile); // Dokument erzeugen InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createAnwesenheit(Klasse kl, String kopf, Date parsedFrom, Date parsedTo, OutputStream out, int filter1Id, int filter2Id) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);//from w w w.j a v a 2s . c o m /* Anwesenheit einfgen */ TypedQuery<AnwesenheitEintrag> query = em.createNamedQuery("findAnwesenheitbyKlasse", AnwesenheitEintrag.class); query.setParameter("paramKName", kl.getKNAME()); query.setParameter("paramFromDate", new java.sql.Date(parsedFrom.getTime())); query.setParameter("paramToDate", new java.sql.Date(parsedTo.getTime())); Log.d("setze From auf " + new java.sql.Date(parsedFrom.getTime())); List<AnwesenheitObjekt> anwesenheit = getData(query); /** * Termindaten holen */ Termine t1 = null; Termine t2 = null; if (filter1Id != -1) { t1 = em.find(Termine.class, filter1Id); } if (filter2Id != -1) { t2 = em.find(Termine.class, filter2Id); } List<Termin> termine = null; TypedQuery<Termin> tquery = null; if (filter1Id != 0) { // zwei Filter if (filter2Id != 0) { tquery = em.createNamedQuery("findAllTermineTwoFilters", Termin.class); tquery.setParameter("filter1", t1.getId()); tquery.setParameter("filter2", t2.getId()); tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime())); tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime())); termine = tquery.getResultList(); } // nur Filter1 else { tquery = em.createNamedQuery("findAllTermineOneFilter", Termin.class); tquery.setParameter("filter1", t1.getId()); tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime())); tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime())); termine = tquery.getResultList(); } } else { // nur Filter2 if (filter2Id != 0) { tquery = em.createNamedQuery("findAllTermineOneFilter", Termin.class); tquery.setParameter("filter1", t2.getId()); tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime())); tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime())); termine = tquery.getResultList(); } // kein Filter, Termine so generieren else { termine = new ArrayList<>(); Date current = new Date(parsedFrom.getTime()); parsedTo.setTime(parsedTo.getTime() + 1000); while (current.before(parsedTo)) { termine.add(new Termin(new Timestamp(current.getTime()))); Log.d("Erzeuge neuen Termin:" + new Termin(new Timestamp(current.getTime()))); current.setTime(current.getTime() + 24 * 60 * 60 * 1000); } } } Log.d("Result List:" + anwesenheit); GregorianCalendar c = (GregorianCalendar) GregorianCalendar.getInstance(); c.setTime(parsedFrom); String tagZeile = ""; document.open(); Query q = em.createNamedQuery("findSchuelerEinerBenanntenKlasse"); q.setParameter("paramNameKlasse", kl.getKNAME()); List<Schueler> schueler = q.getResultList(); Date current = new Date(parsedFrom.getTime()); Log.d("Current=" + current + " TO=" + parsedTo + " From=" + parsedFrom + " Termine=" + termine.size()); int spalte = 0; for (spalte = 0; spalte < termine.size(); spalte++) { tagZeile += "<table align='center' width='100%' style=\"border: 2px solid black; border-collapse: collapse;\">\n"; tagZeile += ("<tr >\n"); tagZeile += ("<td width='25%' style=\"font-size: 14;border: 1px solid black;\"><b>Name</b></td>\n"); // Zeile f. Tage (Headline) Log.d("Spalte ist nun " + spalte); int i = 0; for (i = 0; i < 7 && spalte + i < termine.size(); i++) { current = new Date(termine.get(spalte + i).getDate().getTime()); c.setTime(current); if (c.get(GregorianCalendar.DAY_OF_WEEK) == 1 || c.get(GregorianCalendar.DAY_OF_WEEK) == 7) { tagZeile += ("<td align=\"center\" style=\"padding:5px; background-color: #cccccc; font-size: 12;border: 1px solid black;\">" + DatumUtil.getWochentag(c.get(GregorianCalendar.DAY_OF_WEEK)) + "<br></br>" + c.get(GregorianCalendar.DATE) + "." + (c.get(GregorianCalendar.MONTH) + 1) + "." + c.get(GregorianCalendar.YEAR) + "</td>\n"); } else { tagZeile += ("<td align=\"center\" style=\"padding: 5px; font-size: 12;border: 1px solid black;\">" + DatumUtil.getWochentag(c.get(GregorianCalendar.DAY_OF_WEEK)) + "<br></br>" + c.get(GregorianCalendar.DATE) + "." + (c.get(GregorianCalendar.MONTH) + 1) + "." + c.get(GregorianCalendar.YEAR) + "</td>\n"); } Log.d("Spalte " + (i + spalte) + " Datum=" + current); } Log.d("Head aufgebaut"); tagZeile += "</tr>\n"; // Zeile pro Name for (Schueler s : schueler) { tagZeile += "<tr>\n"; tagZeile += ("<td width='20%' style=\"padding: 5px;font-size: 12;border: 1px solid black;\"><b>" + s.getVNAME() + " " + s.getNNAME() + "</b></td>\n"); // Zeile f. Tage //Log.d("Zeile f. Schler " + s.getNNAME()); for (i = 0; i < 7 && spalte + i < termine.size(); i++) { current = new Date(termine.get(spalte + i).getDate().getTime()); c.setTime(current); if (c.get(GregorianCalendar.DAY_OF_WEEK) == 1 || c.get(GregorianCalendar.DAY_OF_WEEK) == 7) { tagZeile += ("<td style=\"background-color:#cccccc;font-size: 11;border: 1px solid black;\">" + findVermerk(s.getId(), current, anwesenheit) + "</td>\n"); } else { tagZeile += ("<td style=\"font-size: 11;border: 1px solid black;\">" + findVermerk(s.getId(), current, anwesenheit) + "</td>\n"); } Log.d("Zeile f. Schler " + s.getNNAME() + " Datum " + current); } tagZeile += "</tr>\n"; } Log.d("Rumpf aufgebaut"); spalte = spalte + i - 1; // neue Seite bei 7 Terminen if (i == 7) { tagZeile += "</table>\n"; htmlString.append(tagZeile); InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.newPage(); Log.d("neue Seite"); htmlString = new StringBuilder(); tagZeile = ""; htmlString.append(kopf); } Log.d("SPalte ist " + spalte + " Termine=" + termine.size()); } Log.d("Ende der ForSchleife spalte=" + spalte); // den Rest der Seite noch drucken if (spalte % 7 != 0) { tagZeile += "</table>\n"; htmlString.append(tagZeile); Log.d("Rest Seite erzeugen"); //Log.d("html String =" + htmlString.toString()); //document.add(new Paragraph("Tutorial to Generate PDF using Servlet")); InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); Log.d("writer=" + writer + " document=" + document + " is=" + is); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); } document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createPortfolio(Klasse kl, OutputStream out) throws DocumentException, IOException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); document.open();/*ww w .jav a 2 s. co m*/ Query q = em.createNamedQuery("findSchuelerEinerBenanntenKlasse"); q.setParameter("paramNameKlasse", kl.getKNAME()); List<Schueler> schueler = q.getResultList(); Query q2 = em.createNamedQuery("findPortfolio"); q2.setParameter("paramIdKlasse", kl.getId()); List<Noten_all> portfolio = q2.getResultList(); Query q3 = em.createNamedQuery("getLatestSchuljahr").setMaxResults(1); List<Schuljahr> schuljahr = q3.getResultList(); Log.d("Schuljahr = " + schuljahr.get(0).getNAME() + " Zeugnisdatum=" + schuljahr.get(0).getZEUGNISDATUM()); Log.d("Noten_all=" + portfolio); for (Schueler s : schueler) { htmlString.append("<h2 align=\"center\">Multi Media Berufsbildende Schulen</h2>"); htmlString.append("<h2 align=\"center\">der Region Hannover</h2>"); htmlString.append("<hr></hr>"); htmlString.append("<h1 align=\"center\">Portfolio</h1>"); htmlString.append("<h3 align=\"center\">ber besuchte Zusatzkurse</h3>"); htmlString.append("<p align=\"center\">fr " + s.getVNAME() + " " + s.getNNAME() + " geb. am " + toReadable(s.getGEBDAT()) + "</p>"); htmlString.append("<br></br>"); htmlString.append("<hr></hr>"); htmlString.append("<br></br>"); int oldSchuljahr = -1; for (Noten_all p : portfolio) { Log.d("Suche fr Schler ID=" + s.getId() + " einen Portfolioeintrag, found ID=" + p.getID_SCHUELER()); if (p.getID_SCHUELER().intValue() == s.getId().intValue()) { Log.d("gefunden!"); Schuljahr sj = em.find(Schuljahr.class, p.getID_SCHULJAHR()); Klasse_all ka = em.find(Klasse_all.class, p.getID_KLASSEN_ALL()); Log.d(" Schler gefunden sj=" + sj.getNAME() + " ka=" + ka.getTitel()); if (oldSchuljahr != sj.getID()) { htmlString.append("<h3>Schuljahr " + sj.getNAME() + "</h3>"); oldSchuljahr = sj.getID(); } htmlString.append("<table>"); htmlString.append("<tr>"); htmlString.append( "<td width=\"70%\"><b>" + ka.getTitel() + "</b><p>" + ka.getNotiz() + "</p></td>"); htmlString.append("<td>" + NotenUtil.getNote(p.getWERT()) + "</td>"); htmlString.append("</tr>"); htmlString.append("</table>"); htmlString.append("<p> </p>"); } } htmlString.append("<br></br>"); htmlString.append("<br></br>"); htmlString.append("<b>Hannover, " + toReadable(schuljahr.get(0).getZEUGNISDATUM()) + "</b>"); htmlString.append("<br></br>"); htmlString.append("<br></br>"); htmlString.append("<br></br>"); htmlString.append("<br></br>"); htmlString.append("<table width=\"100%\" >"); htmlString.append("<tr>"); htmlString.append( "<td style=\"font-size: 10;border-bottom: 0.5px solid #888888\" width=\"40%\" align=\"center\"> </td>"); htmlString.append("<td></td>"); htmlString.append("</tr>"); htmlString.append("<tr>"); htmlString.append( "<td style=\"font-size: 10;\" width=\"40%\" align=\"center\">Klassenlehrerin/Klassenlehrer</td>"); htmlString.append("<td> </td>"); htmlString.append("</tr>"); htmlString.append("<tr>"); htmlString.append( "<td style=\"font-size: 9;border-top: 0.5px solid #888888\" colspan=\"2\">Noten: sehr gut (1), gut (2), befriedigend (3), ausreichend (4), mangelhaft (5), ungengend (6)<br></br>*) Angegeben ist die durchschnittliche Unterrichtsstundenzahl pro Schuljahr.<br></br>*) In Kursen mit insgesamt 12 Unterrichtsstunden findet keine Bewertung statt.</td>"); htmlString.append("</tr>"); htmlString.append("</table>"); InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(480f, 730f); image.scalePercent(40f); Log.d("Image=" + image); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); htmlString = new StringBuilder(); document.newPage(); } document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createVertretungsliste(Date parsedFrom, Date parsedTo, OutputStream out) throws DocumentException, BadElementException, IOException { Document document = new Document(); Log.d("create Vertretungsliste von " + parsedFrom.toString() + " bis" + parsedTo.toString()); GregorianCalendar cf = (GregorianCalendar) GregorianCalendar.getInstance(); cf.setTime(parsedFrom);/*from w w w .j a v a2s .c o m*/ GregorianCalendar ct = (GregorianCalendar) GregorianCalendar.getInstance(); ct.setTime(parsedTo); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); String kopf = ""; kopf += ("<table border='1' align='center' width='100%'>"); kopf += ("<tr>"); kopf += ("<td rowspan=\"3\" width='150px'></td>"); kopf += ("<td align='center'><h2>Multi Media Berufsbildende Schulen Hannover</h2></td>"); kopf += ("<td colspan=\"2\" align='center'><b>Digitales Klassenbuch Vertretungsliste</b></td>"); kopf += ("</tr>"); kopf += ("<tr>"); kopf += ("<td align='center' rowspan=\"2\"><h3>von " + toReadableDate(cf) + " bis " + toReadableDate(ct) + "</h3></td>"); kopf += ("<td style=\"font-size: 11;padding:4px;height:30px;\">Verantwortlicher: BO </td>"); kopf += ("<td style=\"font-size: 11;padding:4px;\">geprft</td>"); kopf += ("</tr>"); kopf += ("<tr>"); DateFormat df = new SimpleDateFormat("dd.MM.yyyy"); Calendar c = df.getCalendar(); c.setTimeInMillis(System.currentTimeMillis()); String dat = c.get(Calendar.DAY_OF_MONTH) + "." + (c.get(Calendar.MONTH) + 1) + "." + c.get(Calendar.YEAR); kopf += ("<td style=\"font-size: 11;\">Ausdruck am: " + dat + "</td>"); kopf += ("<td style=\"font-size: 11;\">Datum</td>"); kopf += ("</tr>"); kopf += ("</table>"); kopf += ("<p> </p>"); htmlString.append(kopf); document.open(); Query qb = em.createNamedQuery("findVertretungbyDate"); qb.setParameter("paramFromDate", parsedFrom); qb.setParameter("paramToDate", parsedTo); List<Vertretung> vl = qb.getResultList(); Log.d("Result Liste = " + vl); for (Vertretung v : vl) { htmlString.append("<h3>Absenz von " + v.getAbsenzVon() + " am " + toReadableFromat(v.getAbsenzAm()) + " eingereicht von " + v.getEingereichtVon() + " am " + toReadableFromat(v.getEingereichtAm()) + "</h3>"); htmlString.append("<h4>" + v.getKommentar() + "</h4>"); htmlString.append("<p> </p>"); htmlString.append("<table border='0.5' align='center' width='100%'>"); htmlString.append("<tr>"); htmlString.append( "<td width='10%' style=\"padding:4px;\">Stunde</td><td width='15%' style=\"padding:4px;\">Klasse</td><td width='15%' style=\"padding:4px;\">Aktion</td><td width='10%' style=\"padding:4px;\">Vertreter</td><td style=\"padding:4px;\">Kommentar</td>"); htmlString.append("</tr>"); JSONParser jsonParser = new JSONParser(); try { JSONArray ja = (JSONArray) jsonParser.parse(v.getJsonString()); for (int i = 0; i < ja.size(); i++) { JSONObject jo = (JSONObject) ja.get(i); htmlString.append("<tr>"); htmlString.append( "<td style=\"font-size: 11;padding:4px;\" width='10%'>" + jo.get("stunde") + "</td>"); htmlString.append( "<td style=\"font-size: 11;padding:4px;\" width='15%'>" + jo.get("Klasse") + "</td>"); htmlString.append( "<td style=\"font-size: 11;padding:4px;\" width='15%'>" + jo.get("Aktion") + "</td>"); htmlString.append("<td style=\"font-size: 11;padding:4px;\" width='10%'>" + jo.get("Vertreter") + "</td>"); htmlString.append("<td style=\"font-size: 11;padding:4px;\">" + jo.get("Kommentar") + "</td>"); htmlString.append("</tr>"); } } catch (org.json.simple.parser.ParseException ex) { ex.printStackTrace(); Logger.getLogger(DokuServlet.class.getName()).log(Level.SEVERE, null, ex); } htmlString.append("</table>"); htmlString.append("<p></p>"); } //document.add(new Paragraph("Tutorial to Generate PDF using Servlet")); InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createVerlauf(Klasse kl, String kopf, Date parsedFrom, Date parsedTo, OutputStream out, String filter1, String filter2, String me) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);//from w w w . j a v a 2 s. c o m /* Verlauf einfgen */ Query query = em.createNamedQuery("findVerlaufbyKlasse"); query.setParameter("paramKName", kl.getKNAME()); query.setParameter("paramFromDate", new java.sql.Date(parsedFrom.getTime())); query.setParameter("paramToDate", new java.sql.Date(parsedTo.getTime())); List<Verlauf> overlauf = query.getResultList(); List<Verlauf> verlauf = new ArrayList<>(); /** * Filtern der oVerlauf Liste */ for (Verlauf v : overlauf) { if (filter1.equals("eigeneEintraege")) { if (v.getID_LEHRER().equals(me)) { if (filter2.equals("alle") || filter2.equals(v.getID_LERNFELD())) { verlauf.add(v); } } } else { if (filter2.equals("alle") || filter2.equals(v.getID_LERNFELD())) { verlauf.add(v); } } } Log.d("Result List:" + verlauf); htmlString.append( "<table align='center' width='100%' style=\"border: 2px solid black; border-collapse: collapse;\">"); String tagZeile = Verlauf.getTRHead(); htmlString.append(tagZeile); String tag = " "; int kw = -1; document.open(); boolean firstPage = true; for (Verlauf v : verlauf) { String str = v.getDATUM().toString(); if (str.compareTo(tag) == 0) { htmlString.append(v.toHTML()); } // ein neuer Tag else { if (kw == -1) { kw = v.getKw(); } // Jede Woche eine neue Seite! if (!firstPage && kw != v.getKw()) { kw = v.getKw(); htmlString.append("</table>"); Log.d("html String=" + htmlString.toString()); //document.add(new Paragraph("Tutorial to Generate PDF using Servlet")); InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.newPage(); htmlString = new StringBuilder(); htmlString.append(kopf); htmlString.append( "<table align='center' width='100%' style=\"border: 2px solid black; border-collapse: collapse;\">"); htmlString.append(tagZeile); Log.d("weiter mit neuer Seite"); } htmlString.append("<tr>"); htmlString.append( "<td colspan=\"6\" align=\"center\" style=\"background-color: #cccccc; padding:4px;border: 1px solid black;\">KW " + v.getKw() + " / " + v.getWochentag() + " " + str.substring(0, str.indexOf(" ")) + "</td>"); htmlString.append("</tr>"); htmlString.append(v.toHTML()); firstPage = false; tag = str; } } htmlString.append("</table>"); Log.d("html String Rest=" + htmlString.toString()); //document.add(new Paragraph("Tutorial to Generate PDF using Servlet")); InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.MailServlet.java
private void createPdf(HttpServletResponse response, String recipient, String content, String klasse, String lehrerId) {/*from w w w . j a v a 2 s . co m*/ OutputStream out = null; try { out = response.getOutputStream(); Log.d("Mail versandt erfolgreich erzeuge pdf Dokumentation! out=" + out); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=Fehlzeitenbericht_" + recipient + ".pdf"); String kopf = ""; kopf += ("<table border='1' align='center' width='100%'>"); kopf += ("<tr>"); kopf += ("<td rowspan=\"3\" width='150px'></td>"); kopf += ("<td align='center'><h2>Multi Media Berufsbildende Schulen Hannover</h2></td>"); kopf += ("<td colspan=\"2\" align='center'><b>Digitales Klassenbuch Fehlzeitenbericht</b></td>"); kopf += ("</tr>"); kopf += ("<tr>"); kopf += ("<td align='center' rowspan=\"2\"><h3>Klasse/ Kurs: " + klasse + "</h3></td>"); kopf += ("<td style=\"font-size: 11;\">Verantwortlicher: " + lehrerId + "</td>"); kopf += ("<td style=\"font-size: 11;\">geprft</td>"); kopf += ("</tr>"); kopf += ("<tr>"); DateFormat df = new SimpleDateFormat("dd.MM.yyyy"); Calendar c = df.getCalendar(); c.setTimeInMillis(System.currentTimeMillis()); String dat = c.get(Calendar.DAY_OF_MONTH) + "." + (c.get(Calendar.MONTH) + 1) + "." + c.get(Calendar.YEAR); kopf += ("<td style=\"font-size: 11;\">Ausdruck am: " + dat + "</td>"); kopf += ("<td style=\"font-size: 11;\">Datum</td>"); kopf += ("</tr>"); kopf += ("</table>"); kopf += ("<p> </p>"); Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf); String body = ""; body += "<table align='center' width='100%'>"; body += "<tr><td><h3 align=\"center\">Empfnger:" + recipient + "</h3></td></tr>"; Log.d("Content=" + StringUtil.addBR(content)); body += "<tr><td style=\"font-size: 12;\">" + StringUtil.addBR(content) + "</td></tr>"; body += "</table>"; htmlString.append(body); document.open(); // Dokument erzeugen InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image; try { image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); if (image != null) { document.add(image); } } catch (BadElementException ex) { Logger.getLogger(MailServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MailServlet.class.getName()).log(Level.SEVERE, null, ex); } XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); out.close(); } catch (IOException ex) { Logger.getLogger(MailServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(MailServlet.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (out != null) { out.close(); } } catch (IOException ex) { Logger.getLogger(MailServlet.class.getName()).log(Level.SEVERE, null, ex); } } }