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 6801119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:03:38+00:00 2026-05-26T19:03:38+00:00

I have a java web application based on Spring MVC. The task is to

  • 0

I have a java web application based on Spring MVC.
The task is to generate a pdf file. As all knows the spring engine has its own built-in iText library so the generating of pdf file is really simple. First of all we need to do is to overload AbstractView and create some PdfView. And the seconf thing is to use that view in controller. But in my application I am also have to be able to store generated pdf files on local drive or give my users some link to download that file. So the view in that case is not suitable for me.

I want to create some universal pdf generator that creates a pdf file and returns the bytes array. So I can use that array for file storing (on hard drive) or printing it directly in browser. And the question is – are there any way to use such engine (that returns only the bytes array) in PdfVIew solution? I am asking because overloaded buildPdfDocument method (in PdfView) already have PdfWriter and Document parameters.
Thank you

  • 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-05-26T19:03:39+00:00Added an answer on May 26, 2026 at 7:03 pm

    tldr; you should be able to use a view and save it to a file.

    Try using Flying Saucer and its iTextRenderer when you overload AbstractPdfView.

    import org.xhtmlrenderer.pdf.ITextRenderer;
    public class MyAbstractView extends AbstractView {
       OutputStream os;
    
       public void buildPdfDocument(Map<String,Object> model, com.lowagie.text.Document document, com.lowagie.text.pdf.PdfWriter writer, HttpServletRequest request, HttpServletResponse response){
       //process model params
       os = new FileOutputStream(outputFile);
       ITextRenderer renderer = new ITextRenderer();
       String url = "http://www.mysite.com"; //set your sample url namespace here
       renderer.setDocument(document, url); //use the passed in document
       renderer.layout();
       renderer.createPDF(os);
       os.close();
       }
    }
    
    protected final void renderMergedOutputModel(Map<String,Object> model,
                                             HttpServletRequest request,
                                             HttpServletResponse response)
                                      throws Exception{
     if(os != null){
      response.outputStream = os;
     }
    
    public byte[] getPDFAsBytes(){
      if(os != null){
         byte[] stuff;
         os.write(stuff);
         return stuff;
      }
    }
    

    }

    You’ll probably have to tweak the sample implementation shown here, but that should provide a basic gist.

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

Sidebar

Related Questions

I have a Spring framework based Java web application, which has been built in
We have a Java web application that uses Spring and Hibernate and has a
We have a web based java/JSF/Spring application for which we want to create sitempas.xml
I have a Java based web-application using Java Server Faces and Facelets. I am
We have a Java EE-based web application running on a Glassfish app server cluster.
Hi I have a page in my java/jsp based web application which shows list
I am a newbie to Java Web Application development. So far all I have
I have a java web application that generates and displays graphical pictures based upon
Context: The Cloud We have a java-based web application that we normally host on
I searched for Java based web application frameworks the last few days. I have

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.