Print Sensibly to PDF in Firefox
I use HTML and CSS as my word processor. No, really. I started doing this about two years ago and I really like the simplicity of writing in Markdown, processing that as HTML, then producing documents that I can distribute either as web pages or as PDF. I could even dump them into a Leanpub book if I wanted to. I compose in Typora, do power editing in Kakoune, use Jekyll and pandoc for production, then Firefox to preview. Finally, I can use Firefox to print to PDF. I spent hours crafting a print CSS stylesheet that I can feel good about.
Today, however, I ran into trouble: the header were suddenly flush with the edge of the page. This image illustrates what I wanted compared to what I got.
My “word processor” produces the document, but Firefox adds the header and footer. Setting the margins for the document was easy. Setting the margins for the header was… not obvious.
No options in the Print Preview. No options in the Print… dialog. Nothing. Srsly!
The Solution
Evidently, one must change configuration settings deep in the bowels of Firefox. You can read more at https://support.mozilla.org/en-US/questions/1061569.
- In Firefox, visit
about:config
. - Accept the risk of changing the complicated and scary configuration settings.
- Search for preferences matching the text
print.Mozilla_Save_to_PDF
, since Mozilla recently (in mid-January 2021) changed the name of this device from “Print to File” to “Mozilla Save to PDF”, at least on Linux. - Look for four configuration settings whose names match the pattern
print.Mozilla_Save_to_PDF.print_edge_<where>
, for the four areas of the page: bottom, left, right, top. - Set values for each of these to match the desired margins. (See the next section for details.)
- Close any print preview and open it again. Yay!
The Print Edge Margin Units
If your paper measurement system is Colonial/Imperial/Archaic, such as “Letter (8.5 inches by 11 inches)”, then enter a margin as a multiple of 0.01 inch. For example, for a 0.5-inch margin, enter 50, and for a 0.25-inch margin, enter 25.
If you measure paper using Modern/Sensible/Metric designations, such as “A4”, then enter a margin in millimetres, like a functioning adult.
I live in Canada. Sadly, we are Colonial. Hundredths of an inch it is.
I chose left and right margins of 50/100 inch as well as top and bottom margins of 25/100 inch. Excellent! You can see the great results in the image near the beginning of this article.
Now I simply have to remember to check this if I ever need to print an article onto physical sheets of paper.
Changes in Mid-January 2021
Recently I noticed that my header and footer moved back to the edge of the page. This happened at the same time that the print dialog changed, at least on Linux. I hunted through the configuration properties and found the new properties print.print_edge_bottom
(and so on for the four edges of the page) which seem to do nothing, because when I changed those values, nothing changed.
I did, however, after a while, notice another batch of “print edge” configuration settings named print.print_Mozilla_Save_to_PDF.print_edge_bottom
and so on. When I changed these values, then opened a new print preview, the header and footer moved to the expected spot on the page. Success!
Since I feel lucky, I reset the properties print.print_edge_*
to their default values and deleted the properties print.printer_Print_to_File.print_edge_*
, since these last ones seem now obsolete. I will update this article if, in the future, these settings cause any problems.