List of usage examples for com.lowagie.text Paragraph setAlignment
public void setAlignment(String alignment)
From source file:sms.ViewResults.java
private void itextPrint() { // String searchQuery = "SELECT * FROM `exam` WHERE `yearid` ='" + yearid + "'AND `termid`='"+termid+"'AND `examid`='"+yearid+"'" // + "AND CONCAT(`class`) LIKE '%" + stream + "%'AND YEAR(updated_at)='"+yearchooser.getYear()+"'"; methods nn = new methods(); 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 {// w ww . ja va 2s .co m Form1Exams n = new Form1Exams(); Document pdfp = new Document(); PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(), "report.pdf"))); pdfp.open(); 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; for (a = 0; a < names.length; a++) { String s = names[a]; tbl1.addCell(s.substring(0, Math.min(s.length(), 3))); } tbl1.addCell("Tot"); tbl1.addCell("Ave"); tbl1.addCell("Agg"); pdfp.add(tbl1); try { String[] Subjects = n.findSubjectid(); String[] Subjectsnames = n.findSubjectname(); int subjectCount = Subjects.length; ArrayList<ExamDbDataHolder> users = ListUsers(this.sid.getText()); for (int i = 0; i < users.size(); i++) { tbl.addCell(String.valueOf(i + 1)); String id = ((ExamDbDataHolder) users.get(i)).getSid(); String nam = nn.getStudentName(id); String name = "Eric"; tbl.addCell(id); tbl.addCell(nam); int c = 2; for (int s = 0; s < Subjects.length; s++) { if (Subjects[s].equals("s1")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMathematics()); // JOptionPane.showMessageDialog(null,((ExamDbDataHolder)users.get(i)).getMathematics()); // String maths = ((ExamDbDataHolder)users.get(i)).getMathematics(); c++; } else if (Subjects[s].equals("s2")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getEnglish()); //row[c] = ((ExamDbDataHolder)users.get(i)).getEnglish(); c++; } else if (Subjects[s].equals("s3")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getKiswahili()); // row[c] = ((ExamDbDataHolder)users.get(i)).getKiswahili(); c++; } else if (Subjects[s].equals("s4")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getPhysics()); // row[c] = ((ExamDbDataHolder)users.get(i)).getPhysics(); c++; } else if (Subjects[s].equals("s5")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getChemistry()); // row[c] = ((ExamDbDataHolder)users.get(i)).getChemistry(); c++; } else if (Subjects[s].equals("s6")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBiology()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBiology(); c++; } else if (Subjects[s].equals("s7")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHistory()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHistory(); c++; } else if (Subjects[s].equals("s8")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getGeography()); // row[c] = ((ExamDbDataHolder)users.get(i)).getGeography(); c++; } else if (Subjects[s].equals("s9")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getCre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getCre(); c++; } else if (Subjects[s].equals("s10")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getIre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getIre(); c++; } else if (Subjects[s].equals("s11")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHre(); c++; } else if (Subjects[s].equals("s12")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getAgriculture()); // row[c] = ((ExamDbDataHolder)users.get(i)).getAgriculture(); c++; } else if (Subjects[s].equals("s13")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHomescience()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHomescience(); c++; } else if (Subjects[s].equals("s14")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getArtdesign()); // row[c] = ((ExamDbDataHolder)users.get(i)).getArtdesign(); c++; } else if (Subjects[s].equals("s15")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getComputer()); // row[c] = ((ExamDbDataHolder)users.get(i)).getComputer(); c++; } else if (Subjects[s].equals("s16")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBuilding()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBuilding(); c++; } else if (Subjects[s].equals("s17")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getWoodwork()); // row[c] = ((ExamDbDataHolder)users.get(i)).getWoodwork(); c++; } else if (Subjects[s].equals("s18")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMetalwork()); // row[c] = ((ExamDbDataHolder)users.get(i)).getMetalwork(); c++; } else if (Subjects[s].equals("s19")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMusic()); // row[c] = ((ExamDbDataHolder)users.get(i)).getMusic(); c++; } else if (Subjects[s].equals("s20")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getFrench()); // row[c] = ((ExamDbDataHolder)users.get(i)).getFrench(); c++; } else if (Subjects[s].equals("s21")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getGerman()); // row[c] = ((ExamDbDataHolder)users.get(i)).getGerman(); c++; } else if (Subjects[s].equals("s22")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getArabic()); // row[c] = ((ExamDbDataHolder)users.get(i)).getArabic(); c++; } else if (Subjects[s].equals("s23")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBusiness()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBusiness(); c++; } } int tt = ((ExamDbDataHolder) users.get(i)).getTotal(); tbl.addCell(String.valueOf(tt)); float g = Float.valueOf(tt) / 11; tbl.addCell(String.format("%.1f", g)); String gr = nn.checkGrade(yearid, String.format("%.1f", g)); tbl.addCell(gr); } pdfp.add(tbl); } catch (Exception j) { j.printStackTrace(); } pdfp.close(); // Image img=new Image.getInstance("j.png"); } catch (DocumentException ex) { Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:storemanagment.Printing.java
public PdfPCell createTextCellNb(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_CENTER); p.add(text);//www . j a va 2 s . co m cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Rectangle.NO_BORDER); return cell; }
From source file:storemanagment.Printing.java
public PdfPCell createTextCell(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, java.awt.Font.BOLD)); // p.setFont(Font.BOLD); p.setAlignment(Element.ALIGN_CENTER); p.add(text);//from www . j a va 2s .co m cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Rectangle.NO_BORDER); return cell; }
From source file:storemanagment.Printing.java
public PdfPCell createTextCellNormal(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); // p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,16,java.awt.Font.BOLD)); // p.setFont(Font.BOLD); p.setAlignment(Element.ALIGN_CENTER); p.add(text);/* w w w . j a va 2s . c om*/ cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Rectangle.NO_BORDER); return cell; }
From source file:storemanagment.Printing.java
public PdfPCell createTextCellNormalUnderlined(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); // p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,16,java.awt.Font.BOLD)); // p.setFont(Font.BOLD); p.setAlignment(Element.ALIGN_CENTER); p.add(text);/* ww w .j av a2 s.c o m*/ cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Rectangle.NO_BORDER); return cell; }
From source file:subcentro_licto.presentacion.beans.DatosBuscadorBean.java
public void imprimirDatos() { //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL); try {/* ww w. j av a2s . com*/ //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:tufts.vue.PresentationNotes.java
License:Educational Community License
public static void createSpeakerNotes4PerPage(File file) { //page size notes: //martin-top,left,right,bottom = 36 //widht :612//from w ww . j av a2s .c om //height : 792 //usable space 540 x 720 // step 1: creation of a document-object Document document = new Document(PageSize.LETTER); try { GUI.activateWaitCursor(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); // writer.setDefaultColorspace(PdfName.DEFAULTRGB, null); // writer.setStrictImageSequence(true); // step 3: we open the document document.open(); PdfPTable table; PdfPCell cell; int entryCount = 0; int entryOnPage = 0; int currentIndex = VUE.getActivePathway().getIndex(); VUE.getActivePathway().setIndex(-1); for (LWPathway.Entry entry : VUE.getActivePathway().getEntries()) { final LWSlide slide = entry.produceSlide(); final LWComponent toDraw = (slide == null ? entry.node : slide); final String notes = entry.getNotes(); entryCount++; table = new PdfPTable(new float[] { 1, 1 }); table.getDefaultCell().setBorder(0); //table.getDefaultCell().setPaddingBottom(50.0f); table.setSpacingAfter(20.0f); Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_CENTER); Phrase phrase = new Phrase(notes); Font f = phrase.getFont(); f.setSize(8.0f); p.setFont(f); cell = new PdfPCell(phrase); cell.setBorder(0); PdfPCell i2 = new PdfPCell(); i2.setFixedHeight(172); i2.setBorder(0); //Render the table then throw the images on PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(SlideSizeX, SlideSizeY); Point2D.Float offset = new Point2D.Float(); // center vertically only if landscape mode //if (format.getOrientation() == PageFormat.LANDSCAPE) //TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit) Rectangle2D bounds = null; //if (!entry.isMapView()) bounds = slide.getBounds(); //else //bounds = entry.getFocal().getBounds(); Dimension page = null; page = new Dimension(SlideSizeX, 172); //PdfTemplate tp = cb.createTemplate(document.getPageSize().width()-80, document.getPageSize().height()-80); double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true); PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(SlideSizeX, SlideSizeY, getFontMapper(), false, 60.0f); DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle entry.isMapView() ? entry.getFocal() : slide, false); // todo: absolute links shouldn't be spec'd here dc.setClipOptimized(false); dc.setPrintQuality(); /*if (!entry.isMapView()) slide.drawZero(dc); else { entry.getFocal().draw(dc); }*/ toDraw.drawFit(dc, 0); g2d.dispose(); //document.add(Image.getInstance(tp)); // int position = cell. // drawSequenceNumber(writer,36,position+203,entryCount); // cb.addTemplate(tp,56, position); Image img = Image.getInstance(tp); table.addCell(img); table.addCell(cell); p.add(table); document.add(p); } VUE.getActivePathway().setIndex(currentIndex); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } finally { GUI.clearWaitCursor(); } // step 5: we close the document document.close(); }
From source file:tufts.vue.PresentationNotes.java
License:Educational Community License
public static void createNodeNotes4PerPage(File file) { //page size notes: //martin-top,left,right,bottom = 36 //widht :612/*w w w . j a v a 2 s. com*/ //height : 792 //usable space 540 x 720 // step 1: creation of a document-object Document document = new Document(PageSize.LETTER); try { GUI.activateWaitCursor(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); // writer.setDefaultColorspace(PdfName.DEFAULTRGB, null); // writer.setStrictImageSequence(true); // step 3: we open the document document.open(); PdfPTable table; PdfPCell cell; int entryCount = 0; int entryOnPage = 0; Iterator i = VUE.getActiveMap().getAllDescendents(LWComponent.ChildKind.PROPER).iterator(); while (i.hasNext()) { LWComponent component = (LWComponent) i.next(); if (component instanceof LWNode) { final LWNode node = (LWNode) component; final String notes = node.getNotes(); entryCount++; table = new PdfPTable(new float[] { 1, 1 }); table.getDefaultCell().setBorder(0); table.setSpacingAfter(20.0f); Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_CENTER); Phrase phrase = new Phrase(notes); Font f = phrase.getFont(); f.setSize(8.0f); p.setFont(f); cell = new PdfPCell(phrase); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setBorder(0); PdfPCell i2 = new PdfPCell(); i2.setFixedHeight(172); i2.setBorder(0); //Render the table then throw the images on PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(SlideSizeX, SlideSizeY); Point2D.Float offset = new Point2D.Float(); //center vertically only if landscape mode //if (format.getOrientation() == PageFormat.LANDSCAPE) //TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit) Rectangle2D bounds = null; bounds = node.getBounds(); Dimension page = null; page = new Dimension(SlideSizeX, 172); // PdfTemplate tp = cb.createTemplate(document.getPageSize().width()-80, document.getPageSize().height()-80); double scale = ZoomTool.computeZoomFit(page, 15, bounds, offset, true); PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(SlideSizeX, SlideSizeY, getFontMapper(), false, 60.0f); DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle node, false); // todo: absolute links shouldn't be spec'd here dc.setClipOptimized(false); dc.setPrintQuality(); node.drawFit(dc, 15); g2d.dispose(); Image img = Image.getInstance(tp); table.addCell(img); table.addCell(cell); p.add(table); document.add(p); } } } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } finally { GUI.clearWaitCursor(); } // step 5: we close the document document.close(); }
From source file:uk.ac.ox.oucs.vle.resources.PDFWriter.java
License:Educational Community License
public void writeHead(Collection<CourseGroup> courseGroups, CourseComponent courseComponent) throws IOException { try {/*from w ww. jav a 2s. c om*/ Paragraph paragraph; Phrase phrase; // Title paragraph = new Paragraph(); for (CourseGroup courseGroup : courseGroups) { phrase = new Phrase("\n" + courseGroup.getTitle(), titleFont); paragraph.add(phrase); } paragraph.setAlignment(Element.ALIGN_CENTER); document.add(paragraph); // Component paragraph = new Paragraph(); phrase = new Phrase("\nComponent: " + courseComponent.getTitle(), authorFont); paragraph.add(phrase); paragraph.setIndentationLeft(25); paragraph.setIndentationRight(25); paragraph.setAlignment(Element.ALIGN_LEFT); document.add(paragraph); // Presenter paragraph = new Paragraph(); Person presenter = courseComponent.getPresenter(); phrase = new Phrase("\nPresenter: " + ((presenter == null) ? "" : presenter.getName()), authorFont); paragraph.add(phrase); paragraph.setIndentationLeft(25); paragraph.setIndentationRight(25); paragraph.setAlignment(Element.ALIGN_LEFT); document.add(paragraph); // Date paragraph = new Paragraph(); phrase = new Phrase("Date/Time: ...........................................", infoFont); paragraph.add(phrase); paragraph.setIndentationLeft(25); paragraph.setIndentationRight(25); document.add(paragraph); // info paragraph = new Paragraph(); phrase = new Phrase("Please sign to confirm that you have attended this session", infoFont); paragraph.add(phrase); paragraph.setIndentationLeft(25); paragraph.setIndentationRight(25); paragraph.setAlignment(Element.ALIGN_LEFT); document.add(paragraph); } catch (DocumentException e) { throw new IOException("Unable to write Document Header."); } }
From source file:uk.ac.ox.oucs.vle.resources.PDFWriter.java
License:Educational Community License
public void writeTableFoot() throws IOException { try {//from w w w . ja v a 2s. com for (int i = 0; i < 5; i++) { table.addCell(nameCell("", "", "")); table.addCell(""); } Paragraph paragraph = new Paragraph(); paragraph.add(table); paragraph.setAlignment(Element.ALIGN_CENTER); document.add(paragraph); } catch (DocumentException e) { throw new IOException("Unable to write Document table."); } }