Save complete page in htmlviewer as jpg

Is it possible to save the page visible in the htmlviewer as an image to file? I mean the whole page, not just the visible part.

Which platform? Mac, Windows, Linux or iOS?

e.g. For MacOS with MBS Xojo Plugins and WebVIewMBS class:

[code]Dim webview As webviewMBS = HTMLViewer1.WebVIewMBS
Dim i As NSImageMBS = webview.RenderWebsiteImage

Dim p As String = i.JPEGRepresentation

Dim f As FolderItem = SpecialFolder.Desktop.Child(“test.JPG”)

Dim b As BinaryStream = BinaryStream.Create(f, True)
b.Write p[/code]

htmlviewer.drawinto a graphic object , so use the graphics of a picture ?

Nothing happen, nothing appears on the canvas.

Var p As New Picture(htmlviewer1.Width, htmlviewer1.Height) htmlviewer1.DrawInto(p.Graphics, 0, 0) Canvas1.Backdrop = p

Unfortunately, DrawInto does not necessarily work. At least in Windows, it does not with HtmlViewer.

from the command line with chrome or firefox
works on macOS and windows

@Christian Schmitz do you have a windows example ?

[quote=470753:@Christian Schmitz]e.g. For MacOS with MBS Xojo Plugins and WebVIewMBS class:

[code]Dim webview As webviewMBS = HTMLViewer1.WebVIewMBS
Dim i As NSImageMBS = webview.RenderWebsiteImage

Dim p As String = i.JPEGRepresentation

Dim f As FolderItem = SpecialFolder.Desktop.Child(“test.JPG”)

Dim b As BinaryStream = BinaryStream.Create(f, True)
b.Write p[/code][/quote]

Do you have a working example how to save the whole page as jpg for Windows and Mac/Linux?
Same for saving just a specific part, like 1024x768 or 1280x720 etc.?
I am looking for a crossplatform solution (Desktop, Windows, Mac, Linux).

We do have IEImageMBS function on HTMLViewer control.
You can use IEScrollHeightMBS and IEScrollWidthMBS to query size.
With the size you can resize HTMLViewer to show whole page and then ask for the picture.

[quote=470912:@Christian Schmitz]We do have IEImageMBS function on HTMLViewer control.
You can use IEScrollHeightMBS and IEScrollWidthMBS to query size.
With the size you can resize HTMLViewer to show whole page and then ask for the picture.[/quote]

Does that work crossplatform or do I need for each platform another plugin?

HTMLViewer is different on each platform!

[quote=470912:@Christian Schmitz]We do have IEImageMBS function on HTMLViewer control.
You can use IEScrollHeightMBS and IEScrollWidthMBS to query size.
With the size you can resize HTMLViewer to show whole page and then ask for the picture.[/quote]

I tried with IEImageMBS, but the picture created is too large.
IEScrollHeightMBS return 3191, but the picture saved to file has a height of 4184, so it has lots of white at the end.

Well, scroll height can be queried to resize the control to have the right size.
As the image is based on the control size.

I do that. The issue is HiDPI. I am running a 4K monitor with 150% scaling.
When I disable HiDPI support in Xojo, its about right (Scrollbars are still there, even I resize the htmlviewer to the result of IEScrollHeightMBS).

there are ways to get Firefox and chrome to do a snapshot of a page given a url
completely headless and in the background

see https://www.bleepingcomputer.com/news/software/chrome-and-firefox-can-take-screenshots-of-sites-from-the-command-line/

[quote=471411:@Norman Palardy]there are ways to get Firefox and chrome to do a snapshot of a page given a url
completely headless and in the background

see https://www.bleepingcomputer.com/news/software/chrome-and-firefox-can-take-screenshots-of-sites-from-the-command-line/[/quote]

It only makes a screenshot 800x600, not the whole loaded page b default. And even you set a size, how do you know the size of the loaded page?

[quote=470912:@Christian Schmitz]We do have IEImageMBS function on HTMLViewer control.
You can use IEScrollHeightMBS and IEScrollWidthMBS to query size.
With the size you can resize HTMLViewer to show whole page and then ask for the picture.[/quote]

Unfortunately, when setting the htmlviewer to native, it does not render all pages properly, and when I set it to WebKit, it renders all just fine, but IEScrollheightMBS return always 0.

Note that this is just WIndow, no other target for now.

I’ve used this to make them whatever size I want (2560 x 1440) :slight_smile:
you can control the window size - there are hundreds of command line options for chrome (not quite so many for firefox)

[quote=471418:@Norman Palardy]I’ve used this to make them whatever size I want (2560 x 1440) :slight_smile:
you can control the window size - there are hundreds of command line options for chrome (not quite so many for firefox)[/quote]

  1. How do I know what the height of the loaded page is, so i can set the height properly? I cant…
  2. It require the Enduser to have Chrome installed. I cannot assume that this will be always the case.