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

  • SEARCH
  • Home
  • 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 6568789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:31:26+00:00 2026-05-25T14:31:26+00:00

I have a JSF/Seam web app which has a page with a form which,

  • 0

I have a JSF/Seam web app which has a page with a form which, when submitted (button clicked), causes a PDF file to be dynamically created (in Java, server side) based on the form input. Currently what I have working is that the resulting PDF is returned to the browser as a file download, so the user can opt to save it or open it in Acrobat Reader for subsequent printing.

What I would like to happen is that the PDF is sent to the browser and printed (client side) without further user intervention (well, other than perhaps the Windows printer options dialog appearing, about which there’s nothing I could do).

The solution seems to be based on having a hidden iframe on the page into which the PDF is loaded and then calling .contentWindow.print() on the iframe. However, I have no idea how to get the PDF into the iframe via the HttpServletResponse (in Java), much less how to automatically call print() on the iframe once the pdf has been loaded.

  • 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-25T14:31:28+00:00Added an answer on May 25, 2026 at 2:31 pm

    However, I have no idea how to get the PDF into the iframe via the HttpServletResponse (in Java)

    Let the <iframe src> point to a servlet URL which gets an InputStream of the PDF and writes it to the OutputStream of the response. You can if necessary pass JSF bean properties as additional GET parameters so that you can control the PDF generation.

    <iframe src="pdfServlet?foo=#{bean.foo}&amp;bar=#{bean.bar}"></iframe>
    

    The doGet() method of the servlet in question can look like this:

    String foo = request.getParameter("foo");
    String bar = request.getParameter("bar");
    
    response.setContentType("application/pdf");
    
    InputStream input = generatePdfSomehowBasedOn(foo, bar);
    OutputStream output = response.getOutputStream();
    // Now just write input to output.
    

    much less how to automatically call print() on the iframe once the pdf has been loaded.

    Hook a function on <iframe onload>. You however need to take browser specific behaviours into account. More hints can be found in this question: How do I print an IFrame from javascript in Safari/Chrome

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

Sidebar

Related Questions

We're developing a Java web app that utilizes JSF (Richfaces through Seam) for its
I have JSF page has two drop down lists and I want to load
I have a JSF Page which gets few inputs from the User, I want
I have a login.jsp page which contains a login form. Once logged in the
I have jsf page: .... <form jsfc=h:form action=> <h:dataTable value=#{newMusician.strings} var=preferredMusicGenre id=musicGenresSelectTable> <h:column> <h:inputText
I have this JSF page trying to load a GWT app. The page works
I have a seam web application and for one page I have an hardcoded
I have a JSF page that is basically a create form. The form consists
I have a JSF page with two forms (pseudo-code below). First form is for
I have a JSF page which is outputting XHTML (from a facelet). One of

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.