List of usage examples for com.itextpdf.layout Document add
@Override
public Document add(IBlockElement element)
From source file:com.js.quickestquail.ui.actions.io.ExportToPDFAction.java
private void writeAll(File outputFile) throws FileNotFoundException, IOException { // progress dialog JProgressDialog dialog = new JProgressDialog(UI.get(), false); dialog.setMaximum(DriveManager.get().getSelected().size()); dialog.setTitle(java.util.ResourceBundle.getBundle("i18n/i18n").getString("export.pdf")); dialog.setVisible(true);/*w w w . ja v a 2 s. c o m*/ // run this in a new Thread new Thread() { @Override public void run() { try { int nrOfMovies = 0; List<Entry<File, String>> entries = new ArrayList<>( DriveManager.get().getSelected().entrySet()); java.util.Collections.sort(entries, new Comparator<Entry<File, String>>() { @Override public int compare(Entry<File, String> o1, Entry<File, String> o2) { Movie mov1 = CachedMovieProvider.get().getMovieByID(o1.getValue()); Movie mov2 = CachedMovieProvider.get().getMovieByID(o2.getValue()); return mov1.getTitle().compareTo(mov2.getTitle()); } }); PdfWriter writer = new PdfWriter(new FileOutputStream(outputFile)); PdfDocument pdf = new PdfDocument(writer); Document doc = new Document(pdf); for (Entry<File, String> en : entries) { Movie mov = CachedMovieProvider.get().getMovieByID(en.getValue()); // update progress dialog dialog.setText(mov.getTitle()); dialog.setProgress(nrOfMovies); // add table Table table = new Table(new float[] { 0.5f, 0.25f, 0.25f }); table.setWidthPercent(100); table.setBorder(Border.NO_BORDER); Cell cell; cell = new Cell(5, 1); cell.setBorder(Border.NO_BORDER); try { Image img = new Image(ImageDataFactory.create(new URL(mov.getPoster()))); cell.setNextRenderer(new ImageBackgroundCellRenderer(cell, img)); } catch (Exception ex) { } cell.setHeight(160); cell.setWidth(100); table.addCell(cell); cell = new Cell(1, 1).add("Title").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add(mov.getTitle()).setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add("Year").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add(mov.getYear() + "").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add("IMDB ID").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add(mov.getImdbID()).setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add("IMDB Rating").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add(mov.getImdbRating() + "").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add("IMDB Votes").setBorder(Border.NO_BORDER); table.addCell(cell); cell = new Cell(1, 1).add(mov.getImdbVotes() + "").setBorder(Border.NO_BORDER); table.addCell(cell); doc.add(table); nrOfMovies++; if (nrOfMovies % 4 == 0) { doc.add(new AreaBreak()); } doc.add(new Paragraph("")); } // close IO doc.close(); pdf.close(); writer.close(); // close dialog dialog.setVisible(false); } catch (Exception ex) { } } }.start(); }
From source file:com.tcay.slalom.UI.PDF.PDF_Results.java
License:Open Source License
protected void manipulatePdf(String dest) throws Exception { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdfDoc); Table table = new Table(8); for (int i = 0; i < 16; i++) { table.addCell("hi"); }/*from w w w.j a v a 2 s . co m*/ doc.add(table); doc.close(); }
From source file:com.tcay.slalom.UI.PDF.PDF_Results.java
License:Open Source License
public void doit(String title, ArrayList<RaceRun> runs, boolean breakOnClassChange) { Document doc = null; Table table = null;/*from w w w . j ava 2 s. c o m*/ try { File file = new File(DEST); file.getParentFile().mkdirs(); // new PDF_Results().manipulatePdf(DEST); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(DEST)); //Document doc = new Document(pdfDoc); table = new Table(9); // # of columns // for (int i = 0; i < 16; i++) { // table.addCell("hi"); // } } catch (Exception e) { System.out.println(e); e.printStackTrace(); } String lastBoatClass = null; for (RaceRun r : runs) { float totalTime; if (breakOnClassChange) { if (lastBoatClass != null) { if (lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0) ; // log.info("---"); } lastBoatClass = r.getBoat().getBoatClass(); } totalTime = (float) r.getTotalPenalties(); totalTime += r.getElapsed(); } try { ArrayList<Result> sorted = Race.getInstance().getTempResults(); for (Result r : sorted) { if (true || breakOnClassChange) { //Fixme constant true if (lastBoatClass != null) { if (lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0) ; // output.newLine(); } if (lastBoatClass == null || lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0) { // output.write(r.getBoat().getBoatClass()); // output.newLine(); } lastBoatClass = r.getBoat().getBoatClass(); } String s1; // Cell cell23 = new Cell(1, 6).add("a Class ???multi 1,3 and 1,4"); // table.addCell(cell23); // table.startNewRow(); s1 = String.format("%1$3s", r.getBoat().getRacer().getBibNumber()); table.addCell(s1); String s = r.getBoat().getRacer().getShortName(); s1 = String.format("%1$-15s", s); table.addCell(s1); s1 = r.getRun1().getResultString(); table.addCell(s1); s1 = r.getRun1().getPenaltyString(); table.addCell(s1); s1 = r.getRun1().getTotalTimeString(); table.addCell(s1); if (r.getRun2() != null) { table.startNewRow(); table.addCell("."); table.addCell(".."); s1 = r.getRun2().getResultString(); table.addCell(s1); s1 = r.getRun2().getPenaltyString(); table.addCell(s1); s1 = r.getRun2().getTotalTimeString(); table.addCell(s1); } // else { // table.addCell("")//; //} table.startNewRow(); /// todo must integrate TH results before sort - DONE VERIFY 10/11/2013 // output.write(" best="); // s1 = r.getBestRun() != null ? r.getBestRun().formatTimeTotalOnly() : RaceRun.TIME_ONLY_FILL; // output.write(s1); // if (r.getBestRun().getPhotoCellRaceRun() != null) { /// todo must integrate TH results before sort // output.write(ResultsTable.TIMINGMODE_AUTOMATIC); // } // output.newLine(); } PdfFont f = PdfFontFactory.createFont(FontConstants.HELVETICA); Cell cell = new Cell(1, 3); cell.add(new Paragraph("Class K1 ... or whateever")).setFont(f).setFontSize(13) .setFontColor(DeviceGray.WHITE).setBackgroundColor(DeviceGray.BLACK); // .setTextAlignment(TextAlignment.CENTER); table.addHeaderCell(cell); /* for (int i = 0; i < 2; i++) { Cell[] headerFooter = new Cell[] { new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("#"), new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("Key"), new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("Value") }; for (Cell hfCell : headerFooter) { if (i == 0) { table.addHeaderCell(hfCell); } else { table.addFooterCell(hfCell); } } } for (int counter = 1; counter < 20; counter++) { table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add(String.valueOf(counter))); table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add("key " + counter)); table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add("value " + counter)); } */ doc.add(table); doc.close(); } catch (Exception e) { System.out.println(e); System.out.println(e.getStackTrace()); e.printStackTrace(); // log.write(e); } finally { try { // output.close(); } catch (Exception ex) { System.out.println(ex); System.out.println(ex.getStackTrace()); ex.printStackTrace(); } } }
From source file:controller.PasesDeCortesiaController.java
public void exportPDF() throws RemoteException, NotBoundException, FileNotFoundException, IOException { Registry reg = LocateRegistry.getRegistry(host, 27019); oasiscrud.oasisrimbd inter = (oasiscrud.oasisrimbd) reg.lookup("OasisSev"); FileChooser file = new FileChooser(); file.getExtensionFilters().add(new FileChooser.ExtensionFilter("Documento PDF", " *.pdf")); File f = file.showSaveDialog(null); PdfWriter writer = new PdfWriter(f.getAbsolutePath()); PdfDocument pdf = new PdfDocument(writer); pdf.setDefaultPageSize(PageSize.LETTER); Document document = new Document(pdf); com.itextpdf.layout.element.Image img = new com.itextpdf.layout.element.Image( ImageDataFactory.create(getClass().getResource("/images/pdf-logo.png"))); img.setHorizontalAlignment(HorizontalAlignment.CENTER); document.add(img); generaTitulo(document, "Lista de Pases de Cortesia"); document.add(new Paragraph("\n")); Table t = generaCabezera(Arrays.asList("Nombre", "Cedula", "Telefono", "Codigo", "Invitados", "Fecha")); document.add(t);/*from w w w .jav a2s. c om*/ for (int i = 0; i < tabla.getItems().size(); i++) { generaPaseCortesia(document, tabla.getItems().get(i)); white *= -1; } document.close(); }
From source file:controller.PasesDeCortesiaController.java
private void generaTitulo(Document document, String text) throws IOException { Table t = new Table(1); Cell c = new Cell(); c.setTextAlignment(TextAlignment.CENTER); c.setFont(PdfFontFactory.createRegisteredFont("times-italic")); c.setFontSize(18);/* w w w. j a v a2s . c om*/ c.setFontColor(Color.BLACK); c.add("\n"); c.add(text); c.setBorder(Border.NO_BORDER); c.setBorderBottom(new SolidBorder(Color.GRAY, 1)); t.addCell(c); document.add(t); }
From source file:controller.PasesDeCortesiaController.java
public void generaPaseCortesia(Document doc, PaseCortesia res) throws IOException { Table t = new Table(6); if (white < 0) { t.setBackgroundColor(Color.LIGHT_GRAY); }//from w ww. j a v a 2s.com t.addCell(generaCeldaNormal(res.nombre)); t.addCell(generaCeldaNormal(res.cedula)); t.addCell(generaCeldaNormal(res.telefono)); t.addCell(generaCeldaNormal(res.codigo)); t.addCell(generaCeldaNormal(res.invitados)); t.addCell(generaCeldaNormal(res.fecha)); doc.add(t); }
From source file:controller.ReporteDiarioController.java
public void generaPDF(ActionEvent evt) throws FileNotFoundException, MalformedURLException, IOException, RemoteException, NotBoundException { Registry reg = LocateRegistry.getRegistry(host, 27019); oasiscrud.oasisrimbd inter = (oasiscrud.oasisrimbd) reg.lookup("OasisSev"); FileChooser file = new FileChooser(); file.getExtensionFilters().add(new FileChooser.ExtensionFilter("Documento PDF", " *.PDF")); File f = file.showSaveDialog(null); PdfWriter writer = new PdfWriter(f.getAbsolutePath()); PdfDocument pdf = new PdfDocument(writer); pdf.setDefaultPageSize(PageSize.LETTER.rotate()); Document document = new Document(pdf); Cell c;/*from ww w. j a v a2s . c o m*/ Table tc; Paragraph p = new Paragraph(); Image img = new Image(ImageDataFactory.create(getClass().getResource("/images/pdf-logo.png"))); img.setHorizontalAlignment(HorizontalAlignment.CENTER); document.add(img); document.add(new Paragraph("\n")); tc = new Table(1); tc.addCell(generaCabezera("Reporte del dia " + date.getValue().getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault()) + " " + date.getValue().format(DateTimeFormatter.ISO_LOCAL_DATE))); document.add(tc); generaTitulo(document, "Detalles de asistencias General"); generaTablaAsistencia(document); pdf.addNewPage(); document.add(new AreaBreak()); generaTitulo(document, "Detalles de Aperturas de mesas"); generaTablaAperturaMesas(document); pdf.addNewPage(); document.add(new AreaBreak()); generaTitulo(document, "Detalles de Pases generados"); generaTablaPases(document); pdf.addNewPage(); document.add(new AreaBreak()); generaTitulo(document, "Detalles de Autorizaciones"); generaTablaAutorizaciones(document); pdf.addNewPage(); document.add(new AreaBreak()); generaTitulo(document, "Detalles de accesos al sistema"); generaTablaAcceso(document); pdf.addNewPage(); document.add(new AreaBreak()); generaTitulo(document, "Detalles de busquedas en el sistema"); generaTablaBusqueda(document); document.close(); System.out.println(f.getAbsolutePath()); close(evt); }
From source file:controller.ReporteDiarioController.java
private void generaTablaAsistencia(Document doc) throws IOException, RemoteException, NotBoundException { Registry reg = LocateRegistry.getRegistry(host, 27019); oasisrimbd inter = (oasisrimbd) reg.lookup("OasisSev"); ArrayList<Asistencia> asist = inter .asistenciaPorFecha(date.getValue().format(DateTimeFormatter.ISO_LOCAL_DATE)); ArrayList<Invitado> invad = inter.getInvitados(); List<String> ls = new ArrayList<>(); for (Asistencia o : asist) { ls.add(o.getContrato());/*from w w w . ja v a 2 s . c om*/ } invad.removeIf(r -> !(r.getFecha().equals(date.getValue().format(DateTimeFormatter.ISO_LOCAL_DATE)) && ls.contains(r.getContrato()))); int inv = 0, invadd = invad.size(); for (Asistencia a : asist) { inv += Integer.parseInt(a.getInvitados()); } Table tc = new Table(2); Cell c = new Cell(); c.setFont(PdfFontFactory.createRegisteredFont("times-italic")); c.setBorder(Border.NO_BORDER); c.add("\n"); c.add("Numero de titulares"); c.add("Numero de invitados"); c.add("Numero de invitados Adicionales"); c.add("\n"); tc.addCell(c); c = new Cell(); c.setFont(PdfFontFactory.createRegisteredFont("times-italic")); c.setBorder(Border.NO_BORDER); c.add("\n"); c.add(Integer.toString(asist.size())); c.add(Integer.toString(inv)); c.add(Integer.toString(invadd)); c.add("\n"); tc.addCell(c); doc.add(tc); ArrayList<String> l = new ArrayList<>( Arrays.asList("Cedula", "Cliente", "Contrato", "Plan", "Fecha", "Invitados", "Inv Adicionales")); tc = generaCabezera(l); doc.add(tc); for (Asistencia a : asist) { generaClienteAsistencia(doc, a); white *= -1; } }
From source file:controller.ReporteDiarioController.java
private void generaClienteAsistencia(Document doc, Asistencia asist) throws IOException, RemoteException, NotBoundException { Registry reg = LocateRegistry.getRegistry(host, 27019); oasisrimbd inter = (oasisrimbd) reg.lookup("OasisSev"); Cliente c = inter.clientePorContrato(asist.getContrato()); ArrayList<Invitado> inv = inter.getInvitados(); inv.removeIf(r -> !r.getContrato().equals(asist.getContrato())); Table tc = new Table(7); if (white < 0) { tc.setBackgroundColor(Color.LIGHT_GRAY); }//from w w w .j a v a2s . c o m tc.addCell(generaCeldaNormal(c.getCedula())); tc.addCell(generaCeldaNormal(c.getNombre())); tc.addCell(generaCeldaNormal(asist.getContrato())); tc.addCell(generaCeldaNormal(c.getPlan())); tc.addCell(generaCeldaNormal(asist.getFecha())); tc.addCell(generaCeldaNormal(asist.getInvitados())); tc.addCell(generaCeldaInvitados(inv)); doc.add(tc); }
From source file:controller.ReporteDiarioController.java
private void generaTitulo(Document document, String text) throws IOException { Table t = new Table(1); Cell c = new Cell(); c.setTextAlignment(TextAlignment.CENTER); c.setFont(PdfFontFactory.createRegisteredFont("times-italic")); c.setFontSize(16);//w ww. j a va 2 s . com c.setFontColor(Color.GRAY); c.add("\n"); c.add(text); c.setBorder(Border.NO_BORDER); t.addCell(c); document.add(t); }