Before I read this I had the same problem as you

I tried to solve it like this:


- 1) I wrote a servlet wich writes the content into the session:
/**********************
  public PDFServiceImpl() {
                super();
        }



        public String prepareSession(String header, String table) {

                try {
                         if(table != null && !table.trim().equals("")){

                                getSession().removeAttribute("_pdf");
                                getSession().removeAttribute("_content");
                                getSession().removeAttribute("_header");

                                String resultKey = 
ServerUtils.generateOnTimeKey();

                                if(log.isInfoEnabled())
log.info("PDFServiceImpl.showProfilAsPDFForBerater CRC for PDF  crc: "
+ resultKey);

                                if (resultKey.length() < 6)
                                        throw
GwtExceptionBuilder.getGWTBadRequestException("PDFServiceImpl CRC was
smaller than 6 chars :"
                                                        + " crc: " + resultKey 
+ " return!");

                                getSession().setAttribute("_pdf", resultKey);
                                getSession().setAttribute("_content", table);
                                getSession().setAttribute("_header", header);

                                log.info("PDFServiceImpl prepair pdf-session. 
ResultKey = "+
resultKey);

                                return resultKey;
                         }
                         log.info("PDFServiceImpl tried prepair pdf-session and 
failed
cause tableString is empty returns null");

                         return null;

                } catch (Exception e) {

                        log.info("PDFServiceImpl tried prepair pdf-session and 
failed.
returns null");

                        return null;
                }

        }
        ************************/


- 2)and wrote an HTTP Servlet wich reads the session attributes an
creates the pdf:

 /***********************
     public class PDFGenerator extends HttpServlet{

 ....



        public PDFGenerator() {
                super();
        }

         public void doGet (HttpServletRequest request, HttpServletResponse
response)
            throws IOException, ServletException {

                // we retrieve the content
                String content =
(String)request.getSession().getAttribute("_content");
                 String header = (String)
request.getSession().getAttribute("_header");
                 StringBuffer buf = new StringBuffer();
                buf.append("<html>");




                // put in some style
                buf.append("<head>");
                buf.append("<meta http-equiv=\"content-typ\" content=\"text/
html; charset=windows-1250\"></meta>");
                buf.append("<link rel='stylesheet' type='text/css'
href='http://xyz/css/stylsheet.css' media='print'/>");
                 buf.append("</head>");

                buf.append("<body>");

          try {

                    DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();


                    org.w3c.dom.Document doc = builder.parse(new
StringBufferInputStream(buf.toString()));


                    ITextRenderer renderer = new ITextRenderer();
                    renderer.setDocument(doc, null);
                    renderer.layout();

                    response.setContentType("application/pdf");

                    OutputStream os = response.getOutputStream();
                    renderer.createPDF(os);
                    os.close();


                } catch (Exception ex) {
                    ex.printStackTrace();

                    response.setHeader("Content-Type", "text/html");
                                response.setContentType("text/html");
                                PrintWriter out = response.getWriter();

                                StringBuilder html = new StringBuilder();
                                html.append("<html>");
                                html.append("<head>");
                                html.append("<meta http-equiv=\"content-type\" 
content=
\"text/html; charset=windows-1250\">");
                                html.append("<title>exeption PDF</title>");
                                html.append("</head>");
                                html.append("<body>");
                                html.append("<h3 align=\"center\">");
                                html.append("<br><br><br><hr color=\"red\">");
                                html.append("<font size=\"4\" 
color=\"#004B8D\">");
                                html.append("<br><br>Fehler beim Export des 
PDFs:<br><br>");
                                html.append("</font>");
                                html.append("<font size=\"3\" 
color=\"#004B8D\">");
                                
html.append("<br><br>"+ex.getMessage()+"<br><br><hr>");
                                html.append(content);
                                html.append("</font>");
                                html.append("<hr color=\"red\">");
                                html.append("</h3>");
                                html.append("</body>");
                                html.append("</html>");

                                out.println(html);
                }
                ....


                *****************/

-3) And ivoked It like this on client site:

PDFService.Util.getInstance().prepareSession(Window.prompt("Hier bitte
eine Überschrift für die Tabelle eingeben!", ""), table.toString(),
new AsyncCallback()
                                {


                                        public void onFailure(Throwable caught) 
{
                                                Window.alert(" Exception: 
"+caught.getMessage());

                                        }

                                        public void onSuccess(Object result) {
                                                if (result!=null && result 
instanceof String){
                                                        String b = (String) 
result;
                                                        
Window.open("PDFGenerator?session=" + b, "_blank",
"resizable");
                                                }else{
                                                        Window.alert("F.....");
                                                }

                                        }
                                });

- 4) table.toString:
public String toString(){
                return DOM.getInnerHTML(getElement());
        }

IMPORTENT HERE:
==============
This worked with firefox but the ie returned a html without quotes and
other important characters!!!!
So I was forced to parse the whole html on server-site and clean all
the mass that ie returned me
by "hand". This was real anoying.... so I let it be.

My approach now is to serialize the DOM- Object in any way. Send it to
server and process it browser independen. But this step is still
proceeding


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to