3

In Chromium, as in other web browsers, there is a Print function, which includes printing to physical printers, as well as a "Print to File" function.

The default paper size for the physical printers appears to be set to the same default paper size as the printer settings in CUPS itself. So those are fine.

However, the default paper size for the "Print to File" option is set to "US Letter", and I can't figure out how to change it. This has been asked on SuperUser two and a half years ago, at time of writing, but there were no sensible answers given. I could not find any obvious issue or bug for this. Am I missing something?

My (possibly naive) expectation was that Chromium would get it from a default system setting. The obvious setting is /etc/papersize, which happened to be set to letter. I changed it to a4 and restarted the browser, but it doesn't make any difference.

The version of Chromium I am using is 35.0.1916.153-1~deb7u on Debian 7.6 (wheezy), the current default version for that release.

UPDATE: Reported this to the Chromium issue tracker as Chromium browser does not allow setting the default paper size for “Print to File”, but I'm not holding my breath for a reply.

UPDATE 2: @don_crissti pointed out that Chromium got its default paper size in "Print to File" from LC_PAPER, or at any rate, it is one of the things it looks at. I verified this. I had earlier seen some stuff on the web about this, including this Mozilla bug report with a entry by our very own @derobert, but had not taken the possibility seriously enough to check it out.

Here, of course, is also a Debian bug report: Use LC_PAPER.

Extra points for anyone who can document how this is done in the Chromium source.

Faheem Mitha
  • 35,108
  • Interesting. LC_PAPER is unset here, though. What value does it have for you? – Faheem Mitha Aug 07 '14 at 21:04
  • @don_crissti I tried this, and to my surprise, it worked. I closed all chromium windows, set export LC_PAPER=fr_FR.UTF8, and hey presto, I got A4. You should write an answer. – Faheem Mitha Aug 07 '14 at 22:20

2 Answers2

2

It's actually a default set by GTK2 (the widget toolkit used by Chromium, as well as many other programs).

The default is determined in gtk/gtkpapersize.c, function gtk_paper_size_get_default. In order of preference, it gets its paper size from:

  1. nl_langinfo, on systems where that can return paper size. AFAIK, Linux/glibc is not one of those, so this step isn't relevant on Linux. It'll only take A4 or Letter as a default, it'll ignore any other sizes (and continue on with the rest of these steps to get either A4 or Letter).
  2. Next, it'll get locale information. It'll use the LC_PAPER category if available, otherwise, it'll use LC_MESSAGES. Linux/glibc has LC_PAPER, so that's the category it'll use. The locale information is returned as, according to the Single Unix Specification, "a string associated with the specified category for the locale". In short, something like en_US.UTF-8.
  3. If it didn't get a locale string, it assumes A4, and is done.
  4. Otherwise, it compares the locale string against a hardcoded list of country codes for places that use US Letter. Those are (at least in my version of gtk2) BZ, CA, CL, CO, CR, GT, MX, NI, PA, PH, PR, SV, US, and VE. There is a comment saying that list comes from the Unicode Territory-Language Information If the locale is on that list, it returns Letter. Otherwise, it returns A4.

As a side note, the locale is configured in several places. For the LC_PAPER category, the search order is (according to man 7 locale): 1, the LC_ALL environment variable; 2, the LC_PAPER environment variable; 3, the LANG environment variable.

derobert
  • 109,670
1

I think Chromium sets the default paper size based on your current locale settings. If you start it from terminal with some euro LC_PAPER setting, e.g.

LC_PAPER=fr_FR.utf8 chromium

or

LC_PAPER=en_GB.utf8 chromium

it should default to A4 when Printing to File.

don_crissti
  • 82,805