Screenshot of whole page?

Post Reply
softtouch
Posts: 4
Joined: Tue Jan 14, 2020 8:28 am

Screenshot of whole page?

Post by softtouch » Tue Jan 14, 2020 8:53 am

I need to take a snapshot/save a bitmap of the whole loaded page, not just the visible part, so TakeSnapShot wont do it for me.
Is there any way to do that?
I am using the latest CEF4Delphi with Delphi 10.3.3, if that matter.

User avatar
salvadordf
Posts: 2504
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Screenshot of whole page?

Post by salvadordf » Tue Jan 14, 2020 9:42 am

Hi,

If the page is not too big you can create a browser with the maximum dimensions and call TChromium.TakeSnapshot.
If it's too big you can use JavaScript to scroll and call TChromium.TakeSnapshot several times.

CEF doesn't have an API call to take snapshots and TChromium.TakeSnapshot is the only way we have to take them for the moment.

Perhaps we could use the "html5 canvas" in JavaScript as an alternative to take screenshots :
https://stackoverflow.com/questions/4912092/using-html5-canvas-javascript-to-take-in-browser-screenshots/6678156

softtouch
Posts: 4
Joined: Tue Jan 14, 2020 8:28 am

Re: Screenshot of whole page?

Post by softtouch » Tue Jan 14, 2020 10:00 am

Thank you for the quick response!
The pages are unfortunately big, some more than 4000 pixel, so a TakeSnapShot isn't possible (via resizing the browser).
I am doing it at the moment using TWebBrowser, but TWebBrowser has other issues, so I was hoping I can do it with CEF4Delphi too somehow.
I guess I will then have to live with the TWebBrowser bugs and hoping that some day, CEF4Delphi will have a function to render the document to a bitmap.

User avatar
salvadordf
Posts: 2504
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Screenshot of whole page?

Post by salvadordf » Tue Jan 14, 2020 10:08 am

You can also try a TChromium in OSR mode.

In that mode the page is rendered in a bitmap (or a DirectX texture). You would need to use the TChromium.OnGetViewRect event to set the browser dimensions and you will receive the raw pixels in TChromium.OnPaint.

However, If I remember correctly Chromium has a browser size limit and I'm not sure if you can create a browser with a 4000px height.

Post Reply