List of usage examples for com.lowagie.text Image getInstance
public static Image getInstance(java.awt.Image image, java.awt.Color color) throws BadElementException, IOException
From source file:ambit.io.PDFWriter.java
License:Open Source License
public void writeMolecule(IMolecule molecule) { Object value;/*from ww w . j a va 2 s . c om*/ try { //give it a chance to create a header just before the first write if (!writingStarted) { if (header == null) setHeader(molecule.getProperties()); writeHeader(); writingStarted = true; } Paragraph p = new Paragraph(""); String s; for (int i = 0; i < header.size(); i++) { StringBuffer b = new StringBuffer(); b.append(header.getList().get(i)); b.append(" = "); value = molecule.getProperty(header.getList().get(i)); if (i == smilesIndex) { if (value == null) //no SMILES available try { value = ""; //sg.createSMILES(molecule); } catch (Exception x) { logger.error("Error while createSMILES\t", x.getMessage()); value = ""; } } if (value != null) { if (value instanceof Number) { s = value.toString(); } else { s = value.toString(); } b.append(s); p.add(new Paragraph(b.toString())); } } BufferedImage image = imageTools.getImage(molecule); image.flush(); Image png_struc = Image.getInstance(image, Color.white); png_struc.setAlignment(Image.LEFT); png_struc.scalePercent(100); PdfPCell cell = new PdfPCell(); cell.setMinimumHeight(cell.height()); cell.addElement(png_struc); table.addCell(cell); cell = new PdfPCell(p); cell.setBackgroundColor(Color.white); table.addCell(cell); } catch (Exception x) { logger.error("ERROR while writing Molecule: ", x.getMessage()); logger.debug(x); x.printStackTrace(); } }
From source file:ambit2.core.io.PDFWriter.java
License:Open Source License
public void writeMolecule(IMolecule molecule) { Object value;//ww w. j a v a 2 s. c om try { //give it a chance to create a header just before the first write if (!writingStarted) { if (header == null) setHeader(molecule.getProperties()); writeHeader(); writingStarted = true; } Paragraph p = new Paragraph(""); String s; for (int i = 0; i < header.size(); i++) { StringBuffer b = new StringBuffer(); b.append(header.get(i)); b.append(" = "); value = molecule.getProperty(header.get(i)); if (i == smilesIndex) { if (value == null) //no SMILES available try { value = ""; //sg.createSMILES(molecule); } catch (Exception x) { logger.log(Level.WARNING, "Error while createSMILES\t", x); value = ""; } } if (value != null) { if (value instanceof Number) { s = value.toString(); } else { s = value.toString(); } b.append(s); p.add(new Paragraph(b.toString())); } } BufferedImage image = imageTools.getImage(molecule); image.flush(); Image png_struc = Image.getInstance(image, Color.white); png_struc.setAlignment(Image.LEFT); png_struc.scalePercent(100); PdfPCell cell = new PdfPCell(); cell.setMinimumHeight(cell.height()); cell.addElement(png_struc); table.addCell(cell); cell = new PdfPCell(p); cell.setBackgroundColor(Color.white); table.addCell(cell); } catch (Exception x) { logger.log(Level.SEVERE, "Error while writing molecule", x); } }
From source file:ambit2.db.reporters.PDFReporter.java
protected void writeMolecule(IAtomContainer molecule) { Object value;/* w ww. j ava 2 s . c om*/ try { Paragraph p = new Paragraph(""); String s; for (Property property : header) { StringBuffer b = new StringBuffer(); b.append(property.getLabel()); b.append(" = "); value = molecule.getProperty(property); if (value != null) { if (value instanceof Number) { s = value.toString(); } else { s = value.toString(); } b.append(s); Chunk chunk = new Chunk(b.toString()); chunk.setFont(font); p.add(new Paragraph(chunk)); } } BufferedImage image = depict.getImage(molecule); image.flush(); Image png_struc = Image.getInstance(image, Color.white); png_struc.setAlignment(Image.LEFT); png_struc.scalePercent(100); PdfPCell cell = new PdfPCell(); cell.setMinimumHeight(cell.height()); cell.addElement(png_struc); table.addCell(cell); cell = new PdfPCell(p); cell.setBackgroundColor(Color.white); table.addCell(cell); } catch (Exception x) { logger.log(java.util.logging.Level.FINE, x.getMessage(), x); } }
From source file:ambit2.io.PDFWriter.java
License:Open Source License
public void writeMolecule(IMolecule molecule) { Object value;/*from w w w . j av a2s .co m*/ try { //give it a chance to create a header just before the first write if (!writingStarted) { if (header == null) setHeader(molecule.getProperties()); writeHeader(); writingStarted = true; } Paragraph p = new Paragraph(""); String s; for (int i = 0; i < header.size(); i++) { StringBuffer b = new StringBuffer(); b.append(header.get(i)); b.append(" = "); value = molecule.getProperty(header.get(i)); if (i == smilesIndex) { if (value == null) //no SMILES available try { value = ""; //sg.createSMILES(molecule); } catch (Exception x) { logger.error("Error while createSMILES\t", x.getMessage()); value = ""; } } if (value != null) { if (value instanceof Number) { s = value.toString(); } else { s = value.toString(); } b.append(s); p.add(new Paragraph(b.toString())); } } BufferedImage image = imageTools.getImage(molecule); image.flush(); Image png_struc = Image.getInstance(image, Color.white); png_struc.setAlignment(Image.LEFT); png_struc.scalePercent(100); PdfPCell cell = new PdfPCell(); cell.setMinimumHeight(cell.height()); cell.addElement(png_struc); table.addCell(cell); cell = new PdfPCell(p); cell.setBackgroundColor(Color.white); table.addCell(cell); } catch (Exception x) { logger.error("ERROR while writing Molecule: ", x.getMessage()); logger.debug(x); x.printStackTrace(); } }
From source file:br.com.nordestefomento.jrimum.bopepo.view.guia.ViewerPDF.java
License:Apache License
private void setLogoBanco() throws MalformedURLException, IOException, DocumentException { // Atravs da conta bancria ser descoberto a imagem que representa o // banco, com base // no cdigo do banco. Convenio convenio = guia.getArrecadacao().getConvenio(); Image imgLogoBanco = null;//from w w w .j av a2 s .c o m // Se h um banco especificado... if (isNotNull(convenio) && isNotNull(convenio.getBanco())) { if (isNotNull(convenio.getBanco().getImgLogo())) { imgLogoBanco = Image.getInstance(convenio.getBanco().getImgLogo(), null); setImageLogo(imgLogoBanco); } else { if (BancoSuportado .isSuportado(convenio.getBanco().getCodigoDeCompensacaoBACEN().getCodigoFormatado())) { URL url = new URL("file:///C:/tmp/img/" + convenio.getBanco().getCodigoDeCompensacaoBACEN().getCodigoFormatado() + ".png"); if (isNotNull(url)) { imgLogoBanco = Image.getInstance(url); } if (isNotNull(imgLogoBanco)) { // Esta imagem gerada aqui do tipo java.awt.Image convenio.getBanco().setImgLogo(ImageIO.read(url)); } // Se o banco em questo suportado nativamente pelo // componente, // ento um alerta ser exibido. if (log.isDebugEnabled()) { log.debug("Banco sem imagem da logo informada. " + "Com base no cdigo do banco, uma imagem foi " + "encontrada no resource e est sendo utilizada."); } setImageLogo(imgLogoBanco); } else { // Sem imagem, um alerta exibido. log.warn("Banco sem imagem definida. O nome da instituio ser usado como logo."); form.setField("txtLogoBanco", convenio.getBanco().getNome()); } } } }
From source file:br.com.nordestefomento.jrimum.bopepo.view.guia.ViewerPDF.java
License:Apache License
private void setLogoOrgaoRecebedor() throws MalformedURLException, IOException, DocumentException { Image imgLogoBanco = null;//from w w w .j a v a 2 s. c o m OrgaoRecebedor orgaoRecebedor = guia.getArrecadacao().getOrgaoRecebedor(); if (isNotNull(orgaoRecebedor.getImgLogo())) { imgLogoBanco = Image.getInstance(orgaoRecebedor.getImgLogo(), null); setImagemNoCampo("txtLogoOrgaoRecebedor1", imgLogoBanco); setImagemNoCampo("txtLogoOrgaoRecebedor2", imgLogoBanco); } }
From source file:br.com.nordestefomento.jrimum.bopepo.view.guia.ViewerPDF.java
License:Apache License
/** * <p>//from ww w. j a v a 2 s.co m * Coloca as imagens dos campos no pdf de acordo com o nome dos campos do * boleto atribudos no map e templante. * </p> * * @throws DocumentException * @throws IOException * * @since 0.2 */ private void setImagensNosCampos() throws DocumentException, IOException { if (isNotNull(guia.getImagensExtras())) { for (String campo : guia.getImagensExtras().keySet()) { setImagemNoCampo(campo, Image.getInstance(guia.getImagensExtras().get(campo), null)); } } }
From source file:br.com.nordestefomento.jrimum.bopepo.view.ViewerPDF.java
License:Apache License
private void setLogoBanco() throws MalformedURLException, IOException, DocumentException { // Atravs da conta bancria ser descoberto a imagem que representa o // banco, com base // no cdigo do banco. ContaBancaria conta = boleto.getTitulo().getContaBancaria(); Image imgLogoBanco = null;// ww w .j ava 2s. c om if (isNotNull(conta.getBanco().getImgLogo())) { imgLogoBanco = Image.getInstance(conta.getBanco().getImgLogo(), null); setImageLogo(imgLogoBanco); } else { if (BancoSuportado.isSuportado(conta.getBanco().getCodigoDeCompensacaoBACEN().getCodigoFormatado())) { URL url = this.getClass().getResource("/resource/img/" + conta.getBanco().getCodigoDeCompensacaoBACEN().getCodigoFormatado() + ".png"); if (isNotNull(url)) { imgLogoBanco = Image.getInstance(url); } if (isNotNull(imgLogoBanco)) { // Esta imagem gerada aqui do tipo java.awt.Image conta.getBanco().setImgLogo(ImageIO.read(url)); } // Se o banco em questo suportado nativamente pelo // componente, // ento um alerta ser exibido. if (log.isDebugEnabled()) { log.debug( "Banco sem imagem da logo informada. " + "Com base no cdigo do banco, uma imagem foi " + "encontrada no resource e est sendo utilizada."); } setImageLogo(imgLogoBanco); } else { // Sem imagem, um alerta exibido. log.warn("Banco sem imagem definida. O nome da instituio ser usado como logo."); form.setField("txtRsLogoBanco", conta.getBanco().getNome()); form.setField("txtFcLogoBanco", conta.getBanco().getNome()); } } }
From source file:br.com.nordestefomento.jrimum.bopepo.view.ViewerPDF.java
License:Apache License
/** * <p>//from w w w . jav a 2 s . co m * Coloca as imagens dos campos no pdf de acordo com o nome dos campos do boleto atribudos no map e templante. * </p> * * @throws DocumentException * @throws IOException * * @since 0.2 */ private void setImagensNosCampos() throws DocumentException, IOException { if (isNotNull(boleto.getImagensExtras())) { for (String campo : boleto.getImagensExtras().keySet()) { setImagemNoCampo(campo, Image.getInstance(boleto.getImagensExtras().get(campo), null)); } } }
From source file:com.estate.pdf.Page.java
protected void drawTaxPie(Rectangle rct, double totalValue, double tax, String taxLabel, String netLabel) { double taxPercent = (tax / totalValue) * 100; double netValuePercent = 100 - taxPercent; DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue(taxLabel, taxPercent); dataset.setValue(netLabel, netValuePercent); PiePlot3D plot = new PiePlot3D(dataset); plot.setLabelGenerator(new StandardPieItemLabelGenerator()); plot.setInsets(new Insets(0, 5, 5, 5)); plot.setToolTipGenerator(new CustomeGenerators.CustomToolTipGenerator()); plot.setLabelGenerator(new CustomeGenerators.CustomLabelGenerator()); plot.setSectionPaint(0, new Color(pgRed)); plot.setSectionPaint(1, new Color(pgGreen)); plot.setForegroundAlpha(.6f);//from www . ja va 2s . com plot.setOutlinePaint(Color.white); plot.setBackgroundPaint(Color.white); JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); chart.setAntiAlias(true); Rectangle page = rct; try { Image img = Image.getInstance(chart.createBufferedImage((int) page.getWidth(), (int) page.getHeight()), null); drawDiagram(img, rct, 0, 72); } catch (Exception e) { System.out.println(e.getMessage()); } }