2006 IR Open Discussion Posted August 19, 2006 Share Posted August 19, 2006 By: Chris Green - c_g12 UTF-8 encoding for HTML 2003-06-09 11:46 Hi Teodor, I've been using JasperReports to generate reports in PDF, HTML, and CSV. I need to be able to display international characters - basically every character in the Unicode spec. I noticed that when I generated HTML reports, some characters were displayed correctly, but some weren't. I took a look at the JRStringUtil.xmlEncode() method that you use to encode special characters. I found that the characters you encode using this method were the ones that were NOT appearing correctly on the exported HTML report. I needed to change my browser's encoding to Western European in order for them to show up correctly; because the exported report was declared to be UTF-8 encoded, this was what the browser was set to by default. I then changed the xmlEncode() method to simply encode the string to UTF-8, and this worked nicely - the characters in the exported report appeared correctly. Since the exported reports are declared to be UTF-8 encoded, why did you use HTML entities rather than UTF-8 encoding? Can I add my change to the JasperReports code? thanks, Chris Link to comment Share on other sites More sharing options...
krispyjala Posted June 6, 2007 Share Posted June 6, 2007 Anybody running into this problem too? I have set the encoding to ISO-8859-1 (though it could be UTF-8) and it is not converting to the correct characters: http://img504.imageshack.us/img504/6720/hipaa1le8.jpg%5B/IMG] I am not sure if it is related to the suggestion above. Any help would be greatly appreciated =) Thanks!Kris Post edited by: krispyjala, at: 2007/06/05 19:16 Post edited by: krispyjala, at: 2007/06/05 19:17Post edited by: krispyjala, at: 2007/06/05 19:18 Link to comment Share on other sites More sharing options...
krispyjala Posted June 6, 2007 Share Posted June 6, 2007 OK I found the solution on another thread (Thanks Teodor!) Apparently I need to check the box that says "Is Styled Text" and then it won't convert my & to & and display the unicode chars correctly. Here's the link to the original thread:http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=&func=view&catid=8&id=6928#6928 Sorry if I messed up this thread! (Doesn't seem like my problem had anything to do w/ the xmlParser util). Kris.Post edited by: krispyjala, at: 2007/06/05 21:34 Link to comment Share on other sites More sharing options...
zulubeba Posted September 14, 2011 Share Posted September 14, 2011 krispyjalaWrote: OK I found the solution on another thread (Thanks Teodor!) Apparently I need to check the box that says "Is Styled Text" and then it won't convert my & to & and display the unicode chars correctly. Here's the link to the original thread: http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=&func=view&catid=8&id=6928#6928 Sorry if I messed up this thread! (Doesn't seem like my problem had anything to do w/ the xmlParser util). Kris. Post edited by: krispyjala, at: 2007/06/05 21:34 Hello, I'm working with jasper 0.6.7, before print, i can see (HTML) the right display, but when I try to see the PDF, the chars were written unescaped: HTML: PDF: Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ Some chars are converted ok as well, like Ú, for example. I attached the screen format of the text field.I would see the same chars in HTML and PDF as well. Thanks and regards,Zulu.Code: public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse) throws ServletException, IOException { try { boolean novopdf = false; httpservletresponse.setContentType("application/pdf"); List vector = (List)httpservletrequest.getAttribute("dataBeanCollection"); JRBeanCollectionDataSource jrbeancollectiondatasource = null; if (null!=vector){ if (vector.get(0) instanceof RecuperarItensComposicaoPDFDTO){ if ("1".equals(httpservletrequest.getParameter("icSituacao"))){ novopdf =true; }else if (!"N".equals(httpservletrequest.getParameter("indItemSemPreco").trim())){ novopdf =true; } } ValidarColunaPdf validarColunaPdf = new ValidarColunaPdf(); jrbeancollectiondatasource = new JRBeanCollectionDataSource(validarColunaPdf.preencheListPDF(httpservletrequest,vector)); }else{ jrbeancollectiondatasource = new JRBeanCollectionDataSource(vector); SipciHelper.log.info("VETOR DO PDF NULL"); } Object obj = (Map)httpservletrequest.getAttribute("parameters"); if(obj == null){ obj = new HashMap(); } String s = SipciHelper.realPath; ((Map) (obj)).put("pathImagens", s); httpservletrequest.setAttribute("parameters", obj); String s1 = ""; if (novopdf){ s1 = "RecuperarItensComposicaoDetalheNovo.jasper"; }else{ s1 = httpservletrequest.getParameter("file"); } File file = new File((new StringBuilder()).append(s).append("/docroot/_report/").append(s1).toString()); JasperReport jasperreport = (JasperReport)JRLoader.loadObject(file); JasperPrint jasperprint; if(vector != null) { jasperprint = JasperFillManager.fillReport(jasperreport, ((Map) (obj)), jrbeancollectiondatasource); } else { JREmptyDataSource jremptydatasource = new JREmptyDataSource(); jasperprint = JasperFillManager.fillReport(jasperreport, ((Map) (obj)), jremptydatasource); } /*List<JRBasePrintPage> listajp = jasperprint.getPages(); for (JRBasePrintPage jp:listajp){ System.out.print(jp.getElements()); List<JRPrintElement> lstp = jp.getElements(); for (JRPrintElement jr:lstp){ jr. } }*/ ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); bytearrayoutputstream.write(JasperExportManager.exportReportToPdf(jasperprint)); httpservletresponse.setContentType("application/pdf"); httpservletresponse.setHeader("Content-Disposition", (new StringBuilder()).append("inline; filename=").append(file.toString()).toString()); httpservletresponse.setContentLength(bytearrayoutputstream.size()); ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream(); servletoutputstream.write(bytearrayoutputstream.toByteArray(), 0, bytearrayoutputstream.size()); servletoutputstream.flush(); servletoutputstream.close(); } catch(Exception exception) { if (exception.getCause() != null) { SipciHelper.log.fatal("Erro principal na criacao do PDF: " + exception.getCause(), exception.getCause()); } SipciHelper.log.fatal("Erro na criacao do PDF: " + exception, exception); throw new ServletException((new StringBuilder()).append("Erro na gera347343o do PDF: ").append(exception.getMessage()).toString()); } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now