Wednesday, January 22, 2014

Re: Printing

I am having a strange problem, I have figured out how to print my widget with the style. However, when I try to print a second widget, I get a blank page. I only have this problem in firefox, I havn't tested in IE, and chrome seems to work every time. Just to be clear I try to print a widget on my site, it works fine, then I navigate to another page and try to print that one and it is blank. It won't work again until I reload the website. Any ideas? Do I need to reset something?

On Monday, April 16, 2007 9:55:16 AM UTC-4, Freller wrote:

Hi there,

Some people are reporting problems printing with external style links.
I still unable to reproduce the problem in my environment.
Jose claims here http://groups.google.com/group/Google-Web-Toolkit/browse_frm/thread/5bf6997b00dca94a/3acd6b200f77f81f#3acd6b200f77f81f
that he solved the problem introducing a confirm() dialog in the native javascript code.

I think it is a timing problem related to formatting the page using complex html and/or external styles.

Can you try this code below  and report if it works in your case?

Regards,
Freller


import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.UIObject;

public class Print {

    public static native void it() /*-{                                                                                                           
        $wnd.print();                                                                                                                             
    }-*/;

    public static native void doit(String html) /*-{                                                                                              
        var frame = $doc.getElementById('__printingFrame');                                                                                       
        if (!frame) {                                                                                                                             
            $wnd.alert("Error: Can't find printing frame.");                                                                                      
            return;                                                                                                                               
        }                                                                                                                                         
        frame = frame.contentWindow;                                                                                                              
        var doc = frame.document;                                                                                                                 
        doc.open();                                                                                                                               
        doc.write(html);                                                                                                                          
        doc.close();                                                                                                                              
                                                                                                                                                  
        for (var cii=0; cii < 100000; cii++){}                                                                                                    
        frame = $doc.getElementById('__printingFrame');                                                                                           
        frame = frame.contentWindow;                                                                                                              
                                                                                                                                                  
        frame.focus();                                                                                                                            
        frame.print();                                                                                                                            
    }-*/;


    public static void it(String html) {
        try {
            doit(html);
        } catch (Throwable exc) {
            Window.alert(exc.getMessage());
        }   
    }
    public static void it(UIObject obj) {
        it("", obj.getElement ().toString());
    }

    public static void it(Element element) {
        it("", element.toString());
    }

    public static void it(String style, String it) {
        it("<html><head>"+style+"</head>\n<body>"+it+"</body></html>");
    }
    
    public static void it(String style, UIObject obj) {
        it(style, obj.getElement().toString());
    }
    
    public static void it(String style, Element element) {
        it(style, element.toString());
    }

} // end of class Print                                                                                                                           







--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment