List of usage examples for com.itextpdf.layout.element Paragraph Paragraph
public Paragraph(Text text)
From source file:AAMAirline.service.PdfServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RuntimeTypeAdapterFactory<Jsonable> rta = RuntimeTypeAdapterFactory.of(Jsonable.class, "_class") .registerSubtype(Ciudad.class, "Ciudad").registerSubtype(Tiquete.class, "Tiquete") .registerSubtype(Ruta.class, "Ruta").registerSubtype(Avion.class, "Avion") .registerSubtype(Usuario.class, "Usuario").registerSubtype(Asiento.class, "Asiento") .registerSubtype(Vuelo.class, "Vuelo"); response.setContentType("aplication/pdf"); response.setHeader("Content-Disposition", "inline;filename=\"report.pdf\""); PdfDocument pdf = new PdfDocument(new PdfWriter(response.getOutputStream())); Gson gson = new GsonBuilder().registerTypeAdapterFactory(rta).setDateFormat("dd/MM/yyyy").create(); String json;/* w ww .j av a 2s. c om*/ try (Document document = new Document(pdf)) { Paragraph p; p = new Paragraph("TIQUETE DE VUELO"); p.setTextAlignment(TextAlignment.CENTER); p.setBold(); p.setBackgroundColor(Color.PINK); document.add(p); String h = "Vuelo %s, %s - %s, %s %s %s"; String codigo_tiquete = request.getParameter("tiquete"); Tiquete ticket = AAMAirlineModel.consultaTiquete(codigo_tiquete); ArrayList<String> asientosIda = AAMAirlineModel.getAsientosPDF(ticket.getCodigo_Tiquete(), ticket.getVueloida().getAvion().getCodigo_Avion()); ArrayList asientosVuelta; String asientos = ""; String horaVuelta = ""; Float precio = (ticket.getVueloida().getPrecio()) * (asientosIda.size()); if (ticket.getVueloVuelta() != null) { asientosVuelta = AAMAirlineModel.getAsientosPDF(ticket.getCodigo_Tiquete(), ticket.getVueloVuelta().getAvion().getCodigo_Avion()); horaVuelta = " / salida vuelo Vuelta " + ticket.getVueloVuelta().getHora_salida() + " horas "; asientos = asientos + "Vuelta \n"; for (int i = 0; i < asientosVuelta.size(); i++) { asientos = asientos + asientosVuelta.get(i) + "\n"; } precio += (ticket.getVueloVuelta().getPrecio() * asientosVuelta.size()); } String horaida = ticket.getVueloida().getHora_salida(); String algo = " horas "; h = String.format(h, ticket.getVueloida().getCodigo_Vuelo(), ticket.getVueloida().getRuta().getCiudadO().getNombre(), ticket.getVueloida().getRuta().getCiudadD().getNombre(), ticket.getVueloida().getDia_salida(), " salida vuelo ida :" + horaida + algo, horaVuelta); p = new Paragraph(h); p.setTextAlignment(TextAlignment.LEFT); p.setBold(); document.add(p); for (int i = 0; i < asientosIda.size(); i++) { asientos = asientos + "Ida: \n"; asientos = asientos + asientosIda.get(i) + "\n"; } p = new Paragraph("------------- Asientos ------------- \n" + asientos); document.add(p); p = new Paragraph("COSTO TOTAL: $ " + precio); p.setTextAlignment(TextAlignment.RIGHT); p.setBold(); p.setBackgroundColor(Color.PINK); document.add(p); } catch (SQLException ex) { Logger.getLogger(PdfServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Accessor.MyPdfWriter.java
static <T extends Object & Serializable> void write(PdfAccessor pdfAccessor, T element) { try {/*w w w . j a va2s . c o m*/ String DEST = pdfAccessor.getPath(); LOGGER.info("Writing pdf to: " + DEST); File file = new File(DEST); file.getParentFile().mkdirs(); if (element.getClass().equals(NewStudent.class)) { //PdfFont textFont = PdfFontFactory.createFont(FONT, PdfEncodings.IDENTITY_H, true); NewStudent student = (NewStudent) element; //Initialize PDF writer PdfWriter writer = new PdfWriter(DEST); //Initialize PDF document PdfDocument pdf = new PdfDocument(writer); // Initialize document Document document = new Document(pdf); //Add paragraph to the document //Creating header document.add(new Paragraph("Anno scolastico: " + NewStudentWizBean.getSchoolYear()) .setTextAlignment(TextAlignment.CENTER)); document.add(new Paragraph("SCHEDA D'ISCRIZIONE").setBold().setFontSize(18) .setTextAlignment(TextAlignment.CENTER)); //Creating Body pt 1 document.add(new Paragraph("\nDati Personali").setBold()); document.add(new Paragraph(student.toDatiPersonali())); document.add(new Paragraph("\nContatti").setBold()); document.add(new Paragraph(student.toContatti())); //Creating Body pt 2 document.add(new Paragraph("Ambito di interesse").setBold()); document.add(new Paragraph("Corso di italiano" + "\n [ ] 10.00 - 11.30 [ ] 18.00 - 19.30 [ ] 19.30 21.00" + "\nCorso di informatica [ ]" + "\nCertificazione A2 [ ]")); //Creating Tail document.add(new Paragraph("\n\nFirma studente: _______________________") .setTextAlignment(TextAlignment.RIGHT)); document.add(new Paragraph( "Il sottoscritto autorizza al trattamento dei dati personali, secondo quanto previsto dal Decreto legislativo 30 giugno 2003, n. 196.") .setTextAlignment(TextAlignment.RIGHT).setFontSize(9).setItalic()); document.add(new Paragraph(student.toInfo()).setTextAlignment(TextAlignment.RIGHT)); document.add(new Paragraph("\n\nTest d'ingresso:").setBold()); document.add(new Paragraph("Esito: _______________________")); document.add(new Paragraph("Data: _______________________")); //Close document document.close(); } else { LOGGER.info("Unsupported element class : " + element.getClass()); } } catch (Exception e) { LOGGER.info("Exception writing pdf : " + e.getMessage()); } }
From source file:cl.a2r.wsmicampov2.dao.TrasladoDAO.java
public static void addSpaces(Document document) { for (int i = 0; i < 20; i++) { document.add(new Paragraph(" ")); }/*from ww w . ja va 2s. c om*/ }
From source file:cl.a2r.wsmicampov2.pdf.CellHelper.java
public static Cell getCellObservaciones(String text, TextAlignment alignment) { Cell cell = new Cell().add(new Paragraph(text)); cell.setPadding(0);/*from w w w.j av a 2s . co m*/ cell.setTextAlignment(alignment); cell.setHeight(130); return cell; }
From source file:cl.a2r.wsmicampov2.pdf.CellHelper.java
public static Cell getCellFirma(String text, TextAlignment alignment) { Cell cell = new Cell().add(new Paragraph(text)); cell.setPadding(0);/*from w w w . jav a 2s . c o m*/ cell.setTextAlignment(alignment); cell.setHeight(100); cell.setBorder(Border.NO_BORDER); cell.setBold(); ILineDash solid = new Solid(); cell.setNextRenderer(new CustomBorder3Renderer(cell, new ILineDash[] { solid, null, null, null })); return cell; }
From source file:cl.a2r.wsmicampov2.pdf.CellHelper.java
public static Cell getCell(String text, TextAlignment alignment) { Cell cell = new Cell().add(new Paragraph(text)); cell.setPadding(0);//w ww. j a va2 s. co m cell.setTextAlignment(alignment); cell.setBorder(Border.NO_BORDER); return cell; }
From source file:cl.a2r.wsmicampov2.pdf.CellHelper.java
public static Cell getCellDiios(String text, TextAlignment alignment) { Cell cell = new Cell().add(new Paragraph(text)); cell.setPadding(0);/*from ww w. jav a 2 s . c o m*/ cell.setTextAlignment(alignment); cell.setHeight(20); cell.setBorder(Border.NO_BORDER); return cell; }
From source file:com.asptt.plongee.resa.util.UtilsFSpdf.java
private void createTablePlongeur(Table tablePalanques, FicheSecurite fs, int i, Style s_plongeur) { float[] colWidths = { 25, 25, 25, 25 }; Table tablePlongeurs = new Table(colWidths); tablePlongeurs.setMarginTop(0);//from w ww .ja v a 2 s .co m tablePlongeurs.setMarginBottom(0); tablePlongeurs.setWidthPercent(100); // first row Cell cellNom = new Cell(1, 3).add(new Paragraph("Nom")); cellNom.setTextAlignment(TextAlignment.CENTER); cellNom.setFontSize(12); cellNom.setPadding(5); cellNom.setBackgroundColor(new DeviceRgb(140, 221, 8)); tablePlongeurs.addCell(cellNom); Cell cellApt = new Cell(1, 1).add(new Paragraph("Apt")); cellApt.setTextAlignment(TextAlignment.CENTER); cellApt.setFontSize(12); cellApt.setPadding(5); cellApt.setBackgroundColor(new DeviceRgb(140, 221, 8)); tablePlongeurs.addCell(cellApt); if (fs.getPalanques().size() > i) { initTablePlongeur(fs.getPalanques().get(i), tablePlongeurs, s_plongeur); } else { initTablePlongeur(null, tablePlongeurs, s_plongeur); } tablePalanques.addCell(tablePlongeurs); }
From source file:com.asptt.plongee.resa.util.UtilsFSpdf.java
public void createPdf(String dest, FicheSecurite fs) throws IOException, FileNotFoundException, java.io.IOException { //Initialize PDF writer PdfWriter writer = new PdfWriter(dest); //Initialize PDF document PdfDocument pdf = new PdfDocument(writer); // Initialize document Document document = new Document(pdf); //Add paragraph to the document document.add(new Paragraph(fs.getSite())); // Add content Text title1 = new Text("The Strange Case of ").setFontColor(Color.BLUE); Text title2 = new Text("Dr. Jekyll SIIMMOONN").setStrokeColor(Color.GREEN) .setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE); Text title3 = new Text(" and "); Text title4 = new Text("Mr. Hyde").setStrokeColor(Color.RED).setStrokeWidth(0.5f) .setTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE); Paragraph p = new Paragraph().setFontSize(24).add(title1).add(title2).add(title3).add(title4); document.add(p);//from w w w .j a v a2 s . c o m Style normal = new Style(); PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN); normal.setFont(font).setFontSize(14); Style code = new Style(); PdfFont monospace = PdfFontFactory.createFont(FontConstants.COURIER); code.setFont(monospace).setFontColor(Color.RED).setBackgroundColor(Color.LIGHT_GRAY); Paragraph p2 = new Paragraph(); p2.add(new Text("The Strange Case of ").addStyle(normal)); p2.add(new Text("Dr. Jekyll").addStyle(code)); p2.add(new Text(" and ").addStyle(normal)); p2.add(new Text("Mr. Hyde").addStyle(code)); p2.add(new Text(".").addStyle(normal)); document.add(p2); //Close document document.close(); // PageSize ps = PageSize.A4.rotate(); // PdfPage page = pdf.addNewPage(ps); // PdfCanvas canvas = new PdfCanvas(page); // canvas.concatMatrix(1, 0, 0, 1, ps.getWidth() / 2, ps.getHeight() / 2); ////Draw X axis // canvas.moveTo(-(ps.getWidth() / 2 - 15), 0) // .lineTo(ps.getWidth() / 2 - 15, 0) // .stroke(); ////Draw X axis arrow // canvas.setLineJoinStyle(PdfCanvasConstants.LineJoinStyle.ROUND) // .moveTo(ps.getWidth() / 2 - 25, -10) // .lineTo(ps.getWidth() / 2 - 15, 0) // .lineTo(ps.getWidth() / 2 - 25, 10).stroke() // .setLineJoinStyle(PdfCanvasConstants.LineJoinStyle.MITER); ////Draw Y axis // canvas.moveTo(0, -(ps.getHeight() / 2 - 15)) // .lineTo(0, ps.getHeight() / 2 - 15) // .stroke(); ////Draw Y axis arrow // canvas.saveState() // .setLineJoinStyle(PdfCanvasConstants.LineJoinStyle.ROUND) // .moveTo(-10, ps.getHeight() / 2 - 25) // .lineTo(0, ps.getHeight() / 2 - 15) // .lineTo(10, ps.getHeight() / 2 - 25).stroke() // .restoreState(); ////Draw X serif // for (int i = -((int) ps.getWidth() / 2 - 61); // i < ((int) ps.getWidth() / 2 - 60); i += 40) { // canvas.moveTo(i, 5).lineTo(i, -5); // } ////Draw Y serif // for (int j = -((int) ps.getHeight() / 2 - 57); // j < ((int) ps.getHeight() / 2 - 56); j += 40) { // canvas.moveTo(5, j).lineTo(-5, j); // } // canvas.stroke(); //// pdf.close(); //// PdfPage page = pdf.addNewPage(); //// Rectangle rectangle = new Rectangle(x, y, 100, 100); //// Canvas canvas = new Canvas(pdfCanvas, pdf, rectangle); // float llx = 0; // float lly = 0; // float urx = 100; // float ury = 100; // for (Palanque palanque : fs.getPalanques()) { // llx=llx+5; // lly=lly+70; // Rectangle rectangle = new Rectangle(llx, lly, urx-llx, ury-lly); //// PdfCanvas canvas = new PdfCanvas(page); // canvas = new PdfCanvas(page); //// PdfCanvas canvas = new PdfCanvas(pdf.addNewPage()); //// pdfCanvas.rectangle(rectangle); // canvas.setStrokeColor(Color.RED).setLineWidth(0.5f).rectangle(rectangle).stroke(); //// canvas = new Canvas(pdfCanvas, pdf, rectangle); //// pdfCanvas.stroke(); // PdfFont fontRoman = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN); // PdfFont bold = PdfFontFactory.createFont(FontConstants.TIMES_BOLD); // Text title = new Text("GUIDE palanque:"+palanque.getNomCompletGuide()).setFont(bold); // Text author = new Text("PLONGEUR 1 palanque:"+palanque.getNomCompletPlongeur1()).setFont(fontRoman); // Paragraph p3 = new Paragraph().add(title).add(" by ").add(author); // new Canvas(canvas,pdf,rectangle).add(p3); //// canvas.add(p3); // } //Close document pdf.close(); }
From source file:com.isw.cec.Servlet.GenerarFoliosServlet.java
License:Open Source License
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String appPath = request.getServletContext().getRealPath(""); String savePath = appPath + File.separator + SAVE_DIR; File fileSaveDir = new File(savePath); if (!fileSaveDir.exists()) fileSaveDir.mkdirs();/*w w w.ja v a 2s .c om*/ String fileName = java.util.UUID.randomUUID().toString() + ".pdf"; Curso curso = (Curso) request.getAttribute("curso"); List<Entry<String, String>> alum_fol = Reader.getAlumFolios(curso.getID()); OutputStream fos = new FileOutputStream(savePath + File.separator + fileName); PdfWriter writer = new PdfWriter(fos); PdfDocument pdf = new PdfDocument(writer); Document document = new Document(pdf, PageSize.A4); document.setMargins(85, 57, 71, 71); PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN); PdfFont bold = PdfFontFactory.createFont(FontConstants.TIMES_BOLD); Paragraph p = new Paragraph("Folios de los alumnos inscritos al curso"); p.setTextAlignment(TextAlignment.CENTER); document.add(p); p = new Paragraph(curso.getNombre()); p.setFont(bold); p.setTextAlignment(TextAlignment.CENTER); p.setMarginBottom(70); document.add(p); Table table = new Table(new float[] { 1, 1 }); table.setWidthPercent(100); Cell c = new Cell().add(new Paragraph("ALUMNO").setFont(bold)); c.setTextAlignment(TextAlignment.CENTER); table.addHeaderCell(c); c = new Cell().add(new Paragraph("FOLIO").setFont(bold)); c.setTextAlignment(TextAlignment.CENTER); table.addHeaderCell(c); for (Entry<String, String> e : alum_fol) { table.addCell(new Cell().add(new Paragraph(e.getKey()).setFont(font))); table.addCell(new Cell().add(new Paragraph(e.getValue()).setFont(font))); } document.add(table); document.close(); Writer.openCurso(curso.getID(), fileName); response.getWriter().println("OK"); }