List of usage examples for com.itextpdf.text Image setAbsolutePosition
public void setAbsolutePosition(final float absoluteX, final float absoluteY)
Image
. 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();/*w ww.j av a 2s. c o 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);//ww w . ja va 2s .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);/* w ww . 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) {// ww w .jav 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:documentos.PlanillaServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j a va2 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, 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:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java
License:Open Source License
private void createImage(Document document, PdfWriter writer, Font featureHeaderStyle) throws BadElementException, MalformedURLException, IOException, DocumentException { Image imageSprite = Image.getInstance(new URL( "http://lh3.ggpht.com/_4msVPAgKJv8/SCRYD-pPVKI/AAAAAAAAAYU/zUN963EPoZc/s1024/102_0609.JPG")); imageSprite.setAbsolutePosition(400, 500); imageSprite.scaleAbsolute(171.0f, 250.0f); float imageSpriteY = document.getPageSize().getHeight() * 0.60f; float imageSpriteX = document.getPageSize().getWidth() * 0.65f; imageSprite.setAlignment(Image.UNDERLYING); document.add(imageSprite);//from w ww .j a v a 2s .c om PdfContentByte cb = writer.getDirectContent(); ColumnText ct = new ColumnText(cb); Chunk imageHeader = new Chunk("Images", featureHeaderStyle); ct.addText(imageHeader); ct.setAlignment(Element.ALIGN_LEFT); ct.setSimpleColumn(imageSpriteX, imageSpriteY - imageSprite.getScaledHeight(), imageSpriteX + imageSprite.getScaledWidth(), imageSpriteY + imageSprite.getScaledHeight() + 20); ct.go(); ct = new ColumnText(cb); Chunk imageFooter = new Chunk("Footer to be set for a figure. Similar to 'image cpation'.", FontFactory.getFont(FontFactory.TIMES_ROMAN, 8)); ct.addText(imageFooter); ct.setAlignment(Element.ALIGN_CENTER); ct.setSimpleColumn(imageSpriteX, imageSpriteY - 150, imageSpriteX + imageSprite.getScaledWidth(), imageSpriteY); ct.go(); }
From source file:emailworkshop.EmailWorkshop.java
public static void gerarPDF(String nome, int numCert) { Calendar data = Calendar.getInstance(); // criao do objeto documento Document document = new Document() { };/*from w w w. ja v a 2 s .c o m*/ document.setPageSize(new Rectangle(800, 500)); try { PdfWriter.getInstance(document, new FileOutputStream("Certificado.pdf")); document.open(); // adicionando um pargrafo ao documento Image img = Image.getInstance("logo.png"); img.scaleAbsoluteWidth(620); img.scaleAbsoluteHeight(130); Paragraph texto1 = new Paragraph("\n Conferimos o presente Certificado a " + nome + " por ter " + "participado do II Workshop de Inovao, com durao de 4 horas. Onde foram apresentadas as palestras: "); Paragraph texto2 = new Paragraph( "Economia compartilha & Inovao Disruptiva - Arthur Schuler da Igreja.\n" + "Empreendedorismo: Um case de sucesso - Cludio Kopp."); Paragraph texto3 = new Paragraph( "\n\n\n\n\nRegistrado na UFPR Setor Palotina Livro 4 certificado Nr " + numCert + "."); Paragraph localData = new Paragraph("\nPalotina, " + new SimpleDateFormat("dd").format(data.getTime()) + " de " + new SimpleDateFormat("MMMM").format(data.getTime()) + " de " + new SimpleDateFormat("yyyy").format(data.getTime()) + ".\n\n"); texto1.setAlignment("center"); texto2.setAlignment("center"); texto3.setAlignment("right"); localData.setAlignment("center"); Image assinatura = Image.getInstance("assinatura.png"); assinatura.scaleAbsoluteHeight(75); assinatura.scaleAbsoluteWidth(250); assinatura.setAbsolutePosition(275, 110); document.add(img); document.add(texto1); document.add(texto2); document.add(localData); document.add(assinatura); document.add(texto3); document.close(); } catch (DocumentException | IOException de) { System.err.println(de.getMessage()); } }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
public String insertStamp(String loc, float x, float y, int width, int height, int set, String date, int pageNum, int masterHeight, int masterWidth, String projNo) throws BadElementException, MalformedURLException, IOException, DocumentException { Image image = Image.getInstance(loc); float[] scalar = scale(x, y, width, height, masterHeight, masterWidth, pageNum); float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight, masterWidth, pageNum);/*w w w . ja v a 2s .c om*/ float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum); float shift = 0; /* Addition. ftorres - 7/22/2015 - Added to account for rotated pages * with the origin (0,0) not set to the bottom-left of the page. [1400] */ trans = translateRotation(trans[0], trans[1], pageNum); if (set == 1) { float m = image.getPlainHeight(); float pageChunk = r[pageNum - 1].getHeight() / 10; shift = r[pageNum - 1].getHeight() / 100; scalar[1] = (int) (pageChunk); scalar[0] = (int) (image.getPlainWidth() * pageChunk) / image.getPlainHeight(); trans[0] = (int) (0 + (pageChunk * widthScalar)); trans[1] = (int) (r[pageNum - 1].getHeight() - (pageChunk * heightScalar) - (shift * (heightScalar + 2))); heightScalar = heightScalar + 1; if (heightScalar == 8) { heightScalar = 0; widthScalar = widthScalar + 2; } } if (set == 1) { image.setAbsolutePosition(trans[0] + shift, trans[1] - scalar[1]); image.scaleAbsoluteHeight(scalar[1]); image.scaleAbsoluteWidth(scalar[0]); image.setRotationDegrees(rot); } else { //swap stamp dimensions for rotated drawings if (rot > 0) { image.setAbsolutePosition(trans[0] - 2 * scalar[1], trans[1] - 2 * scalar[0]); } else { image.setAbsolutePosition(trans[0], trans[1] - 2 * scalar[1]); } image.scaleAbsoluteHeight(scalar[1] * 2); image.scaleAbsoluteWidth(scalar[0] * 2); image.setRotationDegrees(rot); } PdfContentByte fg = pds.getOverContent(pageNum); fg.addImage(image); //Added by tmittelstadt on 09/21/2012 for ticket #698 //draws a box around the date fg.setColorFill(BaseColor.WHITE); fg.setLineWidth(0f); //dmoody removed box. ticket 900 /*fg.moveTo(trans[0], trans[1] - scalar[1] * 2); fg.lineTo(trans[0], trans[1] - scalar[1] * 2 - 10); fg.lineTo(trans[0] + scalar[0] * 2, trans[1] - scalar[1] * 2 - 10); fg.lineTo(trans[0] + scalar[0] * 2, trans[1] - scalar[1] * 2); fg.lineTo(trans[0], trans[1] - scalar[1] * 2);*/ fg.closePathFillStroke(); fg.fill(); //adds the date the stamp was added to the document to the pdf Phrase p = new Phrase(date); p.getFont().setColor(BaseColor.BLACK); //Modification zreeve 10/11/2012. set font size to 11. p.getFont().setSize(9f); //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id)); ColumnText.showTextAligned(fg, Element.ALIGN_CENTER, p, (float) (trans[0]), (float) (trans[1] - scalar[1] * 2 - 12), 0); Phrase pn = new Phrase("#[" + projNo + "]"); pn.getFont().setColor(BaseColor.BLACK); pn.getFont().setSize(10f); pn.getFont().setStyle("bold"); ColumnText.showTextAligned(fg, Element.ALIGN_CENTER, pn, (float) (trans[0]), (float) (trans[1] - scalar[1] * 2 - 22), 0); return ""; }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
public String insertComment(String sx, String sy, String id, String deptValue, String userInit, String comment, int pageNum, int masterHeight, int masterWidth, int pinned, int customFontSize) throws DocumentException, IOException { float ratio = getRatio(masterHeight, masterWidth, pageNum); float x = Float.parseFloat(sx); float y = Float.parseFloat(sy); float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum); PdfGState gs1 = new PdfGState(); gs1.setFillOpacity(1);//w ww.ja v a2 s .c o m if (customFontSize > 0) fontSize = customFontSize; PdfContentByte fg = pds.getOverContent(pageNum); fg.setGState(gs1); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight, masterWidth, pageNum); // comment tag image (width=35pts, height=8pts) float[] scalar = scale(trans[0], trans[1], 35, 8, masterHeight, masterWidth, pageNum); /* Addition. ftorres - 7/21/2015 - Added to account for rotated pages * with the origin (0,0) not set to the bottom-left of the page. [1400] */ float coords[] = translateRotation(trans[0], trans[1], pageNum); coords = checkBounds(coords[0], coords[1], pageNum); /* Addition. ftorres - 10/20/2015 - If the comment was pinned in EPC, then * render the comment inside a comment box. */ if (pinned == 1) { insertPinnedComment(coords[0], coords[1], id + " - " + deptValue + " (" + userInit + ")", comment, pageNum, masterHeight, masterWidth); // Add the pinned comment text to page annotation -Jon Changkachith 11/24/2015 Rectangle rect = new Rectangle(0, 0, 0, 0); PdfAnnotation annotation = PdfAnnotation.createText(pds.getWriter(), rect, id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), true, id); pds.addAnnotation(annotation, pds.getWriter().getCurrentPageNumber()); } else { Image image = Image.getInstance(commentIMGPath); image.setAbsolutePosition(coords[0] + (scalar[0] * (id.length() / 5f)), coords[1]); /* * Commented out by Jon Changkachith 12/09/2015 because it was throwing * DocumentException with the message "The image must have absolute positioning." image.scaleAbsoluteHeight(1); image.scaleAbsoluteWidth(1); */ image.scalePercent(ratio); //Added to fix DocumentException "The image must have absolute positioning." Jon Changkachith 12/09/2015 image.setAnnotation(new Annotation(id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), 0, 0, 0, 0)); fg.addImage(image); } fg.setLineWidth(.5f * ratio); fg.setColorStroke(new BaseColor(Color.decode("0x6E2405").getRGB())); fg.setColorFill(new BaseColor(Color.decode("0x6E2405").getRGB())); float tHeight = scalar[1]; float tWidth = 0; if (id.length() > 3) { tWidth = (scalar[0] * (id.length() / 5f)); } else { tWidth = (scalar[0]); } fg.moveTo(coords[0], coords[1]); fg.lineTo(coords[0] + (10f * ratio), coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] + (tHeight / 2)); fg.lineTo(coords[0] + (10f * ratio), coords[1] + (tHeight / 2)); fg.lineTo(coords[0], coords[1]); fg.closePathFillStroke(); fg.fill(); // Comment number that goes on the comment tag image Phrase p = new Phrase(id); p.getFont().setColor(BaseColor.WHITE); p.getFont().setSize(8f * ratio); //comment number font size = 8f //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id)); float fs[] = translateRotation(f[0], f[1], pageNum); fs = checkBounds(fs[0], fs[1], pageNum); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, p, (float) (fs[0] + (9 * ratio)), (float) (fs[1] - (3 * ratio)), 0); return ""; }
From source file:es.clinica.veterinaria.facturas.FacturaPdf.java
private void addLogo(Document doc) throws DocumentException, Exception { try {/* www . j av a 2 s . c o m*/ String logo = Executions.getCurrent().getDesktop().getWebApp().getRealPath("logo.png"); Image companyLogo = Image.getInstance(logo); companyLogo.setAbsolutePosition(35, 700); companyLogo.scalePercent(20); doc.add(companyLogo); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }