longdv1208 Posted July 14, 2011 Share Posted July 14, 2011 public static byte [] compileToBinary() throws JRException, IOException{ byte [] binary=null; String pathFile="D:\NetBeans\jasperreport\web\template\template.jrxml"; String destFile="D:\NetBeans\jasperreport\web\template\webtest.html"; JasperReport report=JasperCompileManager.compileReport(pathFile); HashMap<Object,Object> hashMap=new ConstMap<Object, Object>(); hashMap.put("DEFAULT_PDF_FONT_NAME", "D:\NetBeans\jasperreport\web\times.ttf"); JasperPrint print=JasperFillManager.fillReport(report, hashMap, new JREmptyDataSource()); byte [] byteFile =JasperExportManager.exportReportToPdf(print); JasperExportManager.exportReportToHtmlFile(print, destFile); ByteArrayInputStream byinputStream=new ByteArrayInputStream(byteFile); InputStream inputStream=new BufferedInputStream(byinputStream); ByteArrayOutputStream outputStream =new ByteArrayOutputStream(); int b=-1; while((b=byinputStream.read())!=-1){ outputStream.write(b); } binary=outputStream.toByteArray(); inputStream.close(); return binary; }<body> <% byte [] data=CompileFile.compileToBinary(); response.setContentType("application/pdf"); response.setCharacterEncoding("UTF-8"); response.setHeader("Content-Disposition", "inline"); response.setContentLength(data.length); OutputStream outputStream=response.getOutputStream(); outputStream.write(data); outputStream.flush(); outputStream.close(); //LookAndFeelFactory.installDefaultLookAndFeel(); //JasperViewer.viewReport(CompileFile.getJasperPrint()); %> </body>type Exception reportmessagedescriptionThe server encountered an internal error () that prevented it from fulfilling this request.exceptionorg.apache.jasper.JasperException: net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : pdfFontName : times.ttfpdfEncoding : Identity-HisPdfEmbedded : falseroot causenet.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : pdfFontName : times.ttfpdfEncoding : Identity-HisPdfEmbedded : falsenote The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1 logs.Post Edited by longdv1208 at 07/14/2011 07:39 Link to comment Share on other sites More sharing options...
mdahlman Posted July 18, 2011 Share Posted July 18, 2011 Search on Font Extensions. You need font extensions to load fonts correctly.My article might help... but it's not targeted exactly at a JR developer like yourself.Regards,Matt 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