Page 1 of 1

Re: Printing on wrong paper size

Posted: Tue Apr 04, 2017 7:35 am
by salvadordf
grl wrote: Mon Apr 03, 2017 7:44 pm But on one of those the printer will constantly choose the wrong paper size. You can open the printer properties in the printing dialog and change it there then the printout is just fine. But the next report it's back to the old setting.
Looks like the default paper size for that printer in that computer is not configured correctly.

Maybe this could help you :
https://support.microsoft.com/en-us/hel ... paper-size

Take a look at all the tabs and "advanced properties" buttons inside the "properties" of that printer.
Some times you have to set the right page size in several places.

Re: Printing on wrong paper size

Posted: Tue Apr 04, 2017 11:29 am
by salvadordf
Sorry, I misunderstood you.

There's a function in TCefBrowserProcessHandler called "get_print_handler".
According to the CEF3 sources in /include/capi/cef_browser_process_handler_capi.h that function returns the handler for printing in LINUX but it has exactly what you need : access to the printer settings.

Right now CEF4Delphi doesn't implement that function because this project only works in windows but I'll take a look...

Re: Printing on wrong paper size

Posted: Tue Apr 04, 2017 12:34 pm
by salvadordf
I found this CEF3 feature request :
https://bitbucket.org/chromiumembedded/ ... ns-to-cef3

It seems that the feature you need is still pending... :oops:

As a workaround maybe you could use javascript to print. You could inject CSS to set the printing page size and then call the javascript function window.print() :
http://stackoverflow.com/questions/1664 ... paper-size
http://stackoverflow.com/questions/1545 ... javascript

Re: Printing on wrong paper size

Posted: Thu Apr 06, 2017 8:16 am
by salvadordf
Download the latest CEF4Delphi. It has a couple of new context menu options that modify the HTML to set a new printing page size and another option to print from javascript.

Re: Printing on wrong paper size

Posted: Wed Jan 16, 2019 5:48 pm
by salvadordf
The CSS modifications I mentioned in this thread are included in the MiniBrowser demo.

To test them you need to do the following :
  • Right-click on a web page and select "Modify HTML document" to add a few CSS lines at the end of the HEAD element. Open the DevTools to check if the web page you're trying to print has included this new CSS code :

    Code: Select all

    <style type="text/css">@page {size: A4; margin: 0;} @media print {html, body {width: 210mm; height: 297mm;}}</style>
  • Then you can right-click again and select the "Print using JavaScript" option to print the web page.

Here's the procedure that executes JavaScript to add the new CSS code as the last HEAD child element :
https://github.com/salvadordf/CEF4Delph ... r.pas#L478

This CEF3 feature is not implemented and the printer settings can't be changed :
https://bitbucket.org/chromiumembedded/ ... ns-to-cef3

Use the "Print using JavaScript" option in the context menu to print using "window.print();"