3 Replies Latest reply on Aug 4, 2015 10:24 AM by David Baddeley

    Rendering PDF

    Rafael  Frade Newbie

      I'm generating a pdf using specific api of seam to do that.
      I'd like to know if there is a way to render it without
      showing it to the user.
      For example, when the user clicks at a link, I save the pdf
      in a directory without the user realize it. Like a way to render
      the xhtml that is the pdf(that uses the tags p ), but with no
      need to show it to the user.

      Another question is, using the same API, can I include another
      pdf files(real pdfs, not xhtml) to the one I'm making.

      Thank you.

        • 1. Re: Rendering PDF
          Leo van den berg Master


          Although the PDF-support ins Seam is great, nothing beats using the API's directly. It takes some effort, but the result is better.
          In my opinion PDF is a bit to closely coupled, but that's something for another Thread.

          Look at the iText API, or use Birt/JasperReports. The latter has also a nice API to dynamically generate reports. In this way you create the report in the format you want and - if needed - you can output (stream) it directly to your user.


          • 2. Re: Rendering PDF
            cathy ben Newbie

            I found a C#.net PDF rendering API. And it have related pdf reading and edition feature you wanted.

            If you think it's helpful, you can have a look at it.


            Best regards.

            • 3. Re: Rendering PDF
              David Baddeley Newbie

              You should be able to do this in Seam, I have done something similar to email an Excel document as an attachment, see code below, I am sure you could adapt this for Seam PDF

              In the .xhtml file you need to set the export key, this places the generated document in the event scope...eg:


              <e:workbook xmlns:e="http://jboss.org/schema/seam/excel"

              then the following backing bean code to retrieve the report as a byte array:

              //Render the report using a fake request
                EmptyFacesContext emptyFacesContext = new EmptyFacesContext();
                try {
                     String pageLocation = "/somePage.xhtml";
                     Renderer renderer = Renderer.instance();
                     //Retrieve the report from the event context
                          DocumentData data = (DocumentData) Contexts.getEventContext().get("_pue");
                          ByteArrayDocumentData byteData = null;
                          if (data instanceof ByteArrayDocumentData) {
                               byteData = (ByteArrayDocumentData) data;
                          } else {
                               throw new IllegalArgumentException("Couldnt get the bytes from the pdf document, unkown class " + data.getClass().getName());
                          //Send email with attachement
                          Map<String,Object> emailMap = new HashMap<String,Object>();
                          emailMap.put("clientUser", clientUser);
                          emailService.sendMessageToUser(Email.client_usage_report, clientUser, emailMap);
                          log.error("No document found");
                }catch(Exception ex){
                     log.error("Error when trying to get the content of the excel in bytes with the message:\n {0}", ExceptionUtils.getStackTrace(ex));