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

The Archive Base Latest Questions

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

I’m new to JasperReports and find myself getting pretty lost with it. I’ve got

  • 0

I’m new to JasperReports and find myself getting pretty lost with it. I’ve got a webapp in JSF that I want to use to print a PDF. I’ve built the report, and am able to successfully compile and fill it with all my parameters. However, I’m lost on the actual output portion. I’d like it go to a printer as a PDF. I don’t care about ever seeing it on screen, straight to printer would be the ideal (from the server would be ideal, but client would also be fine as we could setup the clients to print as necessary (it’s an internal app)).

  • 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-26T14:57:30+00:00Added an answer on May 26, 2026 at 2:57 pm

    I’d like it go to a printer as a PDF. I don’t care about ever seeing it on screen, straight to printer would be the ideal

    You can’t do it with plain HTML/CSS/JS. As JSF is basically just a HTML/CSS/JS code generator, it can’t do any magic for you. Closest what you can get is JavaScript’s window.print(), but that would still show the user the printer settings and such (basically, it does the same as Ctrl+P).

    Your best bet is to create an Applet which uses the javax.print API and then embed that Applet in your JSF page by HTML <applet> or <object> tag.

    If you can live with seeing it straight on screen and delegating the print job to the enduser itself, then you can send a PDF file to screen by JSF as follows:

    public void sendPdf() throws IOException {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        externalContext.setResponseContentType("application/pdf");
        externalContext.setResponseHeader("Content-Disposition", "inline; filename=\"filename.pdf\"");
        yourJasperReportsClass.writePdfTo(externalContext.getResponseOutputStream());
        facesContext.responseComplete();
    }
    

    I have never worked with JasperReports, so the yourJasperReportsClass.writePdfTo() was just a random guess, but the hint should be clear enough. You basically need to instruct it to write the PDF to the response body.


    Update: as per the comments, that printer is actually connected to the server, not to the client and you actually want to let the server print it to its printer. In that case, just use the javax.print API. At the bottom of that document you can find some code examples. Here’s an extract of relevance:

    Using the API

    A typical application using the Java Print Service API performs these steps to process a print request:

    • Chooses a DocFlavor.
    • Creates a set of attributes.
    • Locates a print service that can handle the print request as specified by the DocFlavor and the attribute set.
    • Creates a Doc object encapsulating the DocFlavor and the actual print data, which can take many forms including: a Postscript file, a JPEG image, a URL, or plain text.
    • Gets a print job, represented by DocPrintJob, from the print service.
    • Calls the print method of the print job.

    The following code sample demonstrates a typical use of the Java Print Service API: locating printers that can print five double-sided copies of a Postscript document on size A4 paper, creating a print job from one of the returned print services, and calling print.

    FileInputStream psStream; 
    
    try { 
      psStream = new FileInputStream("file.ps");
    } catch (FileNotFoundException ffne) {
    } 
    
    if (psStream == null) { 
      return;
    }
    
    DocFlavor psInFormat = DocFlavor.INPUT_STREAM.POSTSCRIPT; 
    Doc myDoc = new SimpleDoc(psStream, psInFormat, null); 
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); 
    aset.add(new Copies(5)); 
    aset.add(MediaSize.A4); 
    aset.add(Sides.DUPLEX); 
    
    PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset); > 
    if (services.length > 0) { 
      DocPrintJob job = services[0].createPrintJob(); 
    
      try {
        job.print(myDoc, aset); 
      } catch (PrintException pe) {
      }
    } 
    

    It’s not relevant if the above code called by a JSF managed bean. It’s after all just Java. You might only want to modify the DocFlavor and other settings.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.