List of usage examples for com.lowagie.text Image getInstance
public static Image getInstance(Image image)
From source file:candelaria.presentacion.beans.EmpleadoControlador.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();//from w ww. j a v a 2 s.c o m pdf.setPageSize(PageSize.A4); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "reportes" + File.separator + "empleados.png"; pdf.add(Image.getInstance(logo)); }
From source file:candelaria.presentacion.beans.MateriaPrimaControlador.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();// w w w. j a v a 2 s .co m pdf.setPageSize(PageSize.A4); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "reportes" + File.separator + "materiaprima.png"; pdf.add(Image.getInstance(logo)); }
From source file:candelaria.presentacion.beans.ProductoControlador.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();//from w ww. j a va 2 s.c o m pdf.setPageSize(PageSize.A4); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "reportes" + File.separator + "productos.png"; pdf.add(Image.getInstance(logo)); }
From source file:candelaria.presentacion.beans.ProveedorControlador.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();// www .j av a2 s . c om pdf.setPageSize(PageSize.A4); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "reportes" + File.separator + "proveedores.png"; pdf.add(Image.getInstance(logo)); }
From source file:ch.elexis.omnivore.data.DocHandle.java
License:Open Source License
public static List<DocHandle> assimilate(List<ImageData> images) { List<DocHandle> ret = new ArrayList<DocHandle>(); FileImportDialog fid = new FileImportDialog(Messages.DocHandle_scannedImageDialogCaption); if (fid.open() == Dialog.OK) { try {//from w ww . jav a 2 s .c om Document pdf = new Document(PageSize.A4); pdf.setMargins(0, 0, 0, 0); ByteArrayOutputStream baos = new ByteArrayOutputStream(100000); PdfWriter.getInstance(pdf, baos); pdf.open(); ImageLoader il = new ImageLoader(); for (int i = 0; i < images.size(); i++) { ImageData[] id = new ImageData[] { images.get(i) }; il.data = id; ByteArrayOutputStream bimg = new ByteArrayOutputStream(); il.save(bimg, SWT.IMAGE_PNG); Image image = Image.getInstance(bimg.toByteArray()); int width = id[0].width; int height = id[0].height; // 210mm = 8.27 In = 595 px bei 72dpi // 297mm = 11.69 In = 841 px if ((width > 595) || (height > 841)) { image.scaleToFit(595, 841); } pdf.add(image); } pdf.close(); DocHandle docHandle = new DocHandle(fid.category, baos.toByteArray(), ElexisEventDispatcher.getSelectedPatient(), fid.originDate, fid.title, "image.pdf", //$NON-NLS-1$ fid.keywords); ret.add(docHandle); } catch (Exception ex) { ExHandler.handle(ex); SWTHelper.showError(Messages.DocHandle_readError, Messages.DocHandle_readErrorText2); } } return ret; }
From source file:classroom.filmfestival_a.Movies06.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1//from ww w.ja v a2 s . c o m Document document = new Document(); try { // step 2 PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); File f; Image img; Paragraph p; Chunk c; Font bold = new Font(Font.HELVETICA, 12, Font.BOLD); Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC); for (FilmTitle movie : results) { f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg"); if (f.exists()) { img = Image.getInstance(f.getPath()); document.add(img); } p = new Paragraph(20); c = new Chunk(movie.getTitle(), bold); c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId()); p.add(c); c = new Chunk(" (" + movie.getYear() + ") ", italic); p.add(c); c = new Chunk("IMDB"); c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb()); p.add(c); document.add(p); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } document.add(list); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:classroom.filmfestival_a.Movies07.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1/* w w w .j a v a2s .com*/ Document document = new Document(); try { // step 2 OutputStream os = new FileOutputStream(RESULT); PdfWriter writer = PdfWriter.getInstance(document, os); writer.setStrictImageSequence(true); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); File f; Image img; Paragraph p; Chunk c; Font bold = new Font(Font.HELVETICA, 12, Font.BOLD); Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC); for (FilmTitle movie : results) { f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg"); if (f.exists()) { img = Image.getInstance(f.getPath()); document.add(img); } p = new Paragraph(20); c = new Chunk(movie.getTitle(), bold); c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId()); p.add(c); c = new Chunk(" (" + movie.getYear() + ") ", italic); p.add(c); c = new Chunk("IMDB"); c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb()); p.add(c); document.add(p); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } document.add(list); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:classroom.filmfestival_a.Movies08.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1// w w w.j av a2 s .c om Document document = new Document(); try { // step 2 OutputStream os = new FileOutputStream(RESULT); PdfWriter writer = PdfWriter.getInstance(document, os); writer.setStrictImageSequence(true); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); File f; Image img; Paragraph p; Chunk c; Font bold = new Font(Font.HELVETICA, 12, Font.BOLD); Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC); for (FilmTitle movie : results) { f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg"); if (f.exists()) { img = Image.getInstance(f.getPath()); img.scaleToFit(72, 144); document.add(img); } p = new Paragraph(20); c = new Chunk(movie.getTitle(), bold); c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId()); p.add(c); c = new Chunk(" (" + movie.getYear() + ") ", italic); p.add(c); c = new Chunk("IMDB"); c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb()); p.add(c); document.add(p); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } document.add(list); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:classroom.filmfestival_b.Movies09.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1//from www . j a v a 2 s .c om Document document = new Document(); try { // step 2 OutputStream os = new FileOutputStream(RESULT); PdfWriter writer = PdfWriter.getInstance(document, os); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); ColumnText column = new ColumnText(writer.getDirectContent()); column.setSimpleColumn(document.left(), document.bottom(), document.right(), document.top()); float pos; int status; File f; Image img; Paragraph p; Chunk c; Font bold = new Font(Font.HELVETICA, 12, Font.BOLD); Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC); for (FilmTitle movie : results) { f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg"); if (f.exists()) { img = Image.getInstance(f.getPath()); img.setWidthPercentage(0); img.scaleToFit(72, 144); } else { img = null; } p = new Paragraph(20); c = new Chunk(movie.getTitle(), bold); c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId()); p.add(c); c = new Chunk(" (" + movie.getYear() + ") ", italic); p.add(c); c = new Chunk("IMDB"); c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb()); p.add(c); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } if (img != null) column.addElement(img); column.addElement(p); column.addElement(list); pos = column.getYLine(); status = column.go(true); if (ColumnText.hasMoreText(status)) { document.newPage(); column.setText(null); column.setYLine(document.top()); } else { column.setYLine(pos); } if (img != null) column.addElement(img); column.addElement(p); column.addElement(list); column.addElement(Chunk.NEWLINE); column.go(); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:classroom.filmfestival_b.Movies10.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1/*from w w w. j a va 2 s .c om*/ Document document = new Document(); float middle = (document.right() + document.left()) / 2; float columns[][] = { { document.left(), document.bottom(), middle - 12, document.top() }, { middle + 12, document.bottom(), document.right(), document.top() } }; try { // step 2 OutputStream os = new FileOutputStream(RESULT); PdfWriter writer = PdfWriter.getInstance(document, os); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); ColumnText column = new ColumnText(writer.getDirectContent()); column.setSimpleColumn(columns[0][0], columns[0][1], columns[0][2], columns[0][3]); float pos; int status; int ccount = 0; File f; Image img; Paragraph p; Chunk c; Font bold = new Font(Font.HELVETICA, 12, Font.BOLD); Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC); for (FilmTitle movie : results) { f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg"); if (f.exists()) { img = Image.getInstance(f.getPath()); img.setWidthPercentage(0); img.scaleToFit(72, 144); } else { img = null; } p = new Paragraph(20); c = new Chunk(movie.getTitle(), bold); c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId()); p.add(c); c = new Chunk(" (" + movie.getYear() + ") ", italic); p.add(c); c = new Chunk("IMDB"); c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb()); p.add(c); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } if (img != null) column.addElement(img); column.addElement(p); column.addElement(list); pos = column.getYLine(); status = column.go(true); if (ColumnText.hasMoreText(status)) { column.setText(null); ccount++; if (ccount > 1) { ccount = 0; document.newPage(); column.setSimpleColumn(columns[0][0], columns[0][1], columns[0][2], columns[0][3]); } else { column.setSimpleColumn(columns[1][0], columns[1][1], columns[1][2], columns[1][3]); } } else { column.setYLine(pos); } if (img != null) column.addElement(img); column.addElement(p); column.addElement(list); column.addElement(Chunk.NEWLINE); column.go(); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }