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

Help, JasperReports not save file


csilva2001

Recommended Posts

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

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...