List of usage examples for com.lowagie.text Image getInstance
public static Image getInstance(Image image)
From source file:servlets.PrenotazioneServlet.java
private void invioBiglietto(ArrayList<Integer> id_prenotazione) throws DocumentException, FileNotFoundException { servletContext = getServletContext(); ArrayList<Double> prezzo_pagato = new ArrayList<>(); ArrayList<Integer> posto = new ArrayList<>(); ArrayList<Integer> spettacolo = new ArrayList<>(); ArrayList<Date> data = new ArrayList<>(); ArrayList<String> emails = new ArrayList<>(); ArrayList<String> titolo = new ArrayList<>(); ArrayList<Date> data_spettacolo = new ArrayList<>(); ArrayList<Integer> sala = new ArrayList<>(); Prenotazione preno = null;/*w w w .jav a2 s . c o m*/ try { for (int i = 0; i < id_prenotazione.size(); i++) { preno = manager.getPrenotazione(id_prenotazione.get(i)); System.out.println(id_prenotazione.get(i)); prezzo_pagato.add(preno.getId_prezzo()); posto.add(preno.getId_posto() - ((preno.getSala() - 1) * 50)); spettacolo.add(preno.getId_spettacolo()); data.add(preno.getData_ora_prenotazione()); emails.add(preno.getEmail()); titolo.add(preno.getTitolo()); data_spettacolo.add(preno.getData_ora_spettacolo()); sala.add(preno.getSala()); } } catch (SQLException ex) { Logger.getLogger(InvioServlet.class.getName()).log(Level.SEVERE, null, ex); } //int id=preno.getId_prenotazione(); //creo il pdf per la prenotazione Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(servletContext.getRealPath("/") + "ticket.pdf")); System.out.println("Creazione file riuscita"); document.open(); //creo il paragrafo per il tiolo della pagina for (int i = 0; i < id_prenotazione.size(); i++) { Paragraph p = new Paragraph("Biglietto n " + id_prenotazione.get(i)); p.setAlignment(Element.ALIGN_CENTER); try { document.add(p); System.out.println("Scrittura file riuscita"); } catch (DocumentException ex) { } //creo il paragrafo per i dati del biglietto p = new Paragraph(""); p.setAlignment(Element.ALIGN_LEFT); p.add("Biglietto: " + id_prenotazione.get(i) + "\n"); p.add("Utente: " + emails.get(i) + "\n"); p.add("Prezzo pagato: " + prezzo_pagato.get(i) + "\n"); p.add("Numero posto: " + posto.get(i) + "\n"); p.add("Spettacolo: " + spettacolo.get(i) + "\n"); p.add("Data: " + data.get(i) + "\n"); p.add("Film: " + titolo.get(i) + "\n"); p.add("Data spettacolo: " + data_spettacolo.get(i) + "\n"); p.add("Sala: " + sala.get(i) + "\n"); System.out.println("INFO INFO INFO" + id_prenotazione.get(i) + " " + emails.get(i) + " " + prezzo_pagato.get(i) + " " + posto.get(i) + " " + spettacolo.get(i) + " " + data.get(i) + " " + "FINE FINE FINE"); try { document.add(p); System.out.println("Scrittura file riuscita"); } catch (DocumentException ex) { } } //creo il qrcode e lo aggiungo alla pagina Image image = null; File file; Paragraph p = new Paragraph(""); file = QRCode.from("Email:" + email + "\n" + "Prezzo:" + prezzo_pagato + "\n" + "Numero posto:" + posto + "\n" + "Spettacolo:" + spettacolo.get(0) + "\n" + "Data:" + data.get(0) + "\n" + "Film: " + titolo.get(0) + "\n" + "Data spettacolo: " + data_spettacolo.get(0) + "\n" + "Sala: " + sala.get(0)).to(ImageType.JPG).withSize(300, 300).file(); try { image = Image.getInstance(file.getAbsolutePath()); } catch (BadElementException | MalformedURLException ex) { // Logger.getLogger(SendTicket.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PrenotazioneServlet.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(file.toString()); try { document.add(image); } catch (DocumentException ex) { } try { document.add(p); document.newPage(); System.out.println("Scrittura file riuscita"); } catch (DocumentException ex) { } document.close(); try { //invio la mail per la conferma della prenotazione con allegato il pdf Email.ticketEmail("smtp.gmail.com", "587", "cinemangiare@gmail.com", "Cinemangiaredb", email, "Conferma acquisto biglietti", "Gentile cliente," + "\n" + "le confermiamo la prenotazione presso il nostro cinema." + "\n" + "In allegato trover il file pdf da stampare contenente i biglietti", servletContext.getRealPath("/") + "ticket.pdf"); } catch (Exception ex) { System.out.println("logan"); } }
From source file:sms.ReportForms.java
public void utext(String query, String Name, String dob, String house, String formclass, String kcpe, String imgurl, String kcpegrade, String id) { methods nn = new methods(); String u = unig();/*w w w .jav a 2 s . co m*/ checkPreviousResults(u, kcpe, kcpegrade, id); ArrayList<ExamDbDataHolder> users = selectExamResults(u, query); if (users.size() < 2) { Form1Exams n = new Form1Exams(); String[] Subjects = n.findSubjectid(); String[] Subjectsnames = n.findSubjectname(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(",")); chooser.setDialogTitle("Save at"); chooser.setApproveButtonText("save"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try { Document pdfp = new Document(); PdfWriter w = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(), "" + sid.getText() + ".pdf"))); pdfp.open(); PdfContentByte canvas = w.getDirectContentUnder(); Image imgb = Image.getInstance("C:\\Users\\kimani kogi\\Pictures\\icons\\logo.png"); imgb.setAbsolutePosition(2, 2); imgb.scaleAbsoluteHeight(PageSize.A4.getHeight() / 4); imgb.scaleAbsoluteWidth(PageSize.A4.getWidth() / 4); canvas.saveState(); PdfGState state = new PdfGState(); state.setFillOpacity(0.6f); canvas.setGState(state); canvas.addImage(imgb); canvas.restoreState(); PdfPTable tbl1 = new PdfPTable(2); // tbl.setWidthPercentage(100); tbl1.setTotalWidth(575); tbl1.setLockedWidth(true); tbl1.setWidths(new int[] { 1, 4 }); if (imgurl.equals("image")) { tbl1.addCell("no image "); String img = imgurl; } else { tbl1.addCell(createImageCell(imgurl)); } tbl1.addCell(createTextCell(schooldetails)); PdfPTable tbl = new PdfPTable(8); // tbl.setWidthPercentage(100); tbl.setTotalWidth(575); tbl.setLockedWidth(true); tbl.setSpacingBefore(8); tbl.setSpacingAfter(6); tbl.getDefaultCell().setBorderWidthTop(2); tbl.getDefaultCell().setBorderWidthLeft(0); tbl.getDefaultCell().setBorderWidthRight(0); tbl.setWidths(new int[] { 1, 1, 1, 2, 1, 1, 1, 1 }); tbl.addCell("Adm No:"); tbl.addCell(sid.getText()); tbl.addCell("Name:"); tbl.addCell(Name); tbl.addCell("Form:"); tbl.addCell(formclass); tbl.addCell("Kcpe:"); tbl.addCell(kcpe); tbl.addCell("House:"); tbl.addCell(house); tbl.addCell("Term:"); tbl.addCell("Second term"); tbl.addCell("Year:"); tbl.addCell("2017"); tbl.addCell("DOB:"); tbl.addCell(dob); PdfPTable tbl2 = new PdfPTable(5); // tbl.setWidthPercentage(100); tbl2.setTotalWidth(575); tbl2.setLockedWidth(true); // tbl2.getDefaultCell().setFixedHeight(35f); tbl2.setWidths(new int[] { 2, 1, 1, 2, 2 }); tbl2.addCell(creatTextCellHeader("Subjects")); tbl2.addCell(creatTextCellHeader("Exams")); tbl2.addCell(creatTextCellHeader("Grade")); tbl2.addCell(creatTextCellHeader("Ratings")); tbl2.addCell(creatTextCellHeader("Remarks")); // String [] Subjectsnames=n.findSubjectname(); for (int i = 0; i < users.size(); i++) { for (int a = 0; a < Subjectsnames.length; a++) { tbl2.addCell(Subjectsnames[a]); String re = null; if (Subjects[a].equals("s1")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMathematics()); re = ((ExamDbDataHolder) users.get(i)).getMathematics(); // JOptionPane.showMessageDialog(null,((ExamDbDataHolder)users.get(i)).getMathematics()); // String maths = ((ExamDbDataHolder)users.get(i)).getMathematics(); } else if (Subjects[a].equals("s2")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getEnglish()); re = ((ExamDbDataHolder) users.get(i)).getEnglish(); //row[c] = ((ExamDbDataHolder)users.get(i)).getEnglish(); // c++; } else if (Subjects[a].equals("s3")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getKiswahili()); re = ((ExamDbDataHolder) users.get(i)).getKiswahili(); // row[c] = ((ExamDbDataHolder)users.get(i)).getKiswahili(); // c++; } else if (Subjects[a].equals("s4")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getPhysics()); re = ((ExamDbDataHolder) users.get(i)).getPhysics(); // row[c] = ((ExamDbDataHolder)users.get(i)).getPhysics(); // c++; } else if (Subjects[a].equals("s5")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getChemistry()); re = ((ExamDbDataHolder) users.get(i)).getChemistry(); // row[c] = ((ExamDbDataHolder)users.get(i)).getChemistry(); // c++; } else if (Subjects[a].equals("s6")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBiology()); re = ((ExamDbDataHolder) users.get(i)).getBiology(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBiology(); // c++; } else if (Subjects[a].equals("s7")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHistory()); re = ((ExamDbDataHolder) users.get(i)).getHistory(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHistory(); // c++; } else if (Subjects[a].equals("s8")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getGeography()); re = ((ExamDbDataHolder) users.get(i)).getGeography(); // row[c] = ((ExamDbDataHolder)users.get(i)).getGeography(); // c++; } else if (Subjects[a].equals("s9")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getCre()); re = ((ExamDbDataHolder) users.get(i)).getCre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getCre(); // c++; } else if (Subjects[a].equals("s10")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getIre()); re = ((ExamDbDataHolder) users.get(i)).getIre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getIre(); // c++; } else if (Subjects[a].equals("s11")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHre()); re = ((ExamDbDataHolder) users.get(i)).getHre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHre(); // c++; } else if (Subjects[a].equals("s12")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getAgriculture()); re = ((ExamDbDataHolder) users.get(i)).getAgriculture(); // row[c] = ((ExamDbDataHolder)users.get(i)).getAgriculture(); // c++; } else if (Subjects[a].equals("s13")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHomescience()); re = ((ExamDbDataHolder) users.get(i)).getHomescience(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHomescience(); // c++; } else if (Subjects[a].equals("s14")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getArtdesign()); re = ((ExamDbDataHolder) users.get(i)).getArtdesign(); // row[c] = ((ExamDbDataHolder)users.get(i)).getArtdesign(); // c++; } else if (Subjects[a].equals("s15")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getComputer()); re = ((ExamDbDataHolder) users.get(i)).getComputer(); // row[c] = ((ExamDbDataHolder)users.get(i)).getComputer(); // c++; } else if (Subjects[a].equals("s16")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBuilding()); re = ((ExamDbDataHolder) users.get(i)).getBuilding(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBuilding(); // c++; } else if (Subjects[a].equals("s17")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getWoodwork()); re = ((ExamDbDataHolder) users.get(i)).getWoodwork(); // row[c] = ((ExamDbDataHolder)users.get(i)).getWoodwork(); // c++; } else if (Subjects[a].equals("s18")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMetalwork()); re = ((ExamDbDataHolder) users.get(i)).getMetalwork(); // row[c] = ((ExamDbDataHolder)users.get(i)).getMetalwork(); // c++; } else if (Subjects[a].equals("s19")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMusic()); re = ((ExamDbDataHolder) users.get(i)).getMusic(); // row[c] = ((ExamDbDataHolder)users.get(i)).getMusic(); // c++; } else if (Subjects[a].equals("s20")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getFrench()); re = ((ExamDbDataHolder) users.get(i)).getFrench(); // row[c] = ((ExamDbDataHolder)users.get(i)).getFrench(); // c++; } else if (Subjects[a].equals("s21")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getGerman()); re = ((ExamDbDataHolder) users.get(i)).getGerman(); // row[c] = ((ExamDbDataHolder)users.get(i)).getGerman(); // c++; } else if (Subjects[a].equals("s22")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getArabic()); re = ((ExamDbDataHolder) users.get(i)).getArabic(); // row[c] = ((ExamDbDataHolder)users.get(i)).getArabic(); // c++; } else if (Subjects[a].equals("s23")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBusiness()); re = ((ExamDbDataHolder) users.get(i)).getBusiness(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBusiness(); // c++; } String[] gr = nn.checkGrade(re, Subjects[a]); tbl2.addCell(gr[0]); tbl2.addCell(gr[1]); tbl2.addCell(""); } } //add for all other subjects PdfPTable tbl3 = new PdfPTable(4); // tbl.setWidthPercentage(100); tbl3.setTotalWidth(575); tbl3.setLockedWidth(true); tbl3.setSpacingBefore(8); tbl3.setSpacingAfter(6); // tbl3.getDefaultCell().setBorderWidthTop(0); tbl3.getDefaultCell().setBorder(0); // tbl3.getDefaultCell().setBorderWidthLeft(0); // tbl3.getDefaultCell().setBorderWidthRight(0); tbl3.setWidths(new int[] { 1, 1, 1, 1 }); tbl3.addCell(creatTextCellHeader("CURRENT MARKS:")); tbl3.addCell(creatTextCellHeader(String.valueOf(((ExamDbDataHolder) users.get(0)).getTotal()))); float g = Float.valueOf(((ExamDbDataHolder) users.get(0)).getTotal()); // tbl.addCell(String.format("%.1f", g)); String gr = nn.checkGrade(yearid, String.format("%.1f", g / getYear())); tbl3.addCell(creatTextCellHeader("PREVIOUS MARKS:")); tbl3.addCell(creatTextCellHeader("459")); tbl3.addCell(creatTextCellHeader("AVERAGE MARKS:")); tbl3.addCell(creatTextCellHeader(String.format("%.1f", g / getYear()))); tbl3.addCell(creatTextCellHeader("PREVIOUS AVERAGE:")); tbl3.addCell(creatTextCellHeader("50")); tbl3.addCell(creatTextCellHeader("MEAN GRADE:")); tbl3.addCell(creatTextCellHeader(gr)); tbl3.addCell(creatTextCellHeader("PREVIOUS MEAN GRADE:")); tbl3.addCell(creatTextCellHeader("B")); tbl3.addCell(creatTextCellHeader("POS")); tbl3.addCell(creatTextCellHeader("3 ")); tbl3.addCell(creatTextCellHeader("OUT OF")); tbl3.addCell(creatTextCellHeader("79")); PdfPTable tbl4 = new PdfPTable(2); // tbl.setWidthPercentage(100); tbl4.setHorizontalAlignment(0); //tbl4.HorizontalAlignment=Element.ALIGN_LEFT; tbl4.setTotalWidth(575 / 2); tbl4.setLockedWidth(true); tbl4.setSpacingBefore(8); tbl4.setSpacingAfter(6); // tbl3.getDefaultCell().setBorderWidthTop(0); tbl4.getDefaultCell().setBorder(0); // tbl3.getDefaultCell().setBorderWidthLeft(0); // tbl3.getDefaultCell().setBorderWidthRight(0); tbl4.setWidths(new int[] { 2, 1 }); PdfPCell cell = new PdfPCell(new Paragraph("REMARKS")); cell.setColspan(2); tbl4.addCell(cell); tbl4.addCell(creatTextCellHeader( "CLASS TEACHERS........................................................." + ":............................\n\n\n")); tbl4.addCell(creatTextCellChart("chart")); tbl4.addCell(creatTextCellHeader( "SIGNATURE-------------------------------------------------------------" + "-------------------------------\n\n\n")); tbl4.addCell(creatTextCellHeader( "-------------\n\n\n-----------------------------------------------------------" + "-----------------------------")); pdfp.add(tbl1); pdfp.add(tbl); pdfp.add(tbl2); pdfp.add(tbl3); pdfp.add(tbl4); // Paragraph p=new Paragraph(); // p.setAlignment(Element.ALIGN_CENTER); // p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,18,Font.BOLD)); // Paragraph po=new Paragraph(); // po.setAlignment(Element.ALIGN_CENTER); // po.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,16,Font.BOLD)); // // Paragraph pd=new Paragraph(); // pd.setAlignment(Element.ALIGN_CENTER); // pd.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,14,Font.BOLD)); // p.add("ITHANGA SECONDARY SCHOOL"); // po.add("PO.BOX 238 ITHANGA THIKA"); // pd.add(new Date().toString()); // pdfp.add(p); // pdfp.add(po); // pdfp.add(pd); // // // // pdfp.add(new Paragraph("\n.................................................................." // + ".................................................................................\n")); // String []names= n.findSubjectname(); // PdfPTable tbl=new PdfPTable(names.length+6); // tbl.setWidths(new float[]{1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1}); // // tbl.setWidthPercentage(100); // tbl.setTotalWidth(575); // tbl.setLockedWidth(true); // PdfPTable tbl1=new PdfPTable(names.length+6); // tbl1.setWidths(new float[]{1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1}); // // tbl.setWidthPercentage(100); // tbl1.setTotalWidth(575); // tbl1.setLockedWidth(true); // PdfPCell cell=new PdfPCell (new Paragraph("RESULTS")); // cell.setColspan((names.length+4)*2); // cell.setBackgroundColor(Color.CYAN); // tbl1.addCell(cell); // tbl1.addCell("Pos"); // tbl1.addCell("id"); // tbl1.addCell("Name"); // int a; pdfp.close(); } catch (Exception j) { j.printStackTrace(); } // Image img=new Image.getInstance("j.png"); } } }
From source file:sms.ReportForms.java
public PdfPCell createImageCell(String path) throws IOException { PdfPCell cell = null;/* w w w . j a v a 2 s . c o m*/ try { Image img = Image.getInstance(path); cell = new PdfPCell(img, true); cell.setFixedHeight(60); cell.setBorder(Rectangle.NO_BORDER); } catch (BadElementException ex) { Logger.getLogger(ReportForms.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(ReportForms.class.getName()).log(Level.SEVERE, null, ex); } return cell; }
From source file:storemanagment.Printing.java
public PdfPCell createImageCell(String path) throws IOException { PdfPCell cell = null;/*from w w w .j av a 2 s .com*/ try { Image img = Image.getInstance(path); cell = new PdfPCell(img, true); cell.setFixedHeight(30); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(10); } catch (BadElementException ex) { Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex); } return cell; }
From source file:storemanagment.Printing.java
public PdfPCell createImageCellCrip(String path, PdfWriter writer) throws IOException, DocumentException { PdfPCell cell = null;//w ww . ja va2s . c o m try { Image img = Image.getInstance(path); float w = img.getScaledWidth(); float h = img.getScaledHeight(); PdfTemplate t = writer.getDirectContent().createTemplate(w, h); t.ellipse(0, 0, w, h); t.newPath(); t.addImage(img, w, 0, 0, h, 0, -600); Image clipped = Image.getInstance(t); cell = new PdfPCell(clipped, true); // cell.setFixedHeight(30); // cell.setBorder(Rectangle.NO_BORDER); //cell.setBorder(R); cell.setPaddingTop(10); } catch (BadElementException ex) { Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex); } return cell; }
From source file:subcentro_licto.presentacion.beans.DatosBuscadorBean.java
public void imprimirDatos() { //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL); try {/*w ww . ja v a2 s.c om*/ //Generamos el archivo PDF String directorioArchivos; ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); directorioArchivos = ctx.getRealPath("/") + "reports"; String name = directorioArchivos + "/documento-datos.pdf"; Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(name)); //PdfWriter writer = PdfWriter.getInstance(document, //new FileOutputStream("C:")); Paragraph paragraph = new Paragraph(); PdfPTable table = new PdfPTable(2); PdfPTable table1 = new PdfPTable(2); PdfPTable table2 = new PdfPTable(2); PdfPTable table3 = new PdfPTable(2); PdfPTable table4 = new PdfPTable(2); PdfPTable table5 = new PdfPTable(2); PdfPTable table6 = new PdfPTable(2); PdfPTable table7 = new PdfPTable(2); PdfPTable table8 = new PdfPTable(2); PdfPTable table9 = new PdfPTable(2); PdfPTable table10 = new PdfPTable(2); PdfPTable table11 = new PdfPTable(2); PdfPTable table12 = new PdfPTable(2); PdfPTable table13 = new PdfPTable(1); paragraph.add("\n\n\n\n\n\n"); paragraph.setAlignment(Paragraph.ALIGN_CENTER); document.open(); Image image1 = Image.getInstance( "C:/Users/Usuario/Documents/NetBeansProjects/gestionsalud/web/resources/images/logoMSP.jpg"); image1.setAlignment(Element.ALIGN_CENTER); PdfPCell cell5 = new PdfPCell(new Paragraph("Fecha Agresin: " + datosSel.getFecha_agresion())); PdfPCell cell7 = new PdfPCell(new Paragraph("Fecha Atencin: " + datosSel.getFecha_de_atencion())); PdfPCell cell8 = new PdfPCell(new Paragraph("Nombres: " + datosSel.getNombres())); PdfPCell cell11 = new PdfPCell(new Paragraph("Apellidos: " + datosSel.getApellidos())); PdfPCell cell12 = new PdfPCell(new Paragraph("Edad: " + datosSel.getEdad())); PdfPCell cell9 = new PdfPCell(new Paragraph("Sexo: " + datosSel.getSexo())); PdfPCell cell10 = new PdfPCell(new Paragraph("Estado Civil:" + datosSel.getEstado_civil())); PdfPCell cell13 = new PdfPCell(new Paragraph("Instruccin:" + datosSel.getInstruccion_formal())); PdfPCell cell1 = new PdfPCell(new Paragraph("Ocupacin: " + datosSel.getOcupacion())); PdfPCell cell2 = new PdfPCell(new Paragraph("Institucin: " + datosSel.getInstitucion())); PdfPCell cell3 = new PdfPCell(new Paragraph("Asociacin: " + datosSel.getAsociacion())); PdfPCell cell4 = new PdfPCell(new Paragraph("Provincia: " + datosSel.getProvincia())); PdfPCell cell6 = new PdfPCell(new Paragraph("Cantn: " + datosSel.getCanton_domicilio())); PdfPCell cell14 = new PdfPCell(new Paragraph("Parroquia: " + datosSel.getParroquia_domicilio())); PdfPCell cell15 = new PdfPCell(new Paragraph("Barrio: " + datosSel.getBarrio())); PdfPCell cell16 = new PdfPCell(new Paragraph("Calles: " + datosSel.getCalles_domicilio())); PdfPCell cell17 = new PdfPCell(new Paragraph("Direccin Trabajo: " + datosSel.getDireccion_trabajo())); PdfPCell cell18 = new PdfPCell(new Paragraph("Telfono Domicilio: " + datosSel.getTelefono())); PdfPCell cell19 = new PdfPCell(new Paragraph("Telfono Trabajo: " + datosSel.getTelefono_trabajo())); PdfPCell cell20 = new PdfPCell( new Paragraph("Objeto de Agresin: " + datosSel.getObjeto_de_agresion())); PdfPCell cell21 = new PdfPCell( new Paragraph("Tipo de Agresin: " + datosSel.getTipos_de_agresiones())); PdfPCell cell22 = new PdfPCell( new Paragraph("Estado de Conciencia: " + datosSel.getEstado_de_conciencia())); PdfPCell cell23 = new PdfPCell(new Paragraph("Lugar de Agresin: " + datosSel.getLugar_de_agresion())); PdfPCell cell24 = new PdfPCell(new Paragraph("Frecuencia: " + datosSel.getFrecuencia())); PdfPCell cell25 = new PdfPCell(new Paragraph("Caso Medico: " + datosSel.getCaso_medico())); PdfPCell cell26 = new PdfPCell(new Paragraph("Tratamiento: " + datosSel.getTratamiento())); PdfPCell cell27 = new PdfPCell(new Paragraph("Referido: " + datosSel.getReferido())); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2.setHorizontalAlignment(Element.ALIGN_LEFT); cell3.setHorizontalAlignment(Element.ALIGN_LEFT); cell4.setHorizontalAlignment(Element.ALIGN_LEFT); cell5.setHorizontalAlignment(Element.ALIGN_LEFT); cell6.setHorizontalAlignment(Element.ALIGN_LEFT); cell7.setHorizontalAlignment(Element.ALIGN_LEFT); cell8.setHorizontalAlignment(Element.ALIGN_LEFT); cell9.setHorizontalAlignment(Element.ALIGN_LEFT); cell10.setHorizontalAlignment(Element.ALIGN_LEFT); cell11.setHorizontalAlignment(Element.ALIGN_LEFT); cell12.setHorizontalAlignment(Element.ALIGN_LEFT); cell13.setHorizontalAlignment(Element.ALIGN_LEFT); cell14.setHorizontalAlignment(Element.ALIGN_LEFT); cell15.setHorizontalAlignment(Element.ALIGN_LEFT); cell16.setHorizontalAlignment(Element.ALIGN_LEFT); cell17.setHorizontalAlignment(Element.ALIGN_LEFT); cell18.setHorizontalAlignment(Element.ALIGN_LEFT); cell19.setHorizontalAlignment(Element.ALIGN_LEFT); cell20.setHorizontalAlignment(Element.ALIGN_LEFT); cell21.setHorizontalAlignment(Element.ALIGN_LEFT); cell22.setHorizontalAlignment(Element.ALIGN_LEFT); cell23.setHorizontalAlignment(Element.ALIGN_LEFT); cell24.setHorizontalAlignment(Element.ALIGN_LEFT); cell25.setHorizontalAlignment(Element.ALIGN_LEFT); cell26.setHorizontalAlignment(Element.ALIGN_LEFT); cell27.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setBorder(Rectangle.NO_BORDER); cell2.setBorder(Rectangle.NO_BORDER); cell3.setBorder(Rectangle.NO_BORDER); cell4.setBorder(Rectangle.NO_BORDER); cell5.setBorder(Rectangle.NO_BORDER); cell6.setBorder(Rectangle.NO_BORDER); cell7.setBorder(Rectangle.NO_BORDER); cell8.setBorder(Rectangle.NO_BORDER); cell9.setBorder(Rectangle.NO_BORDER); cell10.setBorder(Rectangle.NO_BORDER); cell11.setBorder(Rectangle.NO_BORDER); cell12.setBorder(Rectangle.NO_BORDER); cell13.setBorder(Rectangle.NO_BORDER); cell14.setBorder(Rectangle.NO_BORDER); cell15.setBorder(Rectangle.NO_BORDER); cell16.setBorder(Rectangle.NO_BORDER); cell17.setBorder(Rectangle.NO_BORDER); cell18.setBorder(Rectangle.NO_BORDER); cell19.setBorder(Rectangle.NO_BORDER); cell20.setBorder(Rectangle.NO_BORDER); cell21.setBorder(Rectangle.NO_BORDER); cell22.setBorder(Rectangle.NO_BORDER); cell23.setBorder(Rectangle.NO_BORDER); cell24.setBorder(Rectangle.NO_BORDER); cell25.setBorder(Rectangle.NO_BORDER); cell26.setBorder(Rectangle.NO_BORDER); cell27.setBorder(Rectangle.NO_BORDER); table1.addCell(cell5); table1.addCell(cell7); table2.addCell(cell8); table2.addCell(cell11); table3.addCell(cell12); table3.addCell(cell9); table.addCell(cell10); table.addCell(cell13); table4.addCell(cell1); table4.addCell(cell2); table5.addCell(cell3); table5.addCell(cell4); table6.addCell(cell6); table6.addCell(cell14); table7.addCell(cell15); table7.addCell(cell16); table8.addCell(cell17); table8.addCell(cell18); table9.addCell(cell19); table9.addCell(cell20); table10.addCell(cell21); table10.addCell(cell22); table11.addCell(cell23); table11.addCell(cell24); table12.addCell(cell25); table12.addCell(cell26); table13.addCell(cell27); document.add(image1); document.add(paragraph); document.add(table1); document.add(table2); document.add(table3); document.add(table); document.add(table4); document.add(table5); document.add(table6); document.add(table7); document.add(table8); document.add(table9); document.add(table10); document.add(table11); document.add(table12); document.add(table13); //document.add(table); //document.setFooter(event); document.close(); //---------------------------- //Abrimos el archivo PDF FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setContentType("application/pdf"); response.setHeader("Content-disposition", "inline=filename=" + name); try { response.getOutputStream().write(Util.getBytesFromFile(new File(name))); response.getOutputStream().flush(); response.getOutputStream().close(); context.responseComplete(); } catch (IOException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:test.itext.html.AimsPdf.java
License:Open Source License
public static void addTitle(Document doc, String text) throws IOException, BadElementException, DocumentException { float[] widths = { 62f, 164f, 62f }; PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(100);// ww w. ja v a 2 s . c o m table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setSpacingAfter(10); Image image = Image.getInstance("app_title.gif"); image.scalePercent(70); PdfPCell cell = new PdfPCell(image); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); Paragraph title = new Paragraph(text, FontFactory.getFont("arial", 12, Font.BOLD)); cell = new PdfPCell(title); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); image = Image.getInstance("title_shot.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); doc.add(table); table = new PdfPTable(1); table.setWidthPercentage(100); cell = new PdfPCell(); cell.setBackgroundColor(Color.BLACK); cell.setFixedHeight(1); table.addCell(cell); doc.add(table); }
From source file:test.itext.html.AimsPdf.java
License:Open Source License
public static void addScreenShorts(Document doc, String text) throws BadElementException, IOException, DocumentException { Paragraph heading = new Paragraph("Screenshots", FontFactory.getFont("arial", 10, Font.UNDERLINE | Font.BOLDITALIC)); heading.setSpacingAfter(12f);// www . j a v a2s . c o m doc.add(heading); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(80); table.setHorizontalAlignment(Element.ALIGN_CENTER); Image image = Image.getInstance("screen_shoot1.gif"); image.scalePercent(70); PdfPCell cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); image = Image.getInstance("screen_shoot2.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); image = Image.getInstance("screen_shoot3.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); image = Image.getInstance("screen_shoot4.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); image = Image.getInstance("screen_shoot5.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); image = Image.getInstance("screen_shoot6.gif"); image.scalePercent(70); cell = new PdfPCell(image); cell.setPadding(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); // doc.add(new Paragraph("\n")); doc.add(table); }
From source file:tk.diginspect.main.SoOFSignatories.java
private void Checked(PdfPTable table, int align, int checkmark) { try {/*ww w . j a v a2 s.c o m*/ ByteArrayOutputStream streamChecked = new ByteArrayOutputStream(); Bitmap Checked = BitmapFactory.decodeResource(getBaseContext().getResources(), checkmark); Checked.compress(Bitmap.CompressFormat.JPEG, 100, streamChecked); Image ImgChecked = null; ImgChecked = Image.getInstance(streamChecked.toByteArray()); ImgChecked.scalePercent(25f); PdfPCell cell = new PdfPCell(ImgChecked, false); cell.setHorizontalAlignment(align); cell.setPadding(5); cell.setBorder(0); table.addCell(cell); } catch (BadElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:tk.diginspect.main.SoOFSignatories.java
private void sig(PdfPTable table, String image) { try {//from ww w . j ava 2 s. co m FileInputStream fis = openFileInput(image); ByteArrayOutputStream stream = new ByteArrayOutputStream(); Bitmap bitmap = BitmapFactory.decodeStream(fis); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); Image Img = null; Img = Image.getInstance(stream.toByteArray()); Img.scalePercent(10f); PdfPCell cell = new PdfPCell(Img, false); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthBottom(0); table.addCell(cell); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } }