Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Printing on wrong paper size

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

Re: Printing on wrong paper size

Post 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.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Printing on wrong paper size

Post 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...
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Printing on wrong paper size

Post 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
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Printing on wrong paper size

Post 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.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Printing on wrong paper size

Post 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();"
Post Reply