csilva2001 Posted November 4, 2013 Share Posted November 4, 2013 Gentlemen, good evening. I have a strange problem. I have a code that generates multiple PDF files within the loop. Iterator it = repositorio.Iterator(); while(it.hasNext()) { conteudo ctd = (conteudo) it.next(); List lista = ctd.getLista(); String pdfFileName = ctd.getNomeArquivo; JasperPrint impressao = JasperFillManager.fillReport("relatorio.jasper", null, BCD); JasperExportManager.exportReportToPdfFile(impressao, pdfFileName); } Use this code to generate a forty files. But he always writes a smaller number. He 'jumps' some files, as if he had time to save the file. This same code outside of the loop is executed one by one, works great. There is no error msg. All lines are executed. But always fails to save some files. Has anyone experienced this? Can anyone help me? Using JasperReports 3.7 Thank you in advance. A hug Link to comment Share on other sites More sharing options...
Java_Jasper Posted November 4, 2013 Share Posted November 4, 2013 Are you opening and closing as well? Link to comment Share on other sites More sharing options...
csilva2001 Posted November 4, 2013 Author Share Posted November 4, 2013 Sorry. I do not understand your question. Opening and closing what? My code is this: Repositorio.Iterator iterator it = () / / a list of class content. Each class has different data for a report. while (it.hasNext ()) { ctd content = (content) it.next (); List lista = ctd.getLista(); // data for a report String pdfFileName = ctd.getNomeArquivo; // name of the pdf file of this report JRBeanCollectionDataSource BCD = new JRBeanCollectionDataSource (lista); JasperPrint impression JasperFillManager.fillReport = ("relatorio.jasper", null, BCD); JasperExportManager.exportReportToPdfFile (impression, pdfFileName) / / sometimes saves. Sometimes not } Do you have any help for me? Thanks in advance. a hug Link to comment Share on other sites More sharing options...
Java_Jasper Posted November 5, 2013 Share Posted November 5, 2013 Sorry, did not mean to be cryptic. I am refering to opening and closing of the PDF. Example: ByteArrayOutPutStrem byteArrayOuputStream = new ByteArrayOutputStream(); Jasper ExportManager.exportreprotToPdfStream(impression, pdfFileName); Your_Servlet_ect.write(byteArrayOutputStream.toByteArray(); Your_Servlet_ect.flush(); Your_Servlet_ect.close(); Your_Connection.close(); B. Link to comment Share on other sites More sharing options...
csilva2001 Posted November 5, 2013 Author Share Posted November 5, 2013 rs .. okay , my friend, ok... Sorry... pdfFileName is the full name of the pdf file ( c:folderrelatorio.pdf ) . I need to save to disk . I do not get the error message. But the file is not written . See this point : Iterator it = Repositorio.iterator ( ); / / a list of class content. Each class has different data for the report . while ( it.hasNext ()) { ctd content = ( content ) it.next ( ) ; List list = Ctd.getLista( ); / / data for the report PdfFileName String = ctd.getNomeArquivo; / / name of the pdf file of this report JRBeanCollectionDataSource BCD = new JRBeanCollectionDataSource(lista) ; JasperPrint impression JasperFillManager.fillReport = ( " relatorio.jasper " , null , BCD ) ; JasperExportManager.exportReportToPdfFile ( impression , pdfFileName ); / / Here I put a System.out.println ( " aquivo : " + pdfFileName ) // and see the file name in eclipse console , the filename . As if all was well . But the file is not written to disk. } When it is recorded..., I can open and close it . Any idea ? A hug . Link to comment Share on other sites More sharing options...
Java_Jasper Posted November 5, 2013 Share Posted November 5, 2013 A Hug, This is a classic copy and paste which will reformat your post. I kind of figured the pdfFileName was the path. I would recommend you set up the debugger and go through the entire flow. You may have a report or two that just dont work based on the data. B. Link to comment Share on other sites More sharing options...
csilva2001 Posted November 6, 2013 Author Share Posted November 6, 2013 my friend, you're right! ... There was an error. To avoid duplication, I deletava the file before writing a new one. The code to delete file had an error: exclude other files too. Now it's all right. I appreciate your attention, patience and sorry for my bad english ... lol ... Thanks anyway. A big hug Link to comment Share on other sites More sharing options...
Java_Jasper Posted November 7, 2013 Share Posted November 7, 2013 I am glad you found the error, don't forget to mark the correct answer for this post. B. 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