Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8509439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:26:05+00:00 2026-06-11T03:26:05+00:00

My requirement is to generate PDF file using iText, I use below code to

  • 0

My requirement is to generate PDF file using iText, I use below code to create a sample PDF

Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter.getInstance(document, baos);
document.open();
document.add(new Paragraph("success PDF FROM STRUTS"));
document.close();
ServletOutputStream outputStream = response.getOutputStream() ;
baos.writeTo(outputStream);
response.setHeader("Content-Disposition", "attachment; filename=\"stuReport.pdf\"");
response.setContentType("application/pdf");
outputStream.flush();
outputStream.close();

If you see in the above code, iText is not using any inputStream parameter, rather it is writing directly to response’s outputstream. Whereas struts-2 is mandating us to use InputStream parameter (see the configuration below)

<action name="exportReport" class="com.export.ExportReportAction">
    <result name="pdf" type="stream">
        <param name="inputName">inputStream</param>
        <param name="contentType">application/pdf</param>
        <param name="contentDisposition">attachment;filename="sample.pdf"</param>
        <param name="bufferSize">1024</param>
    </result>
</action>

I know that my class should have getters and setters for inputStream and i have that too in the class mentioned in struts-configuration

private InputStream inputStream;
public InputStream getInputStream() {
    return inputStream;
}

public void setInputStream(InputStream inputStream) {
    this.inputStream = inputStream;
}

But since iText doesn’t really need inputstream rather it is writing directly to response’s outputstream, i get exceptions since am not setting anything for the inputStream parameter.

Please let me know how to use iText code in struts-2 having the resultType as stream

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:26:07+00:00Added an answer on June 11, 2026 at 3:26 am

    Found solution to this.

    The method in the action which performs this PDF export can be void. The result type configuration is not needed while we are writing directly to response’s outputstream

    for example, have your action class this way

    Class ExportReportAction extends ActionSupport {
      public void exportToPdf() { // no return type
        try {
            Document document = new Document();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, baos);
            document.open();
            document.add(new Paragraph("success PDF FROM STRUTS"));
            document.close(); 
            ServletOutputStream outputStream = response.getOutputStream() ; 
            baos.writeTo(outputStream); 
            response.setHeader("Content-Disposition", "attachment; filename=\"stuReport.pdf\""); 
            response.setContentType("application/pdf"); 
            outputStream.flush(); 
            outputStream.close(); 
        }catch (Exception e) {
            //catch
        }
    
      } 
    }
    

    and have your struts-configuration this way

    <action name="exportReport" class="com.export.ExportReportAction"> 
     <!-- NO NEED TO HAVE RESULT TYPE STREAM CONFIGURATION-->
    </action>
    

    this works cool !!!

    Thanks for all who attempted to answer this question

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a particular requirement to generate a PDF document with some dynamic data
We have a requirement to generate PDF documents using information from a PDA /
I have a requirement to generate a pdf document on a button click on
I'm building a new web app that has a requirement to generate an internal
I am using log4net to generate logs in my applicaiton. My requirement was to
I have been using fop 0.95 to generate pdf files from xml data. I
I have a requirement to dynamically generate and compress large batches of PDF files.
I sadly have a requirement to generate some messy XML. The main document must
I am a beginner in MVC and have a requirement to generate PDF of
I've a requirement to be able to generate PDF's within our (ASP.net) application. We

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.