Welcome Guest Search | Active Topics | Sign In | Register

Printing without a form Options
mlouthan
Posted: Tuesday, May 12, 2015 3:15:26 PM
Rank: Newbie
Groups: Member

Joined: 5/12/2015
Posts: 9
We are evaluating this product for our needs and are attempting to print a URL without creating a form. Is this possible? I've been trying and the URL will load, but my BeforePrint event never gets triggered. I have tried changing the code below around a bit to simplify things (moving the print call to directly within the threadRunner.Send method), but my BeforePrint listener never gets triggered. Is the print somehow relying on the form being present? I couldn't find anything in the documentation or forums discussing this already. Many thanks for your help.

Code: C#
public static void PrintUri(string localPrinter, Uri uri)
        {
            printerName = localPrinter;
            using (EO.WebBrowser.ThreadRunner threadRunner = new EO.WebBrowser.ThreadRunner())
            {
                EO.WebBrowser.WebView b = threadRunner.CreateWebView();
                threadRunner.Send(() =>
                    {
                        b.LoadCompleted += WebView_LoadCompleted;
                        b.BeforePrint += WebView_BeforePrint;
                        b.LoadUrlAndWait(uri.AbsoluteUri);
                    });
            }
            
        }

        public static void WebView_BeforePrint(object sender, EO.WebBrowser.BeforePrintEventArgs e)
        {
            e.Continue(false);
        }

        public static void WebView_LoadCompleted(object sender, EO.WebBrowser.NavigationTaskEventArgs e)
        {
            EO.WebBrowser.WebView view = (EO.WebBrowser.WebView)sender;
            System.Drawing.Printing.PrinterSettings printSettings = EO.WebBrowser.WebView.GetDefaultPrintSettings();
            printSettings.PrinterName = printerName;

            System.Drawing.Printing.PageSettings pageSettings = new System.Drawing.Printing.PageSettings(printSettings);
            pageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
            pageSettings.PaperSize = new System.Drawing.Printing.PaperSize("4inchCustom", 400, view.GetPageSize().Height);

            view.Print(false, printSettings, pageSettings);
        }
mlouthan
Posted: Tuesday, May 12, 2015 5:31:23 PM
Rank: Newbie
Groups: Member

Joined: 5/12/2015
Posts: 9
I managed to get this to print using a separate thread, though I am disappointed the other method didn't work. My next question centers more around printing though. I was hoping to change the page size on the fly since we are printing to a continuous printer roll (set the papersize height to the height of the rendered html), however just changing the PageSettings.PaperSize doesn't seem to actually change how the document prints. The PrintSettings.PaperSizes collection seems to be impenetrable. I have tried multiple methods to modify it or its contents to no avail. Any suggestions?

Code: C#
Thread printThread = new Thread(() =>
            {
                PictureBox pictureBox = new PictureBox();
                EO.WebBrowser.WebView view = new EO.WebBrowser.WebView();
                view.Create(pictureBox.Handle);
                view.LoadCompleted += WebView_LoadCompleted;
                view.BeforePrint += WebView_BeforePrint;
                view.LoadUrlAndWait(uri.AbsoluteUri);
                System.Windows.Forms.Application.Run();

            });
            printThread.SetApartmentState(ApartmentState.STA);
            printThread.Start();
eo_support
Posted: Tuesday, May 12, 2015 5:49:20 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Thanks for the information. We are looking into this and will reply again as soon as we find anything.
mlouthan
Posted: Wednesday, May 13, 2015 5:58:43 PM
Rank: Newbie
Groups: Member

Joined: 5/12/2015
Posts: 9
Thank you for looking into this. I have tried modifying multiple settings in the page settings for the web view and none seem to impact what is printed. Specifically, the PaperSize and PrinterResolution are properties I need to override. It seems as though the webview is pulling the default values from the printer driver, regardless of the page settings set.
eo_support
Posted: Wednesday, May 13, 2015 10:29:24 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

This is just to let you know that we are still working on this issue. It would require code changes on our side to make it work. We will continue working on it tomorrow and keep you updated as we make any progress.

Thanks
mlouthan
Posted: Thursday, May 14, 2015 10:04:15 AM
Rank: Newbie
Groups: Member

Joined: 5/12/2015
Posts: 9
Thanks for getting back to me. Since I've asked a couple of different questions, can we clarify exactly what issue you are working to fix? Our top concerns are page size and resolution, though having all of the page and print settings work would be ideal. Also, what is the turn around on a change like this? Like many others have posted, I'm under the gun to have a proof of concept, so even a beta build or something similar would be great.
eo_support
Posted: Thursday, May 14, 2015 10:22:16 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

We are working on the page size right now. It appears that you can't feed a printer arbitrary page size ---- it has to be one of those preset sizes, even though it's possible to add custom sizes into the list --- this is what we are working on right now. The same for resolutions --- it supposes to choose from list. For resolutions, it doesn't seem to be a way to add into the list. You can only get from a list of values that the printer supports and then pick one.

We are not too concern about the BeforePrint event not firing issue --- in your original code it will not happen because the whole printing flow is asynchronous. So BeforePrint will happen sometime later after Print method has returned, and the actual printing will happen sometime later after BeforePrint. This requires the WebView and the ThreadRunner to stay alive much longer after LoadUrlAndWait returns. This does bring another issue of how you would know when the printing is done. However this is secondary comparing with the page size/resolution issue.

Hope this gives you a better picture of what we are working on. We will keep you updated as we progress.

Thanks!
mlouthan
Posted: Thursday, May 14, 2015 10:25:15 AM
Rank: Newbie
Groups: Member

Joined: 5/12/2015
Posts: 9
Much appreciated. I was able to get around the BeforePrint event not firing issue, so that is much less of a concern.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.