Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Empty PDF report downloaded as attachment from BIRT enabled web application
Empty PDF report downloaded as attachment from BIRT enabled web application [message #676064] Thu, 02 June 2011 12:51 Go to next message
Eclipse User
Originally posted by: msotomayor

Hello:

I built a web application that uses the RE API to generate reports as
PDF files. The web application generates the report correctly but saves
it in another file.

I need the web application to ask the user for the location were to
download the file. However, when the user specifies the file name to
use and the desired location, the browser actually creates two files.
The file the user wants is created empty and the file with the actual
report contents is created in the home folder named as "report.pdf".

I'm using the following code to tell the browser to download the file as
an attachment:

/*************************************/

String headerValue =
String.format( "attachment; filename=%s", reportFileName);
response.setHeader( "Content-Disposition", headerValue );
response.setContentType( "application/pdf" );

/*************************************/


I'm I missing something?


Thanks,
Re: Empty PDF report downloaded as attachment from BIRT enabled web application [message #676065 is a reply to message #676064] Thu, 02 June 2011 12:58 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

I have done it like:

resp.setContentType( "application/pdf" );
resp.setHeader ("Content-Disposition","inline; filename=test.pdf");


and in the PDFRenderOption I put:

options.setOutputStream(resp.getOutputStream());

Jason

On 6/2/2011 12:51 PM, msotomayor wrote:
> Hello:
>
> I built a web application that uses the RE API to generate reports as
> PDF files. The web application generates the report correctly but saves
> it in another file.
>
> I need the web application to ask the user for the location were to
> download the file. However, when the user specifies the file name to use
> and the desired location, the browser actually creates two files. The
> file the user wants is created empty and the file with the actual report
> contents is created in the home folder named as "report.pdf".
>
> I'm using the following code to tell the browser to download the file as
> an attachment:
>
> /*************************************/
>
> String headerValue =
> String.format( "attachment; filename=%s", reportFileName);
> response.setHeader( "Content-Disposition", headerValue );
> response.setContentType( "application/pdf" );
>
> /*************************************/
>
>
> I'm I missing something?
>
>
> Thanks,
Re: Empty PDF report downloaded as attachment from BIRT enabled web application [message #676090 is a reply to message #676065] Thu, 02 June 2011 15:08 Go to previous messageGo to next message
Eclipse User
Originally posted by: msotomayor

Hi Jason:

Thank you for replying.

That certainly works, but the call:

> options.setOutputStream(resp.getOutputStream());

causes the document to open within the browser.


What I really need is the browser to open the save as dialog without
displaying the contents of the report. If I comment that call, the
dialog is opened but the two files are created, the desired by the user
empty and another one called "report.pdf" with the actual contents.


Any other ideas?



On 06/02/2011 12:58 PM, Jason Weathersby wrote:
> I have done it like:
>
> resp.setContentType( "application/pdf" );
> resp.setHeader ("Content-Disposition","inline; filename=test.pdf");
>
>
> and in the PDFRenderOption I put:
>
> options.setOutputStream(resp.getOutputStream());
>
> Jason
>
> On 6/2/2011 12:51 PM, msotomayor wrote:
>> Hello:
>>
>> I built a web application that uses the RE API to generate reports as
>> PDF files. The web application generates the report correctly but saves
>> it in another file.
>>
>> I need the web application to ask the user for the location were to
>> download the file. However, when the user specifies the file name to use
>> and the desired location, the browser actually creates two files. The
>> file the user wants is created empty and the file with the actual report
>> contents is created in the home folder named as "report.pdf".
>>
>> I'm using the following code to tell the browser to download the file as
>> an attachment:
>>
>> /*************************************/
>>
>> String headerValue =
>> String.format( "attachment; filename=%s", reportFileName);
>> response.setHeader( "Content-Disposition", headerValue );
>> response.setContentType( "application/pdf" );
>>
>> /*************************************/
>>
>>
>> I'm I missing something?
>>
>>
>> Thanks,
>
Re: Empty PDF report downloaded as attachment from BIRT enabled web application [message #676117 is a reply to message #676090] Thu, 02 June 2011 16:18 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Put that line back in ad change the content disposition to use attachment.
resp.setHeader("Content-disposition","attachment; filename=\""
+"test.pdf" +"\"");

Jason

On 6/2/2011 3:08 PM, msotomayor wrote:
> Hi Jason:
>
> Thank you for replying.
>
> That certainly works, but the call:
>
> > options.setOutputStream(resp.getOutputStream());
>
> causes the document to open within the browser.
>
>
> What I really need is the browser to open the save as dialog without
> displaying the contents of the report. If I comment that call, the
> dialog is opened but the two files are created, the desired by the user
> empty and another one called "report.pdf" with the actual contents.
>
>
> Any other ideas?
>
>
>
> On 06/02/2011 12:58 PM, Jason Weathersby wrote:
>> I have done it like:
>>
>> resp.setContentType( "application/pdf" );
>> resp.setHeader ("Content-Disposition","inline; filename=test.pdf");
>>
>>
>> and in the PDFRenderOption I put:
>>
>> options.setOutputStream(resp.getOutputStream());
>>
>> Jason
>>
>> On 6/2/2011 12:51 PM, msotomayor wrote:
>>> Hello:
>>>
>>> I built a web application that uses the RE API to generate reports as
>>> PDF files. The web application generates the report correctly but saves
>>> it in another file.
>>>
>>> I need the web application to ask the user for the location were to
>>> download the file. However, when the user specifies the file name to use
>>> and the desired location, the browser actually creates two files. The
>>> file the user wants is created empty and the file with the actual report
>>> contents is created in the home folder named as "report.pdf".
>>>
>>> I'm using the following code to tell the browser to download the file as
>>> an attachment:
>>>
>>> /*************************************/
>>>
>>> String headerValue =
>>> String.format( "attachment; filename=%s", reportFileName);
>>> response.setHeader( "Content-Disposition", headerValue );
>>> response.setContentType( "application/pdf" );
>>>
>>> /*************************************/
>>>
>>>
>>> I'm I missing something?
>>>
>>>
>>> Thanks,
>>
>
Re: Empty PDF report downloaded as attachment from BIRT enabled web application [message #676118 is a reply to message #676117] Thu, 02 June 2011 17:14 Go to previous messageGo to next message
Eclipse User
Originally posted by: msotomayor

Thanks again, but it didn't worked neither.

Should I use a ByteArrayOutputStream?



On 06/02/2011 04:18 PM, Jason Weathersby wrote:
> Put that line back in ad change the content disposition to use attachment.
> resp.setHeader("Content-disposition","attachment; filename=\""
> +"test.pdf" +"\"");
>
> Jason
>
> On 6/2/2011 3:08 PM, msotomayor wrote:
>> Hi Jason:
>>
>> Thank you for replying.
>>
>> That certainly works, but the call:
>>
>> > options.setOutputStream(resp.getOutputStream());
>>
>> causes the document to open within the browser.
>>
>>
>> What I really need is the browser to open the save as dialog without
>> displaying the contents of the report. If I comment that call, the
>> dialog is opened but the two files are created, the desired by the user
>> empty and another one called "report.pdf" with the actual contents.
>>
>>
>> Any other ideas?
>>
>>
>>
>> On 06/02/2011 12:58 PM, Jason Weathersby wrote:
>>> I have done it like:
>>>
>>> resp.setContentType( "application/pdf" );
>>> resp.setHeader ("Content-Disposition","inline; filename=test.pdf");
>>>
>>>
>>> and in the PDFRenderOption I put:
>>>
>>> options.setOutputStream(resp.getOutputStream());
>>>
>>> Jason
>>>
>>> On 6/2/2011 12:51 PM, msotomayor wrote:
>>>> Hello:
>>>>
>>>> I built a web application that uses the RE API to generate reports as
>>>> PDF files. The web application generates the report correctly but saves
>>>> it in another file.
>>>>
>>>> I need the web application to ask the user for the location were to
>>>> download the file. However, when the user specifies the file name to
>>>> use
>>>> and the desired location, the browser actually creates two files. The
>>>> file the user wants is created empty and the file with the actual
>>>> report
>>>> contents is created in the home folder named as "report.pdf".
>>>>
>>>> I'm using the following code to tell the browser to download the
>>>> file as
>>>> an attachment:
>>>>
>>>> /*************************************/
>>>>
>>>> String headerValue =
>>>> String.format( "attachment; filename=%s", reportFileName);
>>>> response.setHeader( "Content-Disposition", headerValue );
>>>> response.setContentType( "application/pdf" );
>>>>
>>>> /*************************************/
>>>>
>>>>
>>>> I'm I missing something?
>>>>
>>>>
>>>> Thanks,
>>>
>>
>
Re: Empty PDF report downloaded as attachment from BIRT enabled web application [message #676270 is a reply to message #676118] Fri, 03 June 2011 09:04 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

I just tried this and it worked for me. Where is it dropping the second
file?

Jason

On 6/2/2011 5:14 PM, msotomayor wrote:
> Thanks again, but it didn't worked neither.
>
> Should I use a ByteArrayOutputStream?
>
>
>
> On 06/02/2011 04:18 PM, Jason Weathersby wrote:
>> Put that line back in ad change the content disposition to use
>> attachment.
>> resp.setHeader("Content-disposition","attachment; filename=\""
>> +"test.pdf" +"\"");
>>
>> Jason
>>
>> On 6/2/2011 3:08 PM, msotomayor wrote:
>>> Hi Jason:
>>>
>>> Thank you for replying.
>>>
>>> That certainly works, but the call:
>>>
>>> > options.setOutputStream(resp.getOutputStream());
>>>
>>> causes the document to open within the browser.
>>>
>>>
>>> What I really need is the browser to open the save as dialog without
>>> displaying the contents of the report. If I comment that call, the
>>> dialog is opened but the two files are created, the desired by the user
>>> empty and another one called "report.pdf" with the actual contents.
>>>
>>>
>>> Any other ideas?
>>>
>>>
>>>
>>> On 06/02/2011 12:58 PM, Jason Weathersby wrote:
>>>> I have done it like:
>>>>
>>>> resp.setContentType( "application/pdf" );
>>>> resp.setHeader ("Content-Disposition","inline; filename=test.pdf");
>>>>
>>>>
>>>> and in the PDFRenderOption I put:
>>>>
>>>> options.setOutputStream(resp.getOutputStream());
>>>>
>>>> Jason
>>>>
>>>> On 6/2/2011 12:51 PM, msotomayor wrote:
>>>>> Hello:
>>>>>
>>>>> I built a web application that uses the RE API to generate reports as
>>>>> PDF files. The web application generates the report correctly but
>>>>> saves
>>>>> it in another file.
>>>>>
>>>>> I need the web application to ask the user for the location were to
>>>>> download the file. However, when the user specifies the file name to
>>>>> use
>>>>> and the desired location, the browser actually creates two files. The
>>>>> file the user wants is created empty and the file with the actual
>>>>> report
>>>>> contents is created in the home folder named as "report.pdf".
>>>>>
>>>>> I'm using the following code to tell the browser to download the
>>>>> file as
>>>>> an attachment:
>>>>>
>>>>> /*************************************/
>>>>>
>>>>> String headerValue =
>>>>> String.format( "attachment; filename=%s", reportFileName);
>>>>> response.setHeader( "Content-Disposition", headerValue );
>>>>> response.setContentType( "application/pdf" );
>>>>>
>>>>> /*************************************/
>>>>>
>>>>>
>>>>> I'm I missing something?
>>>>>
>>>>>
>>>>> Thanks,
>>>>
>>>
>>
>
Re: Empty PDF report downloaded as attachment from BIRT enabled web application [message #676312 is a reply to message #676270] Fri, 03 June 2011 11:31 Go to previous messageGo to next message
Eclipse User
Originally posted by: msotomayor

The second file (which contains the actual contents of the report) is
automatically named as "report.pdf" and is dropped at the user's home
folder. I noticed that this file is created before the one that the
user specifies in the save as dialog.


On 06/03/2011 09:04 AM, Jason Weathersby wrote:
> I just tried this and it worked for me. Where is it dropping the second
> file?
>
> Jason
>
> On 6/2/2011 5:14 PM, msotomayor wrote:
>> Thanks again, but it didn't worked neither.
>>
>> Should I use a ByteArrayOutputStream?
>>
>>
>>
>> On 06/02/2011 04:18 PM, Jason Weathersby wrote:
>>> Put that line back in ad change the content disposition to use
>>> attachment.
>>> resp.setHeader("Content-disposition","attachment; filename=\""
>>> +"test.pdf" +"\"");
>>>
>>> Jason
>>>
>>> On 6/2/2011 3:08 PM, msotomayor wrote:
>>>> Hi Jason:
>>>>
>>>> Thank you for replying.
>>>>
>>>> That certainly works, but the call:
>>>>
>>>> > options.setOutputStream(resp.getOutputStream());
>>>>
>>>> causes the document to open within the browser.
>>>>
>>>>
>>>> What I really need is the browser to open the save as dialog without
>>>> displaying the contents of the report. If I comment that call, the
>>>> dialog is opened but the two files are created, the desired by the user
>>>> empty and another one called "report.pdf" with the actual contents.
>>>>
>>>>
>>>> Any other ideas?
>>>>
>>>>
>>>>
>>>> On 06/02/2011 12:58 PM, Jason Weathersby wrote:
>>>>> I have done it like:
>>>>>
>>>>> resp.setContentType( "application/pdf" );
>>>>> resp.setHeader ("Content-Disposition","inline; filename=test.pdf");
>>>>>
>>>>>
>>>>> and in the PDFRenderOption I put:
>>>>>
>>>>> options.setOutputStream(resp.getOutputStream());
>>>>>
>>>>> Jason
>>>>>
>>>>> On 6/2/2011 12:51 PM, msotomayor wrote:
>>>>>> Hello:
>>>>>>
>>>>>> I built a web application that uses the RE API to generate reports as
>>>>>> PDF files. The web application generates the report correctly but
>>>>>> saves
>>>>>> it in another file.
>>>>>>
>>>>>> I need the web application to ask the user for the location were to
>>>>>> download the file. However, when the user specifies the file name to
>>>>>> use
>>>>>> and the desired location, the browser actually creates two files. The
>>>>>> file the user wants is created empty and the file with the actual
>>>>>> report
>>>>>> contents is created in the home folder named as "report.pdf".
>>>>>>
>>>>>> I'm using the following code to tell the browser to download the
>>>>>> file as
>>>>>> an attachment:
>>>>>>
>>>>>> /*************************************/
>>>>>>
>>>>>> String headerValue =
>>>>>> String.format( "attachment; filename=%s", reportFileName);
>>>>>> response.setHeader( "Content-Disposition", headerValue );
>>>>>> response.setContentType( "application/pdf" );
>>>>>>
>>>>>> /*************************************/
>>>>>>
>>>>>>
>>>>>> I'm I missing something?
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>
>>>>
>>>
>>
>
Re: Empty PDF report downloaded as attachment from BIRT enabled web application [message #676314 is a reply to message #676312] Fri, 03 June 2011 11:46 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

The file gets created even if you use this line?
options.setOutputStream(resp.getOutputStream());

Jason

On 6/3/2011 11:31 AM, msotomayor wrote:
> The second file (which contains the actual contents of the report) is
> automatically named as "report.pdf" and is dropped at the user's home
> folder. I noticed that this file is created before the one that the user
> specifies in the save as dialog.
>
>
> On 06/03/2011 09:04 AM, Jason Weathersby wrote:
>> I just tried this and it worked for me. Where is it dropping the second
>> file?
>>
>> Jason
>>
>> On 6/2/2011 5:14 PM, msotomayor wrote:
>>> Thanks again, but it didn't worked neither.
>>>
>>> Should I use a ByteArrayOutputStream?
>>>
>>>
>>>
>>> On 06/02/2011 04:18 PM, Jason Weathersby wrote:
>>>> Put that line back in ad change the content disposition to use
>>>> attachment.
>>>> resp.setHeader("Content-disposition","attachment; filename=\""
>>>> +"test.pdf" +"\"");
>>>>
>>>> Jason
>>>>
>>>> On 6/2/2011 3:08 PM, msotomayor wrote:
>>>>> Hi Jason:
>>>>>
>>>>> Thank you for replying.
>>>>>
>>>>> That certainly works, but the call:
>>>>>
>>>>> > options.setOutputStream(resp.getOutputStream());
>>>>>
>>>>> causes the document to open within the browser.
>>>>>
>>>>>
>>>>> What I really need is the browser to open the save as dialog without
>>>>> displaying the contents of the report. If I comment that call, the
>>>>> dialog is opened but the two files are created, the desired by the
>>>>> user
>>>>> empty and another one called "report.pdf" with the actual contents.
>>>>>
>>>>>
>>>>> Any other ideas?
>>>>>
>>>>>
>>>>>
>>>>> On 06/02/2011 12:58 PM, Jason Weathersby wrote:
>>>>>> I have done it like:
>>>>>>
>>>>>> resp.setContentType( "application/pdf" );
>>>>>> resp.setHeader ("Content-Disposition","inline; filename=test.pdf");
>>>>>>
>>>>>>
>>>>>> and in the PDFRenderOption I put:
>>>>>>
>>>>>> options.setOutputStream(resp.getOutputStream());
>>>>>>
>>>>>> Jason
>>>>>>
>>>>>> On 6/2/2011 12:51 PM, msotomayor wrote:
>>>>>>> Hello:
>>>>>>>
>>>>>>> I built a web application that uses the RE API to generate
>>>>>>> reports as
>>>>>>> PDF files. The web application generates the report correctly but
>>>>>>> saves
>>>>>>> it in another file.
>>>>>>>
>>>>>>> I need the web application to ask the user for the location were to
>>>>>>> download the file. However, when the user specifies the file name to
>>>>>>> use
>>>>>>> and the desired location, the browser actually creates two files.
>>>>>>> The
>>>>>>> file the user wants is created empty and the file with the actual
>>>>>>> report
>>>>>>> contents is created in the home folder named as "report.pdf".
>>>>>>>
>>>>>>> I'm using the following code to tell the browser to download the
>>>>>>> file as
>>>>>>> an attachment:
>>>>>>>
>>>>>>> /*************************************/
>>>>>>>
>>>>>>> String headerValue =
>>>>>>> String.format( "attachment; filename=%s", reportFileName);
>>>>>>> response.setHeader( "Content-Disposition", headerValue );
>>>>>>> response.setContentType( "application/pdf" );
>>>>>>>
>>>>>>> /*************************************/
>>>>>>>
>>>>>>>
>>>>>>> I'm I missing something?
>>>>>>>
>>>>>>>
>>>>>>> Thanks,
>>>>>>
>>>>>
>>>>
>>>
>>
>
Re: Empty PDF report downloaded as attachment from BIRT enabled web application [message #676342 is a reply to message #676314] Fri, 03 June 2011 15:51 Go to previous messageGo to next message
Eclipse User
Originally posted by: ms

I found the solution. The HttpServletResponse headers MUST be set
before setting the render options not the opposite.

This is what I have now. I commented some observations along the code.

/*********************************************************************/

response.setContentType( mimeType );
String headerValue = "attachment; filename=" + reportFileName;
response.setHeader( "Content-Disposition", headerValue );

..
..
..

IRenderOption renderOption = new PDFRenderOption();
renderOption.setOutputFormat( IRenderOption.OUTPUT_FORMAT_PDF );
renderOption.setSupportedImageFormats( "JPG;PNG;BMP;SVG;GIF" );
renderOption.setOutputStream( response.getOutputStream() );

// * Downloads file automatically
// renderOption.setOutputFileName( reportFileName );

task.setRenderOption( renderOption );
task.run();

/*********************************************************************/


BTW, the code is part of a Spring MVC webapp ran by Tomcat. I was
testing the code with Google Chrome and Firefox on Linux Fedora 14 with
the acroread package installed.


Hope this can help somebody. Thank you very much for your help!



On 06/03/2011 11:46 AM, Jason Weathersby wrote:
> The file gets created even if you use this line?
> options.setOutputStream(resp.getOutputStream());
>
> Jason
>
> On 6/3/2011 11:31 AM, msotomayor wrote:
>> The second file (which contains the actual contents of the report) is
>> automatically named as "report.pdf" and is dropped at the user's home
>> folder. I noticed that this file is created before the one that the user
>> specifies in the save as dialog.
>>
>>
>> On 06/03/2011 09:04 AM, Jason Weathersby wrote:
>>> I just tried this and it worked for me. Where is it dropping the second
>>> file?
>>>
>>> Jason
>>>
>>> On 6/2/2011 5:14 PM, msotomayor wrote:
>>>> Thanks again, but it didn't worked neither.
>>>>
>>>> Should I use a ByteArrayOutputStream?
>>>>
>>>>
>>>>
>>>> On 06/02/2011 04:18 PM, Jason Weathersby wrote:
>>>>> Put that line back in ad change the content disposition to use
>>>>> attachment.
>>>>> resp.setHeader("Content-disposition","attachment; filename=\""
>>>>> +"test.pdf" +"\"");
>>>>>
>>>>> Jason
>>>>>
>>>>> On 6/2/2011 3:08 PM, msotomayor wrote:
>>>>>> Hi Jason:
>>>>>>
>>>>>> Thank you for replying.
>>>>>>
>>>>>> That certainly works, but the call:
>>>>>>
>>>>>> > options.setOutputStream(resp.getOutputStream());
>>>>>>
>>>>>> causes the document to open within the browser.
>>>>>>
>>>>>>
>>>>>> What I really need is the browser to open the save as dialog without
>>>>>> displaying the contents of the report. If I comment that call, the
>>>>>> dialog is opened but the two files are created, the desired by the
>>>>>> user
>>>>>> empty and another one called "report.pdf" with the actual contents.
>>>>>>
>>>>>>
>>>>>> Any other ideas?
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 06/02/2011 12:58 PM, Jason Weathersby wrote:
>>>>>>> I have done it like:
>>>>>>>
>>>>>>> resp.setContentType( "application/pdf" );
>>>>>>> resp.setHeader ("Content-Disposition","inline; filename=test.pdf");
>>>>>>>
>>>>>>>
>>>>>>> and in the PDFRenderOption I put:
>>>>>>>
>>>>>>> options.setOutputStream(resp.getOutputStream());
>>>>>>>
>>>>>>> Jason
>>>>>>>
>>>>>>> On 6/2/2011 12:51 PM, msotomayor wrote:
>>>>>>>> Hello:
>>>>>>>>
>>>>>>>> I built a web application that uses the RE API to generate
>>>>>>>> reports as
>>>>>>>> PDF files. The web application generates the report correctly but
>>>>>>>> saves
>>>>>>>> it in another file.
>>>>>>>>
>>>>>>>> I need the web application to ask the user for the location were to
>>>>>>>> download the file. However, when the user specifies the file
>>>>>>>> name to
>>>>>>>> use
>>>>>>>> and the desired location, the browser actually creates two files.
>>>>>>>> The
>>>>>>>> file the user wants is created empty and the file with the actual
>>>>>>>> report
>>>>>>>> contents is created in the home folder named as "report.pdf".
>>>>>>>>
>>>>>>>> I'm using the following code to tell the browser to download the
>>>>>>>> file as
>>>>>>>> an attachment:
>>>>>>>>
>>>>>>>> /*************************************/
>>>>>>>>
>>>>>>>> String headerValue =
>>>>>>>> String.format( "attachment; filename=%s", reportFileName);
>>>>>>>> response.setHeader( "Content-Disposition", headerValue );
>>>>>>>> response.setContentType( "application/pdf" );
>>>>>>>>
>>>>>>>> /*************************************/
>>>>>>>>
>>>>>>>>
>>>>>>>> I'm I missing something?
>>>>>>>>
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
Re: Empty PDF report downloaded as attachment from BIRT enabled web application [message #676348 is a reply to message #676342] Fri, 03 June 2011 16:30 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Thanks for the update.

Jason

On 6/3/2011 3:51 PM, ms wrote:
>
> I found the solution. The HttpServletResponse headers MUST be set before
> setting the render options not the opposite.
>
> This is what I have now. I commented some observations along the code.
>
> /*********************************************************************/
>
> response.setContentType( mimeType );
> String headerValue = "attachment; filename=" + reportFileName;
> response.setHeader( "Content-Disposition", headerValue );
>
> ..
> ..
> ..
>
> IRenderOption renderOption = new PDFRenderOption();
> renderOption.setOutputFormat( IRenderOption.OUTPUT_FORMAT_PDF );
> renderOption.setSupportedImageFormats( "JPG;PNG;BMP;SVG;GIF" );
> renderOption.setOutputStream( response.getOutputStream() );
>
> // * Downloads file automatically
> // renderOption.setOutputFileName( reportFileName );
>
> task.setRenderOption( renderOption );
> task.run();
>
> /*********************************************************************/
>
>
> BTW, the code is part of a Spring MVC webapp ran by Tomcat. I was
> testing the code with Google Chrome and Firefox on Linux Fedora 14 with
> the acroread package installed.
>
>
> Hope this can help somebody. Thank you very much for your help!
>
>
>
> On 06/03/2011 11:46 AM, Jason Weathersby wrote:
>> The file gets created even if you use this line?
>> options.setOutputStream(resp.getOutputStream());
>>
>> Jason
>>
>> On 6/3/2011 11:31 AM, msotomayor wrote:
>>> The second file (which contains the actual contents of the report) is
>>> automatically named as "report.pdf" and is dropped at the user's home
>>> folder. I noticed that this file is created before the one that the user
>>> specifies in the save as dialog.
>>>
>>>
>>> On 06/03/2011 09:04 AM, Jason Weathersby wrote:
>>>> I just tried this and it worked for me. Where is it dropping the second
>>>> file?
>>>>
>>>> Jason
>>>>
>>>> On 6/2/2011 5:14 PM, msotomayor wrote:
>>>>> Thanks again, but it didn't worked neither.
>>>>>
>>>>> Should I use a ByteArrayOutputStream?
>>>>>
>>>>>
>>>>>
>>>>> On 06/02/2011 04:18 PM, Jason Weathersby wrote:
>>>>>> Put that line back in ad change the content disposition to use
>>>>>> attachment.
>>>>>> resp.setHeader("Content-disposition","attachment; filename=\""
>>>>>> +"test.pdf" +"\"");
>>>>>>
>>>>>> Jason
>>>>>>
>>>>>> On 6/2/2011 3:08 PM, msotomayor wrote:
>>>>>>> Hi Jason:
>>>>>>>
>>>>>>> Thank you for replying.
>>>>>>>
>>>>>>> That certainly works, but the call:
>>>>>>>
>>>>>>> > options.setOutputStream(resp.getOutputStream());
>>>>>>>
>>>>>>> causes the document to open within the browser.
>>>>>>>
>>>>>>>
>>>>>>> What I really need is the browser to open the save as dialog without
>>>>>>> displaying the contents of the report. If I comment that call, the
>>>>>>> dialog is opened but the two files are created, the desired by the
>>>>>>> user
>>>>>>> empty and another one called "report.pdf" with the actual contents.
>>>>>>>
>>>>>>>
>>>>>>> Any other ideas?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 06/02/2011 12:58 PM, Jason Weathersby wrote:
>>>>>>>> I have done it like:
>>>>>>>>
>>>>>>>> resp.setContentType( "application/pdf" );
>>>>>>>> resp.setHeader ("Content-Disposition","inline; filename=test.pdf");
>>>>>>>>
>>>>>>>>
>>>>>>>> and in the PDFRenderOption I put:
>>>>>>>>
>>>>>>>> options.setOutputStream(resp.getOutputStream());
>>>>>>>>
>>>>>>>> Jason
>>>>>>>>
>>>>>>>> On 6/2/2011 12:51 PM, msotomayor wrote:
>>>>>>>>> Hello:
>>>>>>>>>
>>>>>>>>> I built a web application that uses the RE API to generate
>>>>>>>>> reports as
>>>>>>>>> PDF files. The web application generates the report correctly but
>>>>>>>>> saves
>>>>>>>>> it in another file.
>>>>>>>>>
>>>>>>>>> I need the web application to ask the user for the location
>>>>>>>>> were to
>>>>>>>>> download the file. However, when the user specifies the file
>>>>>>>>> name to
>>>>>>>>> use
>>>>>>>>> and the desired location, the browser actually creates two files.
>>>>>>>>> The
>>>>>>>>> file the user wants is created empty and the file with the actual
>>>>>>>>> report
>>>>>>>>> contents is created in the home folder named as "report.pdf".
>>>>>>>>>
>>>>>>>>> I'm using the following code to tell the browser to download the
>>>>>>>>> file as
>>>>>>>>> an attachment:
>>>>>>>>>
>>>>>>>>> /*************************************/
>>>>>>>>>
>>>>>>>>> String headerValue =
>>>>>>>>> String.format( "attachment; filename=%s", reportFileName);
>>>>>>>>> response.setHeader( "Content-Disposition", headerValue );
>>>>>>>>> response.setContentType( "application/pdf" );
>>>>>>>>>
>>>>>>>>> /*************************************/
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I'm I missing something?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
Previous Topic:Problem with Charts - BIRT crashes
Next Topic:BIRT report without WebViewer
Goto Forum:
  


Current Time: Thu Jul 24 04:45:56 EDT 2014

Powered by FUDForum. Page generated in 0.09644 seconds