List of usage examples for com.itextpdf.text Paragraph setAlignment
public void setAlignment(int alignment)
From source file:principal.Informes.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//w ww .j a v a 2 s . com * * @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, DocumentException, InterruptedException { // SERVLET PARA LA IMPRESIN DE LOS REGISTROS DE SISTEMA try { // Ejecucion de comando que sera introducido en el pdf Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("/opt/script/owncloud/logOwncloud"); process.waitFor(); BufferedReader buffer = new BufferedReader(new InputStreamReader(process.getInputStream())); String linea; //Imagen para documento PDF Image imagen = Image.getInstance("images/owncloud.png"); imagen.setAlignment(Element.ALIGN_CENTER); //donde estara la imagen localizada imagen.setAlt("50"); // Creo objeto document de la clase Document Document document = new Document(); // paso 2 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // Abro nuevo documento PDF document.open(); document.addAuthor("Administrator"); //Nuevo parrafo con texto centrado Paragraph parrafo1 = new Paragraph("Informe de servidor Owncloud"); parrafo1.setAlignment(1); //Centrar el texto document.add(imagen); //introduccion de la imagen en el documento pdf document.add(parrafo1); // bucle ejecutando el comando e introduciendolo en un nuevo parrafo del PDF while ((linea = buffer.readLine()) != null) { document.add(new Paragraph(linea)); } // Cierre del documento PDF document.close(); // Response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // Tipo de contenido que ser response.setContentType("application/pdf"); // the contentlength response.setContentLength(baos.size()); // Extrae todo el PDF para introducirlo en el servlet OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (DocumentException e) { throw new IOException(e.getMessage()); } }
From source file:printers.AbstractHorariosPrinter.java
License:Open Source License
/** * * @param doc/*w w w. j a v a 2s . co m*/ * @throws DocumentException */ public void addTitle(Document doc) throws DocumentException { Font fontTitle = new Font(Font.FontFamily.HELVETICA, 24); Paragraph par = new Paragraph(getTextoTitulo(), fontTitle); par.setAlignment(Paragraph.ALIGN_CENTER); doc.add(par); }
From source file:printers.AbstractHorariosPrinter.java
License:Open Source License
private PdfPCell createCeldaHoras(String texto) { Font font = new Font(Font.FontFamily.HELVETICA, 10); Paragraph p = new Paragraph(texto, font); p.setAlignment(Paragraph.ALIGN_CENTER); PdfPCell c = new PdfPCell(p); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); c.setGrayFill(.9f);/*ww w . j av a2s .c o m*/ c.setNoWrap(true); c.setFixedHeight(alturaCeldas); return c; }
From source file:printers.AbstractHorariosPrinter.java
License:Open Source License
private PdfPCell createCeldaDiasSemana(String texto) { Font font = new Font(Font.FontFamily.HELVETICA, 14); Paragraph p = new Paragraph(texto, font); p.setAlignment(Paragraph.ALIGN_CENTER); PdfPCell c = new PdfPCell(p); c.setGrayFill(.9f);/*from ww w . j av a 2 s. c o m*/ c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setVerticalAlignment(PdfPCell.ALIGN_CENTER); return c; }
From source file:printers.HojaDeFirmaPrinter.java
License:Open Source License
private void creaCabecera(Document doc, Aula aula, GregorianCalendar dia) throws DocumentException { AcademicCalendar cal = dp.getAcademicCalendar(); Font font = new Font(Font.FontFamily.HELVETICA, 16); Font fontbold = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD); String diaSemana = cal.nombreDiaSemana(dia); Paragraph par = new Paragraph(); par.add(new Phrase("Hoja de firma para aula ", font)); par.add(new Phrase(aula.getNombre(), fontbold)); par.add(new Phrase(" correspondiente al da ", font)); par.add(new Phrase(diaSemana + " " + cal.format(dia), fontbold)); par.setAlignment(Paragraph.ALIGN_CENTER); doc.add(par);//w w w . ja v a2 s . c o m par.setAlignment(Paragraph.ALIGN_CENTER); }
From source file:printers.PrinterHorarioPorGrupos.java
License:Open Source License
/** * * @param doc//from ww w .j a v a 2s . co m * @param obj * @throws DocumentException */ @Override public void printCabecera(Document doc, Object obj) throws DocumentException { CarreraCursoGrupoContainer cont = (CarreraCursoGrupoContainer) obj; addTitle(doc); doc.add(new Paragraph()); Font fontSubtitle = new Font(Font.FontFamily.HELVETICA, 16); String texto = "Horarios para %s"; texto = texto.replace("%s", cont.getNombre()); Paragraph par = new Paragraph(texto, fontSubtitle); par.setAlignment(Paragraph.ALIGN_CENTER); doc.add(par); // doc.add(new LineSeparator()); doc.add(new Paragraph()); }
From source file:printers.PrinterHorariosPorAulas.java
License:Open Source License
/** *//w w w. j av a 2 s . c om * @param doc * @param obj * @throws DocumentException */ @Override public void printCabecera(Document doc, Object obj) throws DocumentException { addTitle(doc); String texto; AulaMT cont = (AulaMT) obj; texto = "Horarios para " + cont.getAula().getNombre() + " " + (cont.getEsTarde() ? "tarde" : "maana"); Paragraph par = new Paragraph(texto); par.setAlignment(Paragraph.ALIGN_CENTER); doc.add(par); }
From source file:printers.PrinterHorariosPorProfesor.java
License:Open Source License
/** * * @param doc/*from w ww .java 2 s .c o m*/ * @param obj * @throws DocumentException */ @Override public void printCabecera(Document doc, Object obj) throws DocumentException { addTitle(doc); Profesor p = (Profesor) obj; final Paragraph par = new Paragraph("Horarios para el profesor " + p.getNombre() + " " + p.getApellidos()); par.setAlignment(Paragraph.ALIGN_CENTER); doc.add(par); }
From source file:PROCESOS.ImprimirPDF.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); String precio_unitario = request.getParameter("precio"); String id_vale = request.getParameter("codigo"); // if(request.getParameter("codigo")!=null){ OutputStream salida = response.getOutputStream(); try {//from ww w .j a v a 2s. c om try { DTO.ClaseTransaccion clase = new ClaseTransaccion(); clase = consulta.Transaccion(); Document documento = new Document(PageSize.A4, 36, 36, 45, 20); PdfWriter pw = PdfWriter.getInstance(documento, salida); documento.open(); Paragraph parrafo1 = new Paragraph(); Font font_titulo = new Font(Font.FontFamily.HELVETICA, 16, Font.UNDERLINE, BaseColor.BLACK); parrafo1.add(new Phrase("TecnoBencina, COMPROBANTE", font_titulo)); parrafo1.setAlignment(Element.ALIGN_CENTER); parrafo1.add(new Phrase(Chunk.NEWLINE)); parrafo1.add(new Phrase(Chunk.NEWLINE)); documento.add(parrafo1); Paragraph parrafo2 = new Paragraph(); Font font_titulo_p2 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK); if (id_vale.length() > 0) { parrafo2.add(new Phrase("Comprobante de transaccion : codigo del vale : " + id_vale, font_titulo_p2)); } else { parrafo2.add(new Phrase("Comprobante de transaccion ", font_titulo_p2)); } parrafo2.setAlignment(Element.ALIGN_JUSTIFIED); parrafo2.add(new Phrase(Chunk.NEWLINE)); parrafo2.add(new Phrase(Chunk.NEWLINE)); parrafo2.add(new Phrase(Chunk.NEWLINE)); documento.add(parrafo2); PdfPTable tabla = new PdfPTable(9); PdfPCell celda1 = new PdfPCell(new Paragraph("ID transaccion ", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda2 = new PdfPCell( new Paragraph("Estado ", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda3 = new PdfPCell(new Paragraph("ID de surtidor", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda4 = new PdfPCell( new Paragraph("Litros", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda5 = new PdfPCell( new Paragraph("Monto", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda6 = new PdfPCell( new Paragraph("Fecha", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda7 = new PdfPCell( new Paragraph("ID pago", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda8 = new PdfPCell(new Paragraph("Precio unitario", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); tabla.addCell(celda1); tabla.addCell(celda2); tabla.addCell(celda3); tabla.addCell(celda4); tabla.addCell(celda5); tabla.addCell(celda6); tabla.addCell(celda7); tabla.addCell(celda8); tabla.addCell(String.valueOf(clase.getId_transaccion())); tabla.addCell(clase.getEstado()); tabla.addCell(String.valueOf(clase.getId_transaccion())); tabla.addCell(String.valueOf(clase.getLitros())); tabla.addCell(String.valueOf(clase.getMonto())); tabla.addCell(String.valueOf(clase.getFecha())); tabla.addCell(String.valueOf(clase.getId_pago())); tabla.addCell(precio_unitario); documento.add(tabla); documento.addAuthor("TecnoBencina"); documento.addTitle("Comprobante"); documento.addLanguage("Espaol"); documento.add(new Paragraph(new Phrase(Chunk.NEWLINE))); documento.add(new Paragraph(new Phrase(Chunk.NEWLINE))); documento.add(new Paragraph(new Phrase(Chunk.NEWLINE))); documento.add(new Paragraph(new Phrase(Chunk.NEWLINE))); documento.add(new Paragraph("texto....", font_titulo_p2)); documento.close(); } catch (Exception s) { s.getMessage(); } } catch (Exception s) { System.out.println("" + s.getMessage()); } finally { salida.close(); } // } }
From source file:project1.GENERALCV.java
private void createcvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createcvActionPerformed String firstname, lastname, contactno, email, phonenumber, address; String dob, martialStatus, cast, careerObjectives; String university, city, startdatee, enddatee, coursesAndQualification; String acedemicQualification, certificates, experience, techskills, addSkills; String achivements, additionalCertificates, references, hobbies; firstname = txtname.getText();//from w ww . ja v a2s. com lastname = txtlastname.getText(); email = txtemail.getText(); phonenumber = txtMobileNo.getText(); address = txtAddress.getText(); SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); String link = txtLink.getText(); // dob= dateFormat.format(dateOfBirth.getDate()); martialStatus = cmbMartialStatus.getSelectedItem().toString(); // cast=txtcast.getText(); // careerObjectives=txtcareer.getText(); university = txtCollegeName.getText(); city = txtCity.getText(); // startdatee=dateFormat.format(startdate.getDate()); // enddatee=dateFormat.format(enddate.getDate()); coursesAndQualification = txtExtraCourses.getText(); // certificates=txtcertificats.getText(); // experience=txtexperience.getText(); techskills = txttechnical.getText(); // addSkills=txtadditional.getText(); references = txtreference.getText(); try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/cvmaker", "root", "12345"); pInsertPerson = con .prepareStatement("INSERT INTO PERSONS(NAMEE,CONTACTNO,EMAILID,ADDRESS) VALUES(?,?,?,?)"); pInsertPerson.setString(1, firstname + lastname); pInsertPerson.setString(2, phonenumber); pInsertPerson.setString(3, email); pInsertPerson.setString(4, address); pInsertPerson.executeUpdate(); JOptionPane.showMessageDialog(null, "Data Is Alo Saved In Database...."); showRecords(); } catch (Exception e) { System.out.println(e.toString()); } Statement statement; String selectTableSQL = "SELECT ID FROM PERSONS"; int ss = 0; try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/cvmaker", "root", "12345"); statement = con.createStatement(); //System.out.println(selectTableSQL); // execute select SQL stetementS ResultSet rs = statement.executeQuery(selectTableSQL); while (rs.next()) { ss = rs.getInt("ID"); } } catch (SQLException e) { System.out.println(e.toString()); } catch (ClassNotFoundException ex) { Logger.getLogger(FRESHERCV.class.getName()).log(Level.SEVERE, null, ex); } int newcvid = ss; try { OutputStream file = new FileOutputStream(new File("D:\\PDFFILES\\" + firstname + lastname + ".pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); // Image im=Image.getInstance("E:\\PDFFILES\\FUUAST.png"); // document.add(new Paragraph("")); // document.add(im); Paragraph title1 = new Paragraph(firstname + " " + lastname + " Cv", FontFactory .getFont(FontFactory.HELVETICA, 36, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); Chapter chapter1 = new Chapter(title1, 1); chapter1.setNumberDepth(0); document.add(chapter1); document.add(new Paragraph("\n\n")); List unorderedList = new List(List.UNORDERED); unorderedList.add(new ListItem("Mobile No:" + phonenumber)); unorderedList.add(new ListItem("Email:" + city)); unorderedList.add(new ListItem("Address:" + address)); // unorderedList.add(new ListItem("End Date:" + enddatee)); document.add(unorderedList); // document.add(new Paragraph("Address:"+address)); Paragraph title2 = new Paragraph("Personal Information", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); title2.setAlignment(Element.ALIGN_CENTER); document.add(title2); // document.add(new Paragraph("Date Of Birth:" + dob)); document.add(new Paragraph("Martial Status:" + martialStatus)); // document.add(new Paragraph("Cast:"+cast)); // document.add(new Paragraph("Career Objectives:"+careerObjectives)); Paragraph title3 = new Paragraph("Qualification", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); title3.setAlignment(Element.ALIGN_CENTER); document.add(title3); PdfPTable table = new PdfPTable(2); // 3 columns. document.add(new Paragraph("\n\n")); PdfPCell cell1 = new PdfPCell(new Paragraph("Insituite Name:")); PdfPCell cell2 = new PdfPCell(new Paragraph(university)); PdfPCell cell3 = new PdfPCell(new Paragraph("City:")); PdfPCell cell4 = new PdfPCell(new Paragraph(city)); PdfPCell cell5 = new PdfPCell(new Paragraph("Start Date:")); // PdfPCell cell6 = new PdfPCell(new Paragraph(startdatee)); PdfPCell cell7 = new PdfPCell(new Paragraph("End Date:")); //PdfPCell cell8 = new PdfPCell(new Paragraph(enddatee)); PdfPCell cell71 = new PdfPCell(new Paragraph("Extra Courses:")); PdfPCell cell81 = new PdfPCell(new Paragraph(coursesAndQualification)); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); table.addCell(cell5); // table.addCell(cell6); table.addCell(cell7); // table.addCell(cell8); table.addCell(cell71); table.addCell(cell81); document.add(table); // document.add(new Paragraph("Extra Courses:"+coursesAndQualification)); // document.add(new Paragraph("Certificates:"+certificates)); // Paragraph title4 = new Paragraph("Experience", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); title4.setAlignment(Element.ALIGN_CENTER); document.add(title4); // document.add(new Paragraph(""+experience)); Paragraph title5 = new Paragraph("Skills", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); title5.setAlignment(Element.ALIGN_CENTER); document.add(title5); document.add(new Paragraph("Technical Skills:" + techskills)); // document.add(new Paragraph("Additional Skills:"+addSkills)); Paragraph title6 = new Paragraph("References", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); title6.setAlignment(Element.ALIGN_CENTER); document.add(title6); document.add(new Paragraph("References:" + references)); // Anchor anchor; // anchor = new Anchor(link, FontFactory.getFont(FontFactory.HELVETICA,12, Font.UNDERLINE, new CMYKColor(0, 0,0,255))); // anchor.setReference( link); Paragraph paragraph = new Paragraph("Profile Link:"); // paragraph.add(anchor); document.add(paragraph); Paragraph title11 = new Paragraph( " Cv Number:" + newcvid, FontFactory .getFont(FontFactory.HELVETICA, 15, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17))); document.add(new Paragraph("\n\n")); document.add(title11); try { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(new File("D:\\PDFFILES\\" + firstname + lastname + ".pdf")); } else { System.out.println("Open is not supported"); } } catch (IOException exp) { exp.printStackTrace(); } document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } }