Page 1 of 1

How to take screenshot by CEF?

PostPosted: Sun Apr 30, 2017 12:49 am
by milaneuo
Hi all:
How to take screenshot of the webpage by CEF c++.
Thanks very much.

Re: How to take screenshot by CEF?

PostPosted: Sun Apr 30, 2017 12:24 pm
by Czarek
In windowed mode you can render window contents to a bitmap using native APIs.
In off-screen-rendering mode implement CefRenderHandler and at least two of its callbacks: GetViewRect and OnPaint.

If you don't mind using Python then there is a simple example "screenshot.py" in CEF Python. It uses off-screen rendering mode. This code could also act as a reference in writing C++ equivalent code. See: https://github.com/cztomczak/cefpython/ ... eenshot.py

Re: How to take screenshot by CEF?

PostPosted: Mon May 01, 2017 10:58 pm
by Czarek
Chrome v59 now supports headless mode which has some interesting flags. Running with --screenshot will produce a file named screenshot.png in the current working directory:

Code: Select all
chrome --headless --screenshot https://www.chromestatus.com/

# Size of a standard letterhead.
chrome --headless --screenshot --window-size=1280,1696 https://www.chromestatus.com/

# Nexus 5x
chrome --headless --screenshot --window-size=412,732 https://www.chromestatus.com/


I don't think CEF supports the --screenshot flag though.

Ref: https://developers.google.com/web/updat ... ess-chrome