Jump to content
We've recently updated our Privacy Statement, available here ×

pablodc

Members
  • Posts

    33
  • Joined

  • Last visited

 Content Type 

Profiles

Forum

Events

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Downloads

Everything posted by pablodc

  1. Hi, I'm using this method (fired by Quartz) to register new fonts (I'dont know if this method is compatible with the last release of JR): I also have a method to list the fonts. Hope this helps Good luck Code: public static HashMap<FontKey,PdfFont> fontMap = new HashMap<FontKey,PdfFont>(); private GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); /** * * Metodo para registrar las tipografias de la aplicacion en el sistema de * fuentes de AWT y dentro de las tipografias disponibles para la libreria * iText, utilizada por JasperReports para la exportacion de reportes en * formato PDF. * * @param fontfile nombre del archivo ttf de la tipografia que se desea * registrar. * @return devuelve un <code>boolean</code> indicando si se pudo * o no registrar la tipografia */ private boolean registerFont(String fontsdir, String fontfile) { /** registramos una tipografia propia en el sistema de tipografias de AWT/JAVA 2D con esto la ponemos disponible para que JasperReports pueda realizar sus calculos de altura y dimesiones para la impresion del documento. */ FileInputStream fis = null; boolean retval = false; String fullfontpath = fontsdir + File.separator + fontfile; String fontthumb = fontsdir + File.separator + FilenameUtils.getBaseName(fontfile) + "." + FontThumbs.IMAGEFORMATEXTENSION; FontKey key; PdfFont font; try { _log.info(sessionid +"registrando en AWT"); fis = new FileInputStream(fullfontpath); Font customFont = Font.createFont(Font.TRUETYPE_FONT, fis); ge.registerFont(customFont); _log.info(sessionid +"registrando en iText"); FontFactory.register(fullfontpath); _log.info(sessionid + "se logro registrar la tipografia <" + customFont.getFontName() + "> correspondiente a la familia <" + customFont.getFamily() + ">"); /** * actualizamos el parametro FONT_MAP que luego utilizara la clase * ReportExporter al exportar el reporte al formato PDF. */ key = new FontKey(customFont.getFontName(), false, false); font = new PdfFont(fullfontpath, "Cp1252", true); fontMap.put(key, font); retval = true; } catch (FontFormatException ex) { _log.error(sessionid + "se produjo un error al registrar la " + "tipografia <" + ex + ">"); ex.printStackTrace(); } catch (IOException ex) { _log.error(sessionid + "se produjo un error de E/S <" + ex + ">"); ex.printStackTrace(); } catch (Exception e) { _log.error(sessionid + "se produjo un error generico <" + e + ">"); e.printStackTrace(); } finally { try { fis.close(); } catch (IOException ex) { _log.error(sessionid + "se produjo un error al cerrar el " + "inputstream de la tipografia <" + ex + ">"); ex.printStackTrace(); } } return retval; } /** * metodo para listar las tipografias registradas en el sistema de AWT y * en la libreria iText que utiliza JasperReports para exportar los * reportes a PDF. */ public static void listFonts() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); _log.debug("=== inicio listado de tipografias del sistema ===>"); String[] fontNames = ge.getAvailableFontFamilyNames(); Font[] fontfiles = ge.getAllFonts(); for (int index = 0; index < fontNames.length; index++) { _log.debug("\t" + fontNames[index]); } _log.debug("\t*********************************************"); for (int index = 0; index < fontfiles.length; index++) { _log.debug("\t" + fontfiles[index].getFontName()); } _log.debug("<=== fin listado de tipografias del sistema ==="); _log.debug( "--- inicio listado de tipografias disponibles para iText --->"); for (Iterator i = FontFactory.getRegisteredFonts().iterator(); i.hasNext();) { _log.debug("\t" + (String) i.next()); } _log.debug( "<--- fin listado de tipografias disponibles para iText ---"); }
  2. Hi Haf, You can't sign PDF using JasperReports. You must export the report to PDF format and then use iText to sign them. You have examples at this URL to do that: http://itextpdf.sourceforge.net/howtosign.html Good luck!
  3. what if you copy the contents of PageFooter over LastPageFooter and remove the line?
  4. Hi, I have solved this problem using a method like the one posted in this reply. fontmap is a static HashMap in the class used later in the PDF exporter in this way: pdfexporter.setParameter(JRExporterParameter.FONT_MAP, FontRegister.fontMap); FontRegister is the class that contains the registerFont method. Take in consideration that this method needs java 1.6 due to the use of "registerFont" method to dinamically register the font. If you report design contain in the pdfFontName attribute a value like "font.ttf" the font.ttf must be placed in the webapp classpath: WEB-INF/lib or WEB-INF/classes (just place de fonts in the root, not in subfolders). If the weapp have a a custom font dir you must indicar in the pdfFontName (again, if the value is a ttf font file) the full path to this font. i.e: /home/user/fonts/arial.ttf Hope this helps someone. Forgive my bad english (is not my native language as you can read). Code: private boolean registerFont(String fontsdir, String fontfile) { FileInputStream fis = null; boolean retval = false; String fullfontpath = fontsdir + File.separator + fontfile; FontKey key; PdfFont font; try { _log.info(sessionid +"registering in AWT"); fis = new FileInputStream(fullfontpath); Font customFont = Font.createFont(Font.TRUETYPE_FONT, fis); ge.registerFont(customFont); _log.info(sessionid +"registering en iText"); FontFactory.register(fullfontpath); _log.info(sessionid + "se logro registrar la tipografia <" + customFont.getFontName() + "> correspondiente a la familia <" + customFont.getFamily() + ">"); /** * actualizamos el parametro FONT_MAP que luego utilizara la clase * ReportExporter al exportar el reporte al formato PDF. */ key = new FontKey(customFont.getFontName(), false, false); font = new PdfFont(fullfontpath, "Cp1252", true); fontMap.put(key, font); retval = true; } catch (FontFormatException ex) { _log.error(sessionid + "se produjo un error al registrar la " + "tipografia <" + ex + ">"); ex.printStackTrace(); } catch (IOException ex) { _log.error(sessionid + "se produjo un error de E/S <" + ex + ">"); ex.printStackTrace(); } catch (Exception e) { _log.error(sessionid + "se produjo un error generico <" + e + ">"); e.printStackTrace(); } finally { try { fis.close(); } catch (IOException ex) { _log.error(sessionid + "se produjo un error al cerrar el " + "inputstream de la tipografia <" + ex + ">"); ex.printStackTrace(); } } return retval; }
  5. Hi, I'm using a XML datasource in my report with this content: === starts here === <?xml version="1.0"?> <prices> <book> <title>Data on the Web</title> <source>www.bn.com</source> <price>39.12</price> </book> <book> <title>Data on the Web</title> <source>www.bn.com</source> <price>-39.43</price> </book> </prices> === ends here === And defined the field type for the tag "price" as java.lang.Float. But I have a problem: the negative number is displayed as "null" instead the value. What can I do?, if I change the field type to java.lang.Double the problem disappear. What I doing wrong? Thanks a lot for your help.
  6. Sorry. I have attached twice a subreport. I attach the second one to this response. Grettings
  7. Hi, I have a main report with two subreports. I need to use a return value from the first subreport as evaluation key in "Print when expression" in the second subreport. Basically the detail band have this +---------------------------+ | +-----------------+ | | | subreport 1 | | | +-----------------+ | | | <-- detail area from the main report | +-----------------+ | | | subreport 2 | | | +-----------------+ | +----------------------------+ I have created in the main report (who owns the detail area with the two subreports) a variable called "RETVAL" with a Calculation Type value of "System" and use this within the subreport1 to store the value returned in a variable called RETURN_VALUE in the second subreport. Then, in the "Print when expression" field from the second subreport I have used de RETVAL variable to limit the printing of this subreport. But, when I run my example the first rows returns a null value for the RETVAL var and the second the value of the first row, so the "Print When expression" is not working as expected. I have readed other topics about this , and tried some of the suggestions, but without any lucky. what I doing wrong? Thanks for any help and forgive by bad english, is not my mother language. PS: I have attached the full example: the main report, the two subreports and the datasource in XML used by the reports. Hope this help a little to understand the problem.
×
×
  • Create New...