Welcome Guest Search | Active Topics | Sign In | Register

How to capture webView of particular size with scroll bars included? Options
Frank
Posted: Wednesday, January 29, 2020 10:25:34 PM
Rank: Newbie
Groups: Member

Joined: 1/29/2020
Posts: 2
Hi -

Thank you for writing such a useful tool. We have a web application that generates client-side charts and data tables (ag-grid), and we would like to provide our customers with a tool they can use to capture static images of the results for insertion into Powerpoint, etc.

I have been experimenting with EO.WebBrowser and EO.Pdf.

EO.pdf works well, but I think the insertion into Powerpoint would go more smoothly with PNGs.

With EO.WebBrowser, I am using webView.Capture, but I'm struggling with a few things:

1) If I don't specify a size when I call Capture, I am only getting a subset of my chart+data table (even after waiting long enough for everything to be rendered).

2) If I specify a rectangle when I call Capture, I get my chart+data table, but the ag-grid scrollbar is missing, and the result looks odd.

3) If I specify excludeScrollBars:=False in my call to Capture, I get back "Nothing" (and no error is thrown by the call to Capture).

So... I am wondering:

a) Is it possible to call webView.Capture with *both* excludeScrollBars:=False *and* a Rectangle to force the size?

b) Any ideas on what I might be doing wrong when I ask for excludeScrollBars := False?

c) Any ideas on why my call to webView.Capture() with no sizing rectangle doesn't return an image that is the size returned by webView.GetPageSize()?

Sample code below with comments.

thanks!
-Frank.

Code: Visual Basic.NET
'Create a ThreadRunner object
        Dim threadRunner As New ThreadRunner()

        'Create a WebView through the ThreadRunner
        Dim webView As WebView = threadRunner.CreateWebView()

        threadRunner.Send(Function()
                              'Load a page, wait up to 3 seconds for the reply
                              webView.LoadUrl(url).WaitOne(3000)

                              ' Check initial size
                              Dim sizeA = webView.GetPageSize() ' Returns 800 x 400

                              ' Wait a few seconds (hack) to confirm chart and data table rendered by Javascript
                              Threading.Thread.Sleep(6000)

                              ' Check out size after everything is rendered
                              Dim sizeB = webView.GetPageSize() ' Returns 783 x 821

                              ' SUCCESS but doesn't include all of chart and data table
                              ' Do a capture and have a look at the size in the IDE
                              Dim capture As Object = webView.Capture()
                              Dim size = capture.Size() ' Returns 783 x 400

                              ' SUCCESS but missing scroll bar
                              ' Force a rectangle that is bigger than the chart + data table
                              Dim rect2 As New Rectangle(0, 0, 1000, 1000)
                              Dim capture2 As System.Drawing.Image = webView.Capture(rect2)
                              Dim size2 = capture2.Size() ' Returns 1000 x 1000 as expected
                              capture2.Save("C:\temp\temp2.png", Imaging.ImageFormat.Png)

                              ' FAILURE - capture3 is "Nothing"
                              Dim capture3 As System.Drawing.Image = webView.Capture(excludeScrollBars:=False)
                              ' Throws exception due to capture3 being "Nothing"
                              Dim size3 = capture3.Size()
                          End Function)


eo_support
Posted: Wednesday, January 29, 2020 10:30:20 PM
Rank: Administration
Groups: Administration

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

There is no easy way for you to do that with EO.WebBrowser. However you might consider rendering the page into PDF first, then use the PdfRender object to render a specific PDF page into PNG file. This way you don't have to use WebView.Capture at all. You can also set HtmlToPdf.Options.GeneratePageImages to get the page images instead of using a PdfRender object.

Thanks!
Frank
Posted: Wednesday, January 29, 2020 11:05:20 PM
Rank: Newbie
Groups: Member

Joined: 1/29/2020
Posts: 2
Perfect (PdfRender) - got it working. Thank you for the fast reply!
-Frank.
eo_support
Posted: Thursday, January 30, 2020 6:24:29 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,201
Great!


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.