Last Comment Bug 147419 - Printer paper settings should default to appropriate values for the user/printer
: Printer paper settings should default to appropriate values for the user/printer
: intl
Product: Core
Classification: Components
Component: Printing: Setup (show other bugs)
: Trunk
: x86 Linux
P5 normal with 59 votes (vote)
: mozilla41
Assigned To: Karl Tomlinson (:karlt)
: Jet Villegas (:jet)
: 144625 379074 407406 407418 414041 545937 (view as bug list)
Depends on: 581789
Blocks: 947125
  Show dependency treegraph
Reported: 2002-05-27 11:37 PDT by Markus Kuhn
Modified: 2015-06-18 22:01 PDT (History)
72 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

don't use PS prefs in gtk (1.14 KB, patch)
2011-01-02 08:13 PST, Adrian Johnson
karlt: review-
Details | Diff | Splinter Review
remove ununsed nsIPrintSettings::printCommand and print_command prefs (28.34 KB, patch)
2015-06-10 16:16 PDT, Karl Tomlinson (:karlt)
roc: review+
Details | Diff | Splinter Review
use GTK default paper size and orientation (5.41 KB, patch)
2015-06-10 16:17 PDT, Karl Tomlinson (:karlt)
roc: review+
Details | Diff | Splinter Review
remove print(|.<modulename>)(|.printer_<printername>).filename pref reading code (4.64 KB, patch)
2015-06-10 16:18 PDT, Karl Tomlinson (:karlt)
roc: review+
Details | Diff | Splinter Review
remove meaningless GetPrintMethod() (5.33 KB, patch)
2015-06-10 16:19 PDT, Karl Tomlinson (:karlt)
no flags Details | Diff | Splinter Review
part 5: remove ununsed plexName colorspace resolutionName and downloadFonts (47.86 KB, patch)
2015-06-10 16:20 PDT, Karl Tomlinson (:karlt)
roc: review+
Details | Diff | Splinter Review
part 4: remove meaningless GetPrintMethod() v1.1 (5.46 KB, patch)
2015-06-11 21:20 PDT, Karl Tomlinson (:karlt)
roc: review+
Details | Diff | Splinter Review

Description User image Markus Kuhn 2002-05-27 11:37:34 PDT
The default download binary of Mozilla 1.0rc2 for Linux comes with language
setting en-US only and sets the printing page size at each invocation back to
"US Letter". This is extremely disruptive for most users. The vast majority of
printers (namely practically *every* printer outside the USA and Canada) is fed
with international standard A4 paper.

Similarly, the vast majority of users worldwide are used to think in
millimeters, not inches, but the default margin settings in the print menu use
inches. It is currently not at all obvious for a highly computer literate user
how to change these settings.

A non-North American user should never ever have to worry about the paper size.
No changing to A4 should be necessary ever.

Suggestion: Mozilla for Linux can trivially determine whether it was invoked in
North America by looking at the standard POSIX locale environment variables. The
default settings for printer paper and unit of measurement should be determined
under Linux as in the following example code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* LC_PAPER and LC_MEASUREMENT were introduced
   in  a ISO/IEC TR 14652 draft */

int main()
  char *units = "mm";
  char *paper = "A4";
  char *s;

  if (((s = getenv("LC_ALL"))   && *s) ||
      ((s = getenv("LC_PAPER")) && *s) ||
      ((s = getenv("LANG"))     && *s))
    if (strstr(s, "_US") || strstr(s, "_CA"))
      paper = "Letter";
  if (((s = getenv("LC_ALL"))   && *s) ||
      ((s = getenv("LC_MEASUREMENT")) && *s) ||
      ((s = getenv("LANG"))     && *s))
    if (strstr(s, "_US"))
      units = "inches";

  printf("Paper: %s\nUnits: %s\n", paper, units);
  return 0;

American users should (and with most distributions typically have) LANG=en_US
set (often also with LC_COLLATE=POSIX to prevent ls changing its sorting order),
so they will still get their special national 8.5x11" paper format configured
correctly, without disrupting Mozilla printing worldwide, as it happens at the

Another idea is to include in addition to "en-US" also a language setting "en"
to the default download version of Mozilla. "en" differs from "en-US" in that it
applies ISO standards for default settings instead of US customary values.

en-US: US Letter, inches, mm/dd/yy, am/pm
en:    A4, mm, yyyy-mm-dd, 24-hour time

The default distribution shouldn't force users to use a locale setting (en_US)
that differs so dramatically from international standards.
Comment 1 User image kill this account 2002-05-27 12:19:40 PDT
changed title from:

  Default printer settings set to US Letter and inches


  Printer settings should default to appropiate values for the user

So what works these days?



  nl_langinfo(PAPER_HEIGHT) / nl_langinfo(PAPER_WIDTH)

Comment 2 User image Roy Yokoyama 2002-05-28 13:34:21 PDT
assign to katakai-san.
please have a look. Thanks
Comment 3 User image Kai Lahmann (is there, where MNG is) 2002-08-04 18:46:13 PDT
what's the status of this?
Comment 4 User image Masaki Katakai 2002-08-05 03:05:40 PDT
I've started working on this.
Comment 5 User image Etienne Goyer 2006-10-13 13:32:19 PDT
This issue also affect Thunderbird (tested on Ubuntu 6.10).
Comment 6 User image Fabian Rodriguez 2007-01-16 20:12:38 PST
This bug seems to be the same as .

Will be marking that one as duplicate.
Comment 7 User image Antony Gelberg 2007-03-11 06:00:07 PDT
Masaki, are you still working on this?
Comment 8 User image Fabian Rodriguez 2007-04-11 16:06:43 PDT
Masaki, can you provide any feedback on this ? A month has gone by. Thank you.
Comment 9 User image Masaki Katakai 2007-04-11 21:28:00 PDT
I'm very sorry for the late response. I will not be able to work on this area. Anyone can take this?
Comment 10 User image Anthony DeRobertis 2007-09-01 23:49:23 PDT
*** Bug 144625 has been marked as a duplicate of this bug. ***
Comment 11 User image Gero Mudersbach 2007-09-02 07:22:33 PDT
Since Masaki can't work on this, shouldn't the bug be marked as NEW then?
Comment 12 User image Christoph Laszlo 2007-10-06 13:24:25 PDT
This bug is really annoying. Is anyone interested in solving it? Is there a usual way to support (financially) someone?
Comment 13 User image Andreas Krüger 2008-08-28 01:54:01 PDT
Known workaround (for the "highly computer literate"):

Print into some "virtual printer"
that accepts letter page size and generates PDF,
start some PDF viewer on the output,
set the page size to A4 in the PDF viewer, and "shrink page to fit paper",

There must be a better workaround.
How can I set the page size for one single print job?
Comment 14 User image Nick Urbanik 2008-12-22 23:43:52 PST
This problem has returned with a vengeance with Firefox 3.  3.0.5 implements
this Letter size default in a most annoying way that is really a challenge to override.

I am attempting now to determine what action I can take through the 'about:config" page.
What is the meaning of the '666' value in print.printer_CUPS/hp4l.print_paper_size?
Comment 15 User image Nick Urbanik 2008-12-22 23:57:52 PST
On this (continuously upgraded from previous versions) Fedora 10 system,
$ cat /etc/papersize
$ echo $LC_PAPER

So will try to set LC_PAPER (which should really be deduced
from my setting of LANG).
$ env | grep -i en_au
Comment 16 User image Nick Urbanik 2008-12-23 00:09:35 PST
With LC_PAPER set to a4, I get:
(process:22371): Gtk-WARNING **: Locale not supported by C library.
	Using the fallback 'C' locale.

(firefox:22371): Gdk-WARNING **: locale not supported by C library
With this unset, firefox starts without complaint.
I have changed the content of /etc/papersize to
in case that helps.
Comment 17 User image era+mozilla 2009-01-06 10:58:52 PST
smontagu: are you actually working on this?  What's the status, please?
Comment 18 User image Sebastian J. Bronner 2009-01-07 08:37:38 PST
I have volunteered to take on this issue (note: I am not smontagu) with the aim of writing a patch. Since I am not a regular mozilla code contributor, the bug is still assigned to smontagu (perhaps I can be made a co-assignee?)

I have started looking into the mozilla code base in November, and the current status is still familiarization with the code base. I have 16 hours per month to spend on this issue, so it should be possible to make progress, albeit somewhat slowly.
Comment 19 User image Magnus Melin 2009-01-07 09:11:18 PST
Sebastian: assigning to you
smontagu is default assignee for this component, so I would expect he won't object;)
Comment 20 User image Pacho Ramos 2009-01-31 01:13:38 PST
*** Bug 407418 has been marked as a duplicate of this bug. ***
Comment 21 User image Pacho Ramos 2009-01-31 01:14:11 PST
*** Bug 407406 has been marked as a duplicate of this bug. ***
Comment 22 User image era+mozilla 2009-01-31 11:00:49 PST
Comment in duplicate alleges that Mandriva has solved this problem.  I tried to find a public repository of their patches, but gave up.  Perhaps somebody more knowledgeable about their processes and infrastructure could look into this.
Comment 23 User image era+mozilla 2009-02-15 00:02:13 PST
Just for the record, I don't think "a4" is a valid value for $LC_PAPER.  It is not part of the standard locale settings (yet?) so it's not very well documented.  My impression is that you can set LC_PAPER to the name of a valid locale, and then have the paper size from that locale override any other locale settings of yours.  Thus, try e.g. LC_PAPER=en_DK (depending also on what locales are supported on your installation).  But at this time, of course, Mozilla doesn't care at all about the value of this setting (other than including it in crash reports). [1]


@Sebastian J Bronner: have you been making any progress?
Comment 24 User image timeless 2009-02-15 02:01:58 PST
fwiw, the crash reporter is actively ignoring the lc_ stuff, not honoring it ;-)
Comment 25 User image Markus Kuhn 2009-02-15 04:06:24 PST
My original proposal above, from 2002-05-27, namely to decide on preferred units of measurement and standard paper size by searching for country codes in the LC_* environment variables (exactly as suggested in the above piece of code) is IMHO still the most advisable solution today! Please just try it, before thinking up alternatives.

The alternatives simply don't wash: The /etc/papersize mechanism is a complete non-starter, as it is a global setting that you cannot easily override for individual users or processes. The nl_langinfo(PAPER_HEIGHT) / nl_langinfo(PAPER_WIDTH) was a draft proposal (ISO technical report 14652) that only glibc implemented but that never made it into the POSIX standard or any other ISO standard. It won't work on other platforms and just leads to ugly platform-specific #ifdef massacres.

The above code will do the right thing by default on all POSIX platforms (not just Linux) and provides easy and obvious ways for users to override the defaults. It is the most pragmatic and workable solution you are going to find, given the rather messy standardization in this area.

What it does is very simple: The defaults are millimetres and A4 (because that's what ~95% of the world population use), and only if your environment suggests that you are in Canada or the U.S. will the default paper size become U.S.-Letter, and only if you are in the U.S. will the default unit of measurements become inches. This will be determined by the first of the variables LC_ALL, LC_{PAPER,MEASUREMENT}, LANG that is defined and non-empty, exactly the same priority order that setlocale() applies, but implemented in a strictly portable way without requiring the setlocale() implementation to even know of LC_{PAPER,MEASUREMENT}.

The inclusion of LC_{PAPER,MEASUREMENT} makes sure that users can override their countries' default for paper and measurement without affecting anything else. On the day when the U.S. finally goes metric, simply set LC_MEASUREMENT=POSIX and its done.
Comment 26 User image era+mozilla 2009-02-15 08:07:33 PST
Shouldn't the more-specific LC_PAPER and LC_MEASUREMENT be allowed to override LC_ALL if they are present, though?  (Pardon my ignorance.)
Comment 27 User image Markus Kuhn 2009-02-15 14:35:34 PST
No, the whole purpose of LC_ALL is to allow you to override everything else, whereas the purpose of LANG is to provide the lowest-priority default. The more specific LC_* environment variables are placed between those two extremes in the priority order. (I regularly write LC_ALL=C to force all locale mechanics off in tests.)

Reference: POSIX, section 8.2 (Internationalization Variables): "The value of the LC_ALL environment variable has precedence over any of the other environment variables starting with LC_"

To understand the definition of these environment variables, read
Comment 28 User image era+mozilla 2009-02-16 00:59:54 PST
Thanks for the solid clarification.  It's odd how sparsely documented this is, at least on Linux.
Comment 29 User image era+mozilla 2009-02-19 01:12:51 PST
(In reply to comment #22)
> Comment in duplicate
> alleges that Mandriva has solved this problem.  I tried to find a public
> repository of their patches, but gave up.

I installed Mandriva Linux Free 2009.0 in Virtualbox.  It's got Firefox 3.0.5.  Even though I set up my regional settings to prefer A4 paper, Page Setup in Firefox defaults to letter.  So there doesn't seem to be any basis for the claim that Mandriva has fixed this.
Comment 30 User image Michel Loiseleur 2009-02-19 01:19:24 PST
This problem is the same on Ubuntu Hardy LTS. 
Does someone know how to make Firefox 3 understand that I want A4 paper by default? Without using GUI, of course, since it's for a Firefox Linux deployment, not for a personal Desktop.
I have tried without success to play with prefs.js, with *.rdf files, with gnome-printer-settings, with gtk-printer-settings, with gconf-editor and no success with all of these approaches.
Comment 31 User image James Henstridge 2009-02-19 02:51:42 PST
Given the ubiquity of Linux compared to other unix systems (ignoring MacOS, which has its own port), is it really such a problem to include platform specific code, provided there is a reasonable fallback for other systems?

There is an API that will provide the locale default paper size, so it seems silly to rely on heuristics instead.
Comment 32 User image Sebastian J. Bronner 2009-02-19 04:50:51 PST
(In reply to comment #23)
> @Sebastian J Bronner: have you been making any progress?

No progress to report yet, but I am continuing to work on the issue as time permits.
Comment 33 User image Sebastian J. Bronner 2009-02-19 05:17:57 PST
(In reply to comment #25)
> My original proposal above, from 2002-05-27, namely to decide on preferred
> units of measurement and standard paper size by searching for country codes in
> the LC_* environment variables (exactly as suggested in the above piece of
> code) is IMHO still the most advisable solution today! Please just try it,
> before thinking up alternatives.

My proposol for implementation is to check for the proper paper size setting by stepping through the following items. The first successfully determined value would be used:

1 - if it exists, use a firefox-specific setting
    stored in the user's firefox profile
2 - infer paper size from LC_ALL
3 - infer paper size from LC_PAPER
4 - infer paper size from LANG
5 - if it exists, read paper size from /etc/papersize
6 - retrieve paper size from cups (if that is possible)
7 - default to a4


I have left LC_MEASUREMENT out of this list purposely because it really has no direct bearing on paper. A user may wish to specify different measurement units, but wouldn't expect his locale's paper size to change because of that.

Step 1 - the firefox-specific setting is for users who don't care about user profiles. The user would be able to make a choice in a dialog between a specific paper size and "locale default" (or similar). This would be set to "locale default" unless the user specifically changes it.
Comment 34 User image Markus Kuhn 2009-02-19 05:59:39 PST
Just for the record: only on glibc systems, an API for interpreting the LC_PAPER aspect of the locale setting is

#include <stdio.h>
#include <langinfo.h>
#include <locale.h>

int main()
  if (!setlocale(LC_PAPER, "")) {
    fprintf(stderr, "Can't set the specified locale! "
            "Check LANG, LC_PAPER, LC_ALL.\n");
    return 1;
  printf("paper height = %d mm\n", (int) nl_langinfo(_NL_PAPER_HEIGHT));
  printf("paper width  = %d mm\n", (int) nl_langinfo(_NL_PAPER_WIDTH));
  return 0;

which results in

$ LC_ALL=en_GB.UTF-8 ./lc_paper
paper height = 297 mm
paper width  = 210 mm
$ LC_ALL=en_US.UTF-8 ./lc_paper
paper height = 279 mm
paper width  = 216 mm
$ LC_ALL=en_CA.UTF-8 ./lc_paper
paper height = 279 mm
paper width  = 216 mm

I just checked with

  for l in `locale -a` ; do echo $l: ; LC_ALL=$l ./lc_paper ; done

all glibc locales on openSUSE 10.3 and found in addition to US and CA only one other country code whose locales specify the U.S. Letter format: PR = Puerto Rico.

So please change in my original test code the term

  strstr(s, "_US") || strstr(s, "_CA")


  strstr(s, "_US") || strstr(s, "_CA") || strstr(s, "_PR")

to make its results compatible with glibc.
Comment 35 User image Markus Kuhn 2009-02-19 06:09:15 PST
The file /etc/papersize is a configuration file of the groff text formatting package. It is not mentioned in any API standard. I strongly recommend that Firefox ignores groff configuration files.

This file really should have been called something like /etc/groff/papersize or, even better, groff should have used LC_PAPER instead, as proposed here for Firefox. Let's not perpetuate a mistake made in the design of groff by carrying it over into a web browser. One locale mechanism is enough. Forget about /etc/papersize.
Comment 36 User image Matthias Andree 2009-02-20 04:59:21 PST
If nobody else has the time, perhaps the fix could be made a Google summer of code project?
Comment 37 User image Gerwin 2009-03-10 23:53:28 PDT
This is one of the most annoying bugs if your using FF in a business deployment.
It's really annoying that the printers stops working after it receives a Letter print job.

Also Mozilla Prism is facing the same problems (same code base I guess). Is there a way we can vote for this bug or something?
Comment 38 User image era+mozilla 2009-03-15 18:59:02 PDT
@Gerwin: there is a "vote" link next to the Importance field at the top of the Bugzilla web page for this bug report (which you will find a link to if you read this over email; I believe you will need to be logged in to your Bugzilla account in order to be able to vote, and possibly even see the "vote" link).
Comment 39 User image Francois Cartegnie 2009-03-16 11:21:47 PDT
With FF3, printing a small sized page (popup format) forces printer into "Letter" while it's configured to "A4", making it unprintable.

Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/2009031120 Mandriva/ (2008.1) Firefox/3.0.7

Can't reproduce it with Seamonkey
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20081216 SeaMonkey/1.1.14

related to bug 379074
related to Bug 414041 ?
Comment 40 User image timeless 2009-04-05 05:47:32 PDT
*** Bug 414041 has been marked as a duplicate of this bug. ***
Comment 41 User image timeless 2009-04-05 05:48:42 PDT
*** Bug 379074 has been marked as a duplicate of this bug. ***
Comment 42 User image timeless 2009-04-05 06:05:23 PDT
does it really make sense to favor LC_anything over CUPS settings?

if i have two printers and one is using metric and one is using letter, surely i can't possibly want an env var to break one or the other.

note that using setlocale() is not something I'd want to see. We do not need to have our fragile code confused by something which will almost certainly confuse it on random systems and in random places. Yes that means someone might be forced to parse a couple of env vars manually, however, that's life and it's better than breaking the rest of our code.

1 - if it exists, use a firefox-specific setting
    stored in the user's firefox profile
2 - retrieve paper size from gtk 
    (and hence cups)
3 - infer paper size from LC_ALL
4 - infer paper size from LC_PAPER
5 - infer paper size from LANG
6 - if the system is using something that hints it isn't en-US default to a4

There are lots of people in the US, and just because I'm one of the stupid ones who isn't there doesn't mean we should magically do something strange to their systems.

afaict, we use something called gtk_paper_size_get_name today and have since bug 193001 was fixed in 2008.

it's documented here: 

Perhaps someone could figure out why it isn't doing the right thing instead of complaining about our behavior?

reporter: since you're able to use a compiler, could you please investigate?

someone who doesn't have a compiler is free to find a typical gnome app and (something like gedit) and indicate whether it gets this stuff right. if it does, then you could perhaps try to find someone who can compare our code (it's in the one file i listed above) with the gtk app's code.
Comment 43 User image Roderick Jameson 2009-04-07 19:42:56 PDT
@timeless: gedit gets it right, at least on my system. So do leafpad, evince, dictionary, eog, and in fact every other app except Firefox.
Comment 44 User image Francois Cartegnie 2009-04-16 10:33:45 PDT
Should change this bug to something more important than a simple "enhancement".
For me, Firefox isn't able anymore to do a direct print to a laser printer.
Comment 45 User image timeless 2009-05-03 09:30:33 PDT
roderick: cool, so please pick one and figure out what they're doing.

because i'd expect an app like gedit to use the gtk api and get data from cups.

or do you people really not have cups installed?
Comment 46 User image Oskar Eisemuth 2009-05-14 01:29:41 PDT
I have some more infos in Bug 478733

Actually I do think printing resets always to A4 currently if the paper size doesn't match the internals. I do think LC* is the wrong way.

Actually any hard paper setting is very wrong because I need to switch between A4 and POS Printing.

I tested on the same CUPS Setup:
Firefox 3.0.6 => Tries to always Print A4 on the pos printer, grrr!
Epiphany (Gecko) => Result was a bit better, but not perfect. 
Margins couldn't be disabled, so not usable at all.

Midori Browser (Webkit+GTK) => This was the best experience, no margin problems, printing works on the POS Printer, yay!
Comment 47 User image Francois Cartegnie 2009-09-16 06:10:19 PDT
My LC_PAPER=fr_FR and it stills try to print in US Letter format, which printer rejects. (no suitable tray).

Besides, for similar documents, the first print goes OK and prints to A4. The next ones goes to US Letter.

Something is really messed up. What are the differences with current Seamonkey (which works) ?
Comment 48 User image m 2009-12-09 13:00:47 PST
This bug has been reported back in 2002, it's 7 years now and it's still not resolved. I just spent an hour trying to force cups-pdf to produce A4 pdf instead of US Letter.

Why firefox ignores printer settings at takes a value from system's default? even though my LC_PAPER=en_GB suggests it should print on A4, it still prints on US Letter.

I had to set values (paper name, paper sizes) manually in order to get my cups-pdf working.
Comment 49 User image Sebastian J. Bronner 2009-12-18 06:35:18 PST
I've been scouring the firefox code-base repeatedly with all sorts of search terms, and I can't seem to find the code that makes the decision about what paper size to use when printing.

I'm still looking, but if anybody knows something, I'd be grateful for a pointer.
Comment 51 User image Jos 2010-01-29 12:02:20 PST
Paper size should NOT be linked to language, but to location.
One can use any language in any country, but in most cases, you can only buy one type of paper size in a particular country or continent, e.g. A4 in Europe, Letter in US (for any language).
Comment 52 User image Francois Cartegnie 2010-02-16 06:06:40 PST
Here's an update:

Printing 2 pages document gives 1 correct A4, and the 2nd as US.

When you try to print, you can't select paper tray and the menu is grayed/stuck to "US Letter".

** workaround **
Now, if you "Print Preview", and you can change the document layout to A4 from the menu (footers options/ ...) and it's no longer US Letter. It Prints.

Pls some ppl confirm this.
Comment 53 User image MrJ 2010-04-14 07:10:50 PDT
Hi Francois,

I can confirm this behaviour! If you then go back to Print->Page Setup, you then find that Paper Size is now set to A4.

This is in FF 3.5.9
Comment 54 User image MrJ 2010-04-14 07:11:58 PDT
Also, settings are changeable in Page Setup.
Comment 55 User image Dwayne Bailey 2010-05-06 00:19:13 PDT
*** Bug 545937 has been marked as a duplicate of this bug. ***
Comment 56 User image Marek Sykora 2010-05-07 05:10:22 PDT
I can confirm this behavior with Firefox 3.5 on Ubuntu 9.10
Comment 57 User image Berend De Schouwer 2010-07-06 07:14:56 PDT
I can confirm the print preview from #52, and #53.

I've got a printer here with multiple types of stationary (A3, A4, ...) -- except I can't actually buy US Letter.

I suggest you don't ask the printer for paper size, since it actually accepts print jobs for US Letter, but expects me to go buy stationary before it's willing to print.

It should default to something sane (locale and /etc/papersize have settings) and allow the user to change per printjob.
Comment 58 User image Berend De Schouwer 2010-07-08 04:35:10 PDT
It's possible to select stationary in Firefox 4 Beta 1
Comment 59 User image Simon Montagu :smontagu 2010-07-16 04:33:03 PDT
I've been debugging this a bit. The default "US Letter" setting comes from the following lines in nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter

  nsXPIDLCString papername;
  if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "paper_size", papername))) {
  nsPaperSizePS paper;

  if (paper.Find(papername)) {
    DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g mm/%g mm)\n",
                     paper.Name(), paper.Width_mm(), paper.Height_mm()));

It would be better to just call SetPaperName with null and let gtk_paper_size_new set it to the locale default. Better still would be to pull in the system settings for the printer, but I'm not sure how to do that.
Comment 60 User image m 2010-08-04 14:14:03 PDT
This is still not solved for me - I've got an A4 printer paper selected in Firefox, I've got A4 selected in CUPS-PDF and I get US Letter print-out.
Comment 61 User image Adrian Johnson 2011-01-02 08:13:05 PST
Created attachment 500694 [details] [diff] [review]
don't use PS prefs in gtk

The attached patch fixes this problem for me.

In widget/src/xpwidgets/nsPrintOptionsImpl.cpp the page size is read and written to the prefs of the form:


where NAME is the printer name.

In widget/src/gtk2/nsDeviceContextSpecG.cpp the page size is read but not written from the following prefs:


The problem is the prefs read in nsDeviceContextSpecG.cpp are not the same as the prefs written in nsPrintOptionsImpl.cpp. If these prefs do not exist there is no problem as the prefs read in nsPrintOptionsImpl.cpp are used. However I have found that in a newly created profile the pref "print.postscript.paper_size = letter" always exists. This will always be read and override the saved paper size. As it is not written, the "letter" default will not go away.

The attached patch changes the module name used when reading prefs in nsDeviceContextSpecG.cpp from "postscript" to null so the "print.postscript.paper_size" pref is never read. I am assuming the "postscript" module name is leftover from before gtkprint was used.

With the patch applied and using a newly created profile the default paper size will be the gtk_paper_size_get_default() paper size which is based on the current locale. After printing for the first time the selected page size is correctly saved and restored the next time the print dialog is opened.
Comment 62 User image Michel Loiseleur 2011-01-03 00:56:08 PST
Adrian : It seems really great. I hope that it could be commited into trunk for both Thunderbird & Firefox.
Comment 63 User image Launchpad 2011-01-10 09:55:30 PST
Paolo S added the following comment to Launchpad bug report 10910:

Hello. I'am italian. I have the same problem.. System default paper=A4. All other program work fine. I want to print in firefox 3.6.13, but the default in firefox is always letter. I set to A4 but firefox always forget that. It always start with letter size.
Please help me. Thanks in advance

Comment 64 User image Karl Tomlinson (:karlt) 2011-01-17 16:39:09 PST
The evil print.postscript.paper_size letter default comes from bug 125078 and
I don't see any means provided for changing the default.

initPrintSettingsFromPrinter was meant to get setting from the printer and the
xprint backend implementation appropriately asked the system for available
paper sizes.  It seems print.postscript.paper_size pref was just a space
filler for lack of a postscript implementation.

savePrintSettingsToPrefs and printer-specific prefs in
initPrintSettingsFromPrefs weren't added until bug 128142 and they now seem
the appropriate place for managing preferences.

So I agree that it is better to leave the paper settings at their default than
to pull in this arbitrary default.
Comment 65 User image Karl Tomlinson (:karlt) 2011-01-17 16:40:40 PST
Comment on attachment 500694 [details] [diff] [review]
don't use PS prefs in gtk

However, the way that this patch avoids the arbitrary default adds to the
existing confusion.  It works because the pref lookup no longer matches the
pref setting.  It would be better to remove the pref and the lookup code.

One of the (many) strange things about the print setup code, is that the list
of (basic standard) paper sizes is only added to
print.tmp.printerfeatures.paper.* if a paper_size pref is found, and that will
rarely be anything but "print.postscript.paper_size".
(The initial implementation was added in bug 132563.)

print.tmp.printerfeatures.paper.* is only used from
toolkit/components/printing/content/printjoboptions.js, as a set of available
paper sizes.  AFAICS however, that is only used if
nsPrintingPromptService::ShowPrintDialog cannot find nsIPrintDialogService.
Now that the GTK port provides a nsIPrintDialogService, there is no need to
set up print.tmp.printerfeatures.paper.*

So it safe to remove the whole paper_size block
Comment 66 User image Launchpad 2011-01-22 02:13:37 PST
Paolo S added the following comment to Launchpad bug report 10910:

I found solution to my problem by doing this:
1-assured that in /etc/papersize there is written only a4.
2-open /usr/share/ghostscript/8.71/lib/ghostpdf.ppd and erase every line with inside the word "letter".
3-open /etc/cups/ppd/KM-1635.ppd (instead of  KM-1635 use the name of the printer that doesn't print to a4) and delete the line where there's write letter/letter like this

*PageSize Letter/Letter: "%% FoomaticRIPOptionSetting: PageSize=Letter"
*FoomaticRIPOptionSetting PageSize=Letter: "-p1 "

*PageRegion Letter/Letter: "%% FoomaticRIPOptionSetting: PageSize=Letter"

*ImageableArea Letter/Letter: "12.00 12.00 600.00 780.00"

*PaperDimension Letter/Letter: "612 792"

4)changed in firefox at about:config every line where there's letter on na_letter or letter to a4 and the dimension of that format forced to height 297 and width 210. when i restart firefox the values of print.postscript.paper_size was returned to letter for example but the printer print correctly to a4.

Sorry for my english... Bye

Comment 67 User image Launchpad 2011-01-22 02:34:33 PST
Paolo S added the following comment to Launchpad bug report 10910:

i add to /etc/environment a line, too


i'm not sure but i think this don't do nothig....


Comment 68 User image Junya Keller 2011-02-03 01:58:26 PST
I prefer changing /etc/default/locale from en_US to en_GB in which changes the printing defaults from letter to A4:

sudo /usr/sbin/update-locale LANG="en_GB.UTF-8"
Comment 69 User image Launchpad 2011-02-04 03:42:59 PST
Nick Moffitt added the following comment to Launchpad bug report 10910:

JunyaKeller: That may work fine for you, but I am an American living in England.  I have US keyboard layout, spell "color" without a 'u', and otherwise prefer an en_US locale.  The only thing that changes for me is the default paper geometry in printers I use.  

If LC_PAPER were honored more widely as an override, I think that would be the correct solution.

Comment 70 User image Nik Trevallyn-Jones 2011-07-06 21:31:19 PDT Comment hidden (obsolete)
Comment 71 User image Karl Tomlinson (:karlt) 2011-07-06 22:32:54 PDT
Best file a separate bug, thanks Nik.
This bug is about the Linux implementation while you are seeing a problem on MS Windows.  Fixing this bug will not fix your issue.
Comment 72 User image Nik Trevallyn-Jones 2011-07-06 23:37:42 PDT Comment hidden (obsolete)
Comment 73 User image Teemu Leisti 2012-03-25 15:23:48 PDT
I just did a new installation of Xubuntu 11.10, and then upgraded all the packages. The resulting Firefox version is 11.0.

I changed the contents of my /etc/defaults/locale file to


then logged out and back in again. Now, when I print a page from Firefox, A4 is the paper size used, which is correct, but when I do a print-to-file, the default paper size is still letter. So this bug has not yet been completely fixed.

By the way, it's coming up on the bug's tenth birthday. Should we get together to buy something nice for it, what do you say?
Comment 74 User image Teemu Leisti 2012-06-03 05:21:08 PDT Comment hidden (advocacy)
Comment 75 User image Berend De Schouwer 2013-05-06 01:14:58 PDT
In firefox 20.0, print to file defaults to letter.  If I change this to A4, the PDF file on disk is still marked as size Letter.  So various PDF readers assume it's Letter.
Comment 76 User image Berend De Schouwer 2013-05-06 01:22:13 PDT
in print-to-file I first have to select a different paper size (any different paper size), then re-select A4, then I get A4 paper size in the .pdf.  Otherwise I get letter.

Comment 77 User image Bruce Kingsbury 2013-10-18 22:44:23 PDT
I have just followed the procedure of;

1) Download Firefox-24.0 English(UK) version for Linux
2) Download Firefox-24.0 English(UK) version for Linux again and compare just to be sure I didn't accidentally get the wrong one
3) Check environment and observe LANG=en_NZ.UTF-8
4) Check printer settings and see that default paper size is A4
5) rm -rf ~/.mozilla so there are no previous settings.
6) As root, rm -rf /opt/firefox and extract the one I just downloaded
7) as normal user again, run firefox and get the usual first-run page
8) about:config and search for paper_size

Observe that paper size is letter.

There is nothing on my computer that suggests it should be using letter, and no other program that I ever print from has EVER decided that the paper size should be letter. Only firefox gets this wrong. It's been getting it wrong now for well over ten years.

I like everything else about firefox except for this one infuriating bug.

This bug was first filed in 2002. It's now 2013. I've just upgraded to Firefox 24.0 on all my machines and my default paper size has, once again as it does every upgrade, reverted to the US_Letter papersize.

I live in the other 96% of the world that uses A4 paper, so every time I try to print from Firefox I get an error message on my printer.

OpenOffice and Libreoffice get the paper size right. GIMP gets the paper size right. Inkscape gets the papersize right. Abiword gets the paper size right. Gedit gets the paper size right. Tuxpaint gets the papersize right. EVERY OTHER program I use under any distro of Linux manages to correctly determine that I use A4 paper and doesn't give me any problems.

But not Firefox.

Firefox defaults to US_Letter. Even though my printer is set for A4. Even though my language is en_NZ. Even when I've manually changed ALL of the defaults back to A4 under about:config it still bloody-mindedly sets everything back to US-Letter every singe time there's some minor point-update of Firefox.

Firefox is the ONLY program that does this.

And it's been doing it far too long.

Pleas, for the love of Free Software, FIX THIS BUG.
Comment 78 User image Marcelo Jaccoud Amaral 2013-10-21 06:20:49 PDT
I have submitted a duplicate and have been following this bug for years, saddly seeing no resolution at all. Some stuff must be made clear:

Paper size names are surely locale dependent ("Letter" in the US is "Carta" in Brazil), but the default value for the paper size is NOT. It is determined by the host operating system, i.e., the software component which is responsible for handling the printers and their queues. Any default value provided by Firefox, anywhere, is WRONG. Please find every line setting a default value and get rid of it. 

I have not noticed this bug acting for quite a while in Windows and Mac OS, so this is clearly a platform independent feature which which was corrected the wrong way, probably in the platform dependent module. The linux module should get this values from cups, and that's it -- why on earth does 'letter' keeps popping up? Where does this value come from? Please get rid of it, I already abandoned Firefox for any printing in my Linux boxes, and I am on the verge of abandoning it whatsoever, just because of this stupid little bug which persists for more than a decade. 

I cannot even find a place to buy letter-sixed paper if I needed to. It doesn't exist in Brazil, although some weird legal sizes are still used in some time-shifted places like notary offices and advocacy firms.

Weather websites are smart enough to tell I'm im Rio de Janeiro, but show temperatures in Fahrenheit and wind speed in miles/h. My new GPS app knows I'm im Brazil but shows distandes in miles and yards. My music editor (made in Europe!) gets the paper size right, but still defaults margins in inches, and worst: when I change them, they get rounded to the nearest inch fraction, so I keep getting 2.98 mm instead of 3.00 ! How an European software chooses to use inches inside it is beyond my understanding. This must have something to do with (very old) development frameworks.

Firefox should not be this dumb, and specially not in a internationally freely distributed OS like Linux. 

Please do something. Let us get rid of all US medieval defaults, they're like a curse.
Comment 79 User image Teemu Leisti 2013-10-21 06:33:07 PDT Comment hidden (advocacy)
Comment 80 User image Oskar Eisemuth 2013-11-09 04:28:39 PST
Well the whole situation is very complex, the other platform code is more or less broken too.
Bug 629500 sums the whole situation quite good and looks like a welcome refactor of the whole code base, maybe it will land in the next years?  Feels like gecko/firefox printing is stuck in IE6 age...
Comment 81 User image Daniel Mota Leite 2013-12-17 03:28:35 PST
I'm also annoyed that every firefox i run have the letter as default page size... and of course, one only discovers this after trying to print and nothing show up on the printer.

If in the past, print was little used, with the PDFjs, people start to print a lot more from firefox, making this issue more important.

If this can not be "fixed", at very least remove the default, leave it BLANK... on first printing, ask what paper size one wants... is not as friendly as a default, but having a broken default, trying to print and getting nothing is even worst. Most people will never know that the problem is the wrong paper size and don't understand why they don't have any printout.
Comment 82 User image Oskar Eisemuth 2013-12-17 09:46:35 PST

Actually, while the windows version works better, it is screwed too, specially on unusually paper sizes and margins.

The main problem with "letter" is, that the gtk code part can't understand ps paper names, and the ps paper names doesn't understand iso_a4.

The right solution would be to drop the whole thing and query printer and paper names directly via ipp or use only gtk code and throw the old cups lib and ps based query solution.

Considering the other bug #629500 is stuck as well.
My solution will be my own private inhouse addon as can no longer wait for a solution. 
The win32 version works more or less, except CSS2 Margins are still broken.
For the linux version I plan to to use a ipp based solution or directly accessing cups via js-ctypes.

Accessing CUPS via socket and ipp protocol, query paper sizes, create a postscript file and send it directly should be a more future proof technology. Technical that should work on OSX and if you have the right url with any ipp aware network printer, but that isn't my goal.
Comment 83 User image Karl Tomlinson (:karlt) 2015-06-10 16:15:08 PDT
This bug is not half as bad now that the fix for bug 446041 provides that
print.print_paper_* prefs (once they exist) will override

The print.print_paper_* prefs will record the previous setting, but this will
only be different from print.postscript.paper_size if the value is been
changed in the page setup.

There is also much code here that can be removed and so make the use of
different prefs somewhat less confusing.
Comment 84 User image Karl Tomlinson (:karlt) 2015-06-10 16:16:46 PDT
Created attachment 8620681 [details] [diff] [review]
remove ununsed nsIPrintSettings::printCommand and print_command prefs

These was used only to write to and read from each other.
Comment 85 User image Karl Tomlinson (:karlt) 2015-06-10 16:17:46 PDT
Created attachment 8620682 [details] [diff] [review]
use GTK default paper size and orientation

In the nsPrintSettingsGTK constructor, gtk_paper_size_new(nullptr) gets the
system default paper size from the locale and gtk_page_setup_new() sets
default orientation to portrait.

These are subsequently overridden by prefs if any have been saved from
a previous nsPrintSettingsGTK.
Comment 86 User image Karl Tomlinson (:karlt) 2015-06-10 16:18:36 PDT
Created attachment 8620683 [details] [diff] [review]
remove print(|.<modulename>)(|.printer_<printername>).filename pref reading code

There are no default pref values, and even if some have been set, the value
is subsequently overridden by the print.print_to_filename pref, which exists
if saved from a previous nsPrintSettingsGTK.
Comment 87 User image Karl Tomlinson (:karlt) 2015-06-10 16:19:33 PDT
Created attachment 8620684 [details] [diff] [review]
remove meaningless GetPrintMethod()
Comment 88 User image Karl Tomlinson (:karlt) 2015-06-10 16:20:16 PDT
Created attachment 8620685 [details] [diff] [review]
part 5: remove ununsed plexName colorspace resolutionName and downloadFonts

This was only used to write to and read from otherwise unused preferences.
Comment 89 User image Robert O'Callahan (:roc) (email my personal email if necessary) 2015-06-11 19:11:57 PDT
Comment on attachment 8620682 [details] [diff] [review]
use GTK default paper size and orientation

Review of attachment 8620682 [details] [diff] [review]:

So with this patch, do we still remember the user's paper size in some way? How?
Comment 90 User image Karl Tomlinson (:karlt) 2015-06-11 21:20:05 PDT
Comment on attachment 8620682 [details] [diff] [review]
use GTK default paper size and orientation

(In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #89)
> So with this patch, do we still remember the user's paper size in some way?

Yes.  The code removed here was not reading user's prefs.  Those prefs were never saved. 

> How?

(In reply to Karl Tomlinson (ni?:karlt) from comment #85)
> These are subsequently overridden by prefs if any have been saved from
> a previous nsPrintSettingsGTK.

This happens in nsPrintOptions from InitPrintSettingsFromPrefs(), called after
Comment 91 User image Karl Tomlinson (:karlt) 2015-06-11 21:20:23 PDT
Created attachment 8621437 [details] [diff] [review]
part 4: remove meaningless GetPrintMethod() v1.1

Also removed a now-unused nsresult and a repeated argument sanity check.
Comment 92 User image Robert O'Callahan (:roc) (email my personal email if necessary) 2015-06-11 22:37:16 PDT
Comment on attachment 8621437 [details] [diff] [review]
part 4: remove meaningless GetPrintMethod() v1.1

Review of attachment 8621437 [details] [diff] [review]:

Comment 95 User image Brian Birtles (:birtles) 2015-06-18 18:52:14 PDT Comment hidden (obsolete)
Comment 96 User image Brian Birtles (:birtles) 2015-06-18 22:01:18 PDT Comment hidden (obsolete)

Note You need to log in before you can comment on or make changes to this bug.