cefBrowser borderless printing ?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

cefBrowser borderless printing ?

Postby cbreemer » Thu Jun 16, 2022 4:11 pm

Hi all,

In a nutshell: I am using the CefSharp.WinForms.ChromiumWebBrowser component in a C# application, and I can't get it to print borderless.

My program generates HTML in the browser to render and print an A4 sheet of address labels. The labels extend right up to the edge of the sheet, therefore the printing needs to be borderless, and indeed the print properties specify that. However the Cef browser insists on printing a border (which I have NOT specified in the HTML) so the labels are not positioned correctly. If I do exactly the same but using the good old Windows browser component (System.Windows.Forms.WebBrowser) the sheet is correctly printed, without border. I would happily use the old Windows browser for this lowly purpose were it not for the fact it won't print background color, which the Cef browser does just fine with a suitable CSS tag (which is of course not recognized by the Windows browser). So I'm sort of stuck between a rock and a hard place. I tried the documentation, such as there is, for the Cef browser but I don't see a way to get rid of that border.

Any ideas would be most welcome !

Thanks,
Chris
cbreemer
Newbie
 
Posts: 7
Joined: Thu Sep 23, 2021 12:47 pm

Re: cefBrowser borderless printing ?

Postby amaitland » Thu Jun 16, 2022 4:20 pm

How does Chrome behave at the same version?
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: cefBrowser borderless printing ?

Postby cbreemer » Sat Jun 18, 2022 3:59 pm

amaitland wrote:How does Chrome behave at the same version?

I'm not sure how to correlate the versions of Cef and Chrome, but I am using the most recent versions of both. And if I load my generated HTML in Chrome and print it from there, it's correct - no white border.
cbreemer
Newbie
 
Posts: 7
Joined: Thu Sep 23, 2021 12:47 pm

Re: cefBrowser borderless printing ?

Postby amaitland » Sat Jun 18, 2022 4:13 pm

Load chrome://version in both

Try running chrome with the --no-sandbox command line argument. There have been some quirks in the past when printing that only manifest when sandbox is disabled.

https://peter.sh/experiments/chromium-c ... no-sandbox
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: cefBrowser borderless printing ?

Postby cbreemer » Sun Jun 19, 2022 3:56 am

Thanks for the tips !

Chrome browser:
Google Chrome 102.0.5005.115 (Official Build) (64-bit) (cohort: Stable)

CefSharp browser:
CEF 102.0.9+g1c5e658+chromium-102.0.5005.63
Chromium 102.0.5005.63


The browser's version is a little higher than CEF's, but only a little. Anyway this seems as close as I can get it.
I added the -no-sandbox arg to the CEF params (and it was shown by chrome://version, hence applied correctly) but it did not make a difference.
cbreemer
Newbie
 
Posts: 7
Joined: Thu Sep 23, 2021 12:47 pm

Re: cefBrowser borderless printing ?

Postby amaitland » Sun Jun 19, 2022 2:58 pm

Versions are likely close enough.

I'm suggesting you test chrome with sandbox disabled as CefSharp runs with the sandbox disabled.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: cefBrowser borderless printing ?

Postby cbreemer » Tue Jun 21, 2022 4:08 pm

amaitland wrote:I'm suggesting you test chrome with sandbox disabled as CefSharp runs with the sandbox disabled.

Ah, I misunderstood. Tried it but Chrome prints the same whether or not I add --no-sandbox to the command line (and I got a warning when using the parameter, so I know I did it correctly). No border added at all, which is what I would have expected. I took a photo of my 3 print scenarios: http://home.caiway.nl/~cbreemer/20220621_224513.jpg
On the left is how my program prints using the old Windows WebBrowser. There is a small white border added (my HTML specifies none) but that works just fine for my sheets. But it lacks capability for background color.
In the middle how it prints with CefBrowser. I got the background color but also a large white border, plus the fonts being slightly smaller. Useless for my sheets.
Last on the right how it prints in Chrome (with or without --no-sandbox). No border added at all. I would be happy for CefBrowser to work like this too, as I can always add the required border to my html.
Perhaps I should try specifying a negative margin for use with CefBrowser ?
cbreemer
Newbie
 
Posts: 7
Joined: Thu Sep 23, 2021 12:47 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 36 guests