greenf Posted December 19, 2007 Share Posted December 19, 2007 I've try to create pdf from jrxml inside StringBuffer. I do it by converting Stringbuffer -> String -> bytes[] -> ByteArrayInputStream -> JasperCompileManager.compileReport( stream ) It creates balnk file. However, if I write stream to the file and try to convert file to pdf, it works fine. Is anybody can tell me what the reason of this.Code: byte[] bytes = buf.toString().getBytes(); InputStream stream = new ByteArrayInputStream( bytes ); //Convert stream to Jasper Report and JasperReport to PDF JasperReport jasperReport; JasperPrint jasperPrint; StringBuffer result; try { jasperReport = JasperCompileManager.compileReport( stream ); jasperPrint = JasperFillManager.fillReport( jasperReport, new HashMap(), new JREmptyDataSource() ); bytes = JasperExportManager.exportReportToPdf( jasperPrint ); result = new StringBuffer( new String( bytes) ); LOG.info( "Summary file created rn" ); } catch (JRException e) { result = new StringBuffer(); LOG.info( "Summary creation failed rn" + e ); } buf = new StringBuffer(); return result; Link to comment Share on other sites More sharing options...
Solution lucianc Posted December 19, 2007 Solution Share Posted December 19, 2007 PDF is a binary file format (and not a text file format), so converting the data to a String corrupts it. You need to keep the binary data as is, i.e. as a byte array. HTH,Lucian 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