paper size in cups printing is not set as in print dialogue (always equals A4 in cups spool files)
Categories
(Core :: Printing: Setup, defect, P3)
Tracking
()
People
(Reporter: henning.lorenz, Unassigned)
Details
(Whiteboard: [layout:print-triage:p1])
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0
Steps to reproduce:
Three different label printers are correctly configured (page size, resolution, etc.) in CUPS and working correctly. This happens on all printers with different drivers (Zebra & Intermec) and different size.
I want to print a label from web app in Firefox. The label is rendered correctly, the page size and orientation set correctly in the print dialogue.
Firefox prints the label 90 degree rotated in the middle of the label, half of it is cut off.
Monitoring /var/spool/cups gives the following results:
- a correctly rendered pdf file is saved to the spool directory
- the corresponding spool file contains a wrong page size, which is about A4 (confirmed by CUPS developers at GitHub, not sure what the units are)
If I do exactly the same from Chromium, where the resulting print-out is fine:
- a correctly rendered pdf file is saved to the spool directory (as in Firefox)
- the corresponding spool file contains the correct page size.
I paste here the content of the spool file for a 38 mm/1.5 inch wide and 19 mm/0.75 inch high label.
Firefox (wrong page size - 595.3x841.89):
^B^A^@^B^@^@^@^A^AG^@^Rattributes-charset^@^Eutf-8H^@^[attributes-natural-language^@^Een-gb^BB^@^Yjob-originating-user-name^@^BhlE^@^Kprinter-uri^@+ipp://localhost:631/pr>
Resolution^@^F203dpiB^@^NzeErrorReprint^@^ESavedB^@^KzePrintMode^@^ESavedB^@^HDarkness^@^B-1B^@
zeLabelTop^@^C200B^@^KzePrintRate^@^GDefault!^@^Ljob-priority^@^D^@^@^@2B^@^HPageSize^@^TCustom.595.28x841.89B^@^OzeMediaTracking^@^CWeb"^@^GCollate^@^A^@B^@ MediaType^>
job-sheets^@^DnoneB^@^@^@^DnoneB^@^QzeTearOffPosition^@^D1000!^@ number-up^@^D^@^@^@^AI^@^Xdocument-format-detected^@^Oapplication/pdfI^@^Odocument-format^@^Oappli>
Chromium (correct page size - 107.72x53.86):
^B^A^@^B^@^@^@^A^AG^@^Rattributes-charset^@^Eutf-8H^@^[attributes-natural-language^@^Een-gb^BB^@^Yjob-originating-user-name^@^BhlE^@^Kprinter-uri^@+ipp://localhost:631/pr>
Resolution^@^F203dpiB^@^QzeTearOffPosition^@^D1000B^@^HPageSize^@^SCustom.107.72x53.86B^@^HDarkness^@^B-1B^@
zeLabelTop^@^C200B^@
job-sheets^@^DnoneB^@^@^@^DnoneI^@^Xdocument-format-detected^@^Oapplication/pdfI^@^Odocument-format^@^Oapplication/pdfE^@^Hjob-uuid^@-urn:uuid:ffa2f26b-d558-382a-638f-b94>
Actual results:
Label is printed rotated because the wrong page size that is transferred to the printing system. The size of the content is correct, i.e. not scaled. The rotation is most likely due to the different aspect ratio (higher than wide, while label is wider than high).
Expected results:
The label should print on the label, as it does when sent from another browser (e.g. Chromium) or as pdf via lp.
Comment 1•6 years ago
|
||
Bugbug thinks this bug should belong to this component, but please revert this change in case of error.
Updated•4 years ago
|
Bug report draft — Firefox forces A4 media on Linux/CUPS, ignoring document page size and selected paper
Summary
When printing on Linux (CUPS) to a printer whose media is a non-standard custom size (an 80 mm thermal receipt printer), Firefox always submits the print job with A4 page geometry, regardless of:
the intrinsic page size of the document being printed (a PDF whose MediaBox is 80 × 210 mm), and
the paper size selected in Firefox's print dialog (which correctly lists and shows the printer's 72 × 210 mm size), and
the CUPS queue's configured default media (set to the 72 mm size via lpadmin -o PageSize=...).
The job reaches CUPS as A4 (DEVICEWIDTHPOINTS=595, scupsPageSizeName=A4), so the page is rendered at A4 width (~1725 px @ 203 dpi) instead of the printer's ~72 mm (≈575 px). On this hardware the wide raster additionally crashes the vendor CUPS filter, but the core defect is that Firefox sends A4 — any narrow-format printout is impossible from Firefox.
Environment
Firefox 151.0.3 (build 20260602141352)
OS: CachyOS Linux (Arch-based), kernel 6.18.33, Wayland session
CUPS 2.4.19 + cups-filters (cfFilterGhostscript)
Printer: Xprinter 80 mm thermal (ESC/POS), CUPS queue with custom media X72MMY297MM / X72MMY210MM (72 mm printable width); set as the queue default.
Document: a PDF generated by a web app, MediaBox 226 × 595 pt (80 × 210 mm) — verified with pdfinfo: Page size: 226.768 x 595.266 pts.
Steps to reproduce
On Linux, install a CUPS printer whose only media are custom narrow sizes (e.g. 72/80 mm wide); make a 72 mm size the queue default.
Open a PDF whose page size is ~80 × 210 mm (not A4/Letter) in Firefox.
Ctrl+P. In the print dialog choose this printer; paper size shows the 72 × 210 mm custom size (or leave default).
Print.
Expected result
Firefox submits the job using the selected / document / printer-default media (72–80 mm). CUPS renders at ~575 px width and a correct narrow printout is produced.
Actual result
Firefox submits the job as A4. The CUPS/Ghostscript filter is invoked with A4 geometry and the page is rendered at A4 width. Concrete log from cfFilterGhostscript for such a job:
gs ... -sDEVICE=cups -r203x203
-dDEVICEWIDTHPOINTS=595 -dDEVICEHEIGHTPOINTS=842
-dcupsBitsPerColor=8 -dcupsColorOrder=0 -dcupsColorSpace=3
-scupsPageSizeName=A4 ...
DEVICEWIDTHPOINTS=595 and scupsPageSizeName=A4 confirm A4 was sent, even though the document is 226 pt (80 mm) wide and the printer/dialog use a 72 mm custom size.
Additional notes
Setting print.prefer_system_dialog = true (via user.js) and selecting the 72 × 210 mm paper in the dialog does not change the outcome — CUPS still receives A4.
The system locale is en_US; /etc/papersize is letter. Firefox sends A4 regardless (i.e. not simply following the libpaper/locale default).
Workaround: bypass Firefox and print the PDF straight to CUPS, which honors the page size: lp -d <queue> document.pdf → correct narrow printout. This isolates the defect to Firefox's print path (the document, driver, and CUPS pipeline are all fine).
Possibly related: Bug 498115 (Linux page-size enumeration / inability to set default page size in the UI).
Root-cause analysis (and a candidate patch).
The wrong A4 geometry comes from widget/gtk/nsPrintSettingsGTK.cpp.
nsPrintSettingsGTK initializes its page setup with a named default paper
size:
gtk_paper_size_new(nullptr) // -> gtk_paper_size_get_default(): a NAMED
// size (iso_a4 / na_letter) from locale
When a custom (non-standard) paper size is applied, SetPaperWidth/
SetPaperHeight try to mutate that paper size in place:
NS_IMETHODIMP
nsPrintSettingsGTK::SetPaperWidth(double aPaperWidth) {
GtkPaperSize* paperSize = gtk_page_setup_get_paper_size(mPageSetup);
gtk_paper_size_set_size(paperSize, aPaperWidth, ..., unit);
SaveNewPageSize();
}
But gtk_paper_size_set_size() only works on custom paper sizes — in GTK
(gtk/gtkpapersize.c) it begins with:
g_return_if_fail (size->is_custom);
So on the named A4/Letter default it is a silent no-op: the requested
custom dimensions are dropped and the page setup keeps the A4 size. That
A4 is what ends up in the CUPS spool (PageSize Custom.595.28x841.89),
regardless of the document size, the dialog selection, or the queue
default — exactly the symptom in this bug.
This also explains why Chromium and lp are fine (they don't go through
this GTK paper-size path), and why it has persisted across versions: the
faulty setters are unchanged. Reproduced here on Firefox 151.
Candidate fix — make the setters create a custom GtkPaperSize when the
current one isn't custom:
NS_IMETHODIMP
nsPrintSettingsGTK::SetPaperWidth(double aPaperWidth) {
GtkPaperSize* paperSize = gtk_page_setup_get_paper_size(mPageSetup);
double height =
gtk_paper_size_get_height(paperSize, GetGTKUnit(mPaperSizeUnit));
if (gtk_paper_size_is_custom(paperSize)) {
gtk_paper_size_set_size(paperSize, aPaperWidth, height,
GetGTKUnit(mPaperSizeUnit));
} else {
GtkPaperSize* custom = gtk_paper_size_new_custom(
"custom", "custom", aPaperWidth, height,
GetGTKUnit(mPaperSizeUnit));
gtk_page_setup_set_paper_size(mPageSetup, custom);
gtk_paper_size_free(custom);
}
SaveNewPageSize();
return NS_OK;
}
// SetPaperHeight: symmetric (keep current width, set the new height).
A shared helper (EnsureCustomPaperSize) would be cleaner. I haven't built
mozilla-central to verify yet — happy to if it helps, or for someone with
a tree set up to confirm/land.
Description
•