Loading ...
Sorry, an error occurred while loading the content.

RE: PDF Generation and Javamail

Expand Messages
  • Jignesh Shah
    Hi, I generate my pdf using the below code: public void renderXML(Document xmlsource, InputStream xslobj, HttpServletResponse response) throws ServletException
    Message 1 of 1 , Jul 30, 2003
    • 0 Attachment
      Hi,

      I generate my pdf using the below code:

      public void renderXML(Document xmlsource, InputStream xslobj,
      HttpServletResponse response) throws ServletException
      {
      try {
      response.setContentType("application/pdf");
      Driver driver = new Driver();
      driver.setLogger(log);
      driver.setOutputStream(response.getOutputStream());
      driver.setRenderer(Driver.RENDER_PDF);
      Transformer transformer=TransformerFactory.newInstance()
      .newTransformer(new StreamSource(xslobj));
      transformer.transform(new JDOMSource(xmlsource), new
      SAXResult(driver.getContentHandler()));

      } catch (Exception ex) {
      // throw new ServletException(ex);
      ex.printStackTrace();
      System.out.println("exception in fopservlet renderXML:
      "+ex.getMessage());
      }
      }

      This lets me open the pdf file dynamically. If I have to save the same
      file on the server hard drive, What should I change? How can I assign a
      specific filename and directory location

      Thanks

      Jignesh


      -----Original Message-----
      From: Peter Abbot [mailto:Peter.Abbot@...]
      Sent: Sunday, July 27, 2003 5:49 PM
      To: fop-user@...
      Subject: RE: PDF Generation and Javamail

      Thanks for the response

      Looks like I will have to the same. As the users want a copy of the
      generated pdf I will probably just create a copy at a "known" location
      and then email the pdf document from the file.

      The error I was getting was that the javamail didn't know how to convert
      the string of type application/pdf into a mail attachemnt. When I create
      the pdf document as a file and attach it that way it works fine.

      In the long run I might look at creating a ContentHandler. What I was
      trying to create is a service component that took xhtml and send it as a
      pdf document without having the overhead of creating an actual file.

      Pete

      -----Original Message-----
      From: Bill Lunnon [mailto:bill@...]
      Sent: Friday, 25 July 2003 5:00 p.m.
      To: fop-user@...
      Subject: RE: PDF Generation and Javamail


      Peter,

      This is my experience with fop-0.20.3

      I have been generating content (application/pdf) quite sucsessfully
      using FOP in a servlet. Standard FOP stuff!

      I had a requirement to email one or more PDF documents (as attachments)
      to a recipient. My initial approach was based on using JavaMail and
      creating a HTML page where a user could define the email stuff
      (recipient, subject,
      content(text)) as well as indicate the PDF documents to be generated and
      attached to the email. I then used a servlet to connect to the SMTP
      server
      (sendmail) and create the email content and PDF attachments. The PDF
      generation worked ok, the email creation and connection to the SMTP
      server did not return any errors (or throw any exceptions) but the email
      didn't consistently get to the receipient. Reviewing the SMTP server
      logs, I could see where some email's were getting through and others
      where not. I am not assuming that there are no errors in the code, but
      all checks returned without error or exceptions thrown. I modified the
      approach so that the email details and PDF attachments where written to
      a "known" location by the servlet. I used another (cron'd) task then to
      connect to the SMTP server (again using JavaMail) and sent the email
      with attachments. This has worked without missing a message.

      Hope this helps

      Bill
      -----Original Message-----
      From: Peter Abbot [mailto:Peter.Abbot@...]
      Sent: Friday, 25 July 2003 12:38 PM
      To: fop-user@...
      Subject: PDF Generation and Javamail


      Does anybody have any tips for sending the output of an xml to pdf
      conversion by email using javamail. I also tried creating the output as
      a file and then using javamail to send the file but I got the same
      result.

      I have been looking around the web for help and nothing seems to help.
      The best I have been able to achieve is a whole lot of blank pages. What
      I think I will have to end up doing is write a DataHandler for handling
      the content type "application/pdf".

      Any help would be most appreciated.

      Cheers

      Pete

      ---------------------------------------------------------------------
      To unsubscribe, e-mail: fop-user-unsubscribe@...
      For additional commands, e-mail: fop-user-help@...



      ---------------------------------------------------------------------
      To unsubscribe, e-mail: fop-user-unsubscribe@...
      For additional commands, e-mail: fop-user-help@...


      ---------------------------------------------------------------------
      To unsubscribe, e-mail: fop-user-unsubscribe@...
      For additional commands, e-mail: fop-user-help@...
    Your message has been successfully submitted and would be delivered to recipients shortly.