List of usage examples for com.itextpdf.text Image getInstance
public static Image getInstance(final Image image)
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 w w. ja v a2 s .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 ww .j a va 2 s . co 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();/*from w w w .j a v a 2s. c om*/ 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);//w ww .j a v a2 s .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 ww . ja va2s. 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. ja 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); } } }
From source file:digilib.pdf.PDFTitlePage.java
License:Open Source License
private Image getLogo() { try {// ww w . ja v a2 s .c om URL url = new URL(job_info.getDlConfig().getAsString("pdf-logo")); if (url != null && !url.equals("")) { Image logo = Image.getInstance(url); logo.setAlignment(Element.ALIGN_CENTER); return logo; } } catch (BadElementException e) { logger.error(e.getMessage()); } catch (MalformedURLException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } return null; }
From source file:documentos.PlanillaServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* www . ja v a 2 s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { response.setContentType("application/pdf"); Connection conexion = null; HttpSession session = request.getSession(true); try { conexion = ds.getConnection(); edificioDAO edifDAO = new edificioDAO(); edifDAO.setConexion(conexion); usuarioDAO usuDAO = new usuarioDAO(); usuDAO.setConexion(conexion); //obtener variable boolean error = false; String idString = (String) request.getParameter("id_edificio"); int idEdificio = 0; try { idEdificio = Integer.parseInt(idString); } catch (Exception ex) { System.out.println("Error al convertir variables :" + ex); error = true; } //obtener datos de edificio segun el id edificio edif = new edificio(); edif = edifDAO.findbyIdEdificio(idEdificio); DetalleEdificioDAO detEdifDAO = new DetalleEdificioDAO(); detEdifDAO.setConexion(conexion); administradorDAO adminDAO = new administradorDAO(); adminDAO.setConexion(conexion); //obtener admin Edificio administrador admin = new administrador(); admin = adminDAO.findbyIdEdificio(idEdificio); //obtener datos de detalleEdif detalleEdificio detalleEdif = new detalleEdificio(); detalleEdif = detEdifDAO.findbyIdEdificio(idEdificio); //obtener datos de usuario segun id edificio usuario usuario = new usuario(); usuario = usuDAO.findbyIdUsuarios(edif.getIdUsuario()); //guardar datos de edif en variables separadas String nombreVendedor = usuario.getNombre(); String apellidoVendedor = usuario.getApellido(); int annoNorma = edif.getAnoEdificio(); String ubicacionMed = detalleEdif.getUbicacionMedidores(); String ciige = detalleEdif.getCiigeAnterior(); String testDePruebas = detalleEdif.getDespiche(); String nombreEdif = edif.getNombreEdificio(); String correo = admin.getEmailAdmin(); String fonoAdmin = admin.getTelefonoAdmin(); String fonoEdif = edif.getTelefonoEdificio(); String rutEdif = edif.getRutEdificio(); String dirEdif = edif.getDireccionEdificio(); String nomAdmin = admin.getNombreAdmin(); String rutAdmin = admin.getRutAdmin(); int cantidadDe = edif.getCantCasas() + edif.getCantDepartamentos() + edif.getCantLocales() + edif.getCantLavanderias(); int cantPisos = edif.getCantPisos(); int idEmpresaGas = edif.getIdGas(); //determinar el nombre de la empresa de gas segun su id String empresagas = ""; if (idEmpresaGas == 1) { empresagas = "GASVALPO"; } if (idEmpresaGas == 2) { empresagas = "LIPIGAS"; } if (idEmpresaGas == 3) { empresagas = "ABASTIBLE"; } if (idEmpresaGas == 4) { empresagas = "GASCO"; } if (idEmpresaGas == 5) { empresagas = "OTROS"; } int annoEdif = edif.getAnoEdificio(); int potencia = edif.getPotenciaReal(); int cantidaConductos = edif.getCantConductos(); int cantidadCalderas = edif.getCantCalderas(); //Crear documento Document document = new Document(); Image logo = Image.getInstance(getClass().getResource("logo.png")); PdfWriter.getInstance(document, response.getOutputStream()); Font fuenteNegrita = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD); Font fuenteNormal = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL); Font fuenteEPiePagina = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.BOLD); Font fuentePiePagina = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD); // step 3 document.open(); // step 4 logo.setAbsolutePosition(270f, 750f); logo.scalePercent(65f); PdfPTable tablaEncabezado = new PdfPTable(2); PdfPTable tablaContenido = new PdfPTable(2); tablaEncabezado.addCell(new Paragraph("PLANILLA CIIG-e INSPECCIN PERIODICA")); tablaEncabezado.addCell(logo); tablaContenido.setSpacingBefore(15); tablaContenido.setSpacingAfter(20); tablaContenido.addCell(new Paragraph("VENDEDORA", fuenteNormal)); tablaContenido.addCell(new Paragraph(nombreVendedor + " " + apellidoVendedor, fuenteNormal)); tablaContenido.addCell(new Paragraph("AO DEL EDIFICIO Y NORMA APLICAR", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(annoEdif), fuenteNormal)); tablaContenido .addCell(new Paragraph("UBICACIN MEDIDORES: EN LOS PISOS, FUERA DEL EDIFICO", fuenteNormal)); tablaContenido.addCell(new Paragraph(ubicacionMed, fuenteNormal)); tablaContenido .addCell(new Paragraph("NRO CIIGE DE LA INSPECCION ANTERIOR (VER PAGINA SEC)", fuenteNormal)); tablaContenido.addCell(new Paragraph(ciige, fuenteNormal)); tablaContenido.addCell(new Paragraph("T DE PRUEBAS, DESPICHE OTRO (COCINA)", fuenteNormal)); tablaContenido.addCell(new Paragraph(testDePruebas, fuenteNormal)); tablaContenido.addCell(new Paragraph("NOMBRE: EDIFICIO, CONDOMINIO, PROPIETARIO, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(nombreEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("CORREO ELECTRONICO", fuenteNormal)); tablaContenido.addCell(new Paragraph(correo, fuenteNormal)); tablaContenido.addCell(new Paragraph("FONO ADMINISTRADOR /FONO EDIFICIO", fuenteNormal)); tablaContenido.addCell(new Paragraph("Fono Administrador :" + fonoAdmin + " Fono Edificio :" + fonoEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("R.U.T EDIFICIO, CONDOMINIO, PROPIETARIOS, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(rutEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("DIRECCIN DEL EDIFICO", fuenteNormal)); tablaContenido.addCell(new Paragraph(dirEdif, fuenteNormal)); tablaContenido.addCell(new Paragraph("NOMBRE ADMINISTRADOR, PROPIETARIO, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(nomAdmin, fuenteNormal)); tablaContenido.addCell(new Paragraph("RUT: ADMINISTRADOR, PROPIETARIO, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(rutAdmin, fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE: DEPTOS, CASAS, LOCALES, ETC.", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidadDe), fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE PISOS INMUEBLE", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantPisos), fuenteNormal)); tablaContenido.addCell(new Paragraph("EMPRESA DISTRIBUIDORA DE GAS", fuenteNormal)); tablaContenido.addCell(new Paragraph(empresagas, fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE INSTALACIONES", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidadDe), fuenteNormal)); tablaContenido.addCell(new Paragraph("TIPO DE ARTEFACTOS INSTALADOS", fuenteNormal)); tablaContenido.addCell(new Paragraph("", fuenteNormal)); tablaContenido.addCell(new Paragraph("POTENCIA TOTAL INSTALADA", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(potencia), fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE CONDUCTOS COLECTIVOS", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidaConductos), fuenteNormal)); tablaContenido.addCell(new Paragraph("CANTIDAD DE CALDERAS CENTRALES", fuenteNormal)); tablaContenido.addCell(new Paragraph(Integer.toString(cantidadCalderas), fuenteNormal)); document.add(tablaEncabezado); document.add(tablaContenido); Paragraph textoIng = new Paragraph("IngeneriaRSLimitada", fuenteEPiePagina); textoIng.setAlignment(Element.ALIGN_CENTER); Paragraph textPie = new Paragraph( "Calle Montaa 754 Oficina 37-A Via Del Mar / ingenieria.sr@gmail.com - Fono 032-2697175 / 92564059", fuentePiePagina); textPie.setAlignment(Element.ALIGN_CENTER); document.add(textoIng); document.add(textPie); document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } }
From source file:Documentos.ReportesPDF.java
private void agregarContenido(Document document) { Paragraph ParrafoHoja = new Paragraph(); // AGREGAMOS LA IMAGEN try {//from www .j a va 2s . c o m Image foto = Image.getInstance(getClass().getResource("/Image/logoAnaIS_1.png")); foto.scaleToFit(40, 40); ParrafoHoja.add(foto); } catch (BadElementException | IOException e) { e.getMessage(); } //Agregar lineas en blanco agregarLineasEnBlanco(ParrafoHoja, 1); agregarTabla(ParrafoHoja); try { document.add(ParrafoHoja); } catch (DocumentException ex) { Logger.getLogger(ReportesPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:domain.Pdfmaker.java
public void makePdf() { Document doc = new Document(); doc.setPageSize(PageSize.A4);//from w w w.j av a 2s. co m try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(test.getTitle() + ".pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_7); doc.open(); Font f = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD, new BaseColor(0, 0, 0)); Paragraph title = new Paragraph("TEST TITLE", f); title.setAlignment(Element.ALIGN_CENTER); doc.addCreator("Arne De Bremme"); //make table PdfPTable table = new PdfPTable(4); table.setTotalWidth(550f); table.setLockedWidth(true); table.setHeaderRows(1); Paragraph p = new Paragraph(test.getTitle()); p.setAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(p); cell.setGrayFill(0.7f); cell.setColspan(4); table.addCell(cell); table.addCell(test.getClassGroup().getGroupName()); PdfPCell cell2 = new PdfPCell(new Paragraph(test.getDescription())); cell2.setColspan(2); cell2.setRowspan(2); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Paragraph("DD " + test.getStartDate().getDay() + "/" + test.getStartDate().getMonth() + "/" + test.getStartDate().getYear())); cell3.setRowspan(2); table.addCell(cell3); table.addCell(new Paragraph("Test " + test.getTestId())); doc.add(table); doc.add(Chunk.NEWLINE); for (Exercise e : ex) { Paragraph par = new Paragraph(); par.add("Vraag " + counter); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(e.getPunten() + "/"); doc.add(par); doc.add(new Paragraph("Klimatogram " + e.getClimateChart().getLocation() + " " + e.getPunten())); Robot r = new Robot(); Desktop.getDesktop().browse(new URI( "http://climatechart.azurewebsites.net/ClimateChart/ShowExercises?selectedYear=1&continentId=" + e.getClimateChart().getCountry().getContinent().getId() + "&countryId=" + e.getClimateChart().getCountry().getContinent().getId() + "&climateId=" + e.getClimateChart().getId())); TimeUnit.SECONDS.sleep(6); BufferedImage bi = r.createScreenCapture( new Rectangle(Toolkit.getDefaultToolkit().getScreenSize().width * 7 / 10, Toolkit.getDefaultToolkit().getScreenSize().width * 8 / 14)); File file = new File("screenCapture" + counter + ".jpg"); ImageIO.write(bi, "jpg", file); Image img = Image.getInstance("screenCapture.jpg"); img.scaleAbsolute(400, 300); doc.add(img); doc.add(Chunk.NEWLINE); doc.add(new Paragraph(e.getNaam())); doc.add(Chunk.NEXTPAGE); counter++; } doc.close(); File filz = new File(test.getTitle() + ".pdf"); Desktop.getDesktop().open(filz); } catch (Exception e) { } }