Closed Bug 1793220 Opened 2 years ago Closed 1 year ago

For documents with @page { size ...}, Save-to-PDF should offer a "Default" option to use author-specified size by default

Categories

(Toolkit :: Printing, defect, P3)

defect

Tracking

()

RESOLVED FIXED
112 Branch
Tracking Status
firefox112 --- fixed

People

(Reporter: dholbert, Assigned: fchasen)

References

(Blocks 1 open bug)

Details

Attachments

(5 files, 1 obsolete file)

(We might already have a bug filed for this; please dupe if so)

For a website with @page { size: ...}: if the user chooses save-to-PDF, we should probably default to generating pages that match the page's specified size, rather than the size that we saved from the most recent save-to-PDF operation.

This will probably be relevant for Google Docs printing work. If the user happens to have most recently saved-to-PDF with A5 size, and then the user print a Google Doc, we should be sure we choose Google Docs' specified page size (e.g. US Letter) rather than just restoring A5 or whatever the user most recently used.

(fchasen, who comes from the publishing world, brought this up to me at all-hands.)

(I initially was thinking we could "just" pre-select the author-provided @page size in our print Paper Size dropdown, but that's not sufficient because the author-provided size might be some bogus page size that doesn't match any of the name/predefined sizes in our dropdown.)

Severity: -- → S3
Priority: -- → P3

Fred, can you add a test case for this?

Flags: needinfo?(fchasen)
Attached file testcase 1
Attachment #9297519 - Attachment description: screenshot comparing Firefox (left) to Chrome (right). Firefox generates a US Letter size page in the PDF, by default → screenshot comparing Firefox (left) to Chrome (right). Firefox generates a US Letter size page in the PDF, by default, vs. Chrome just uses the @page rule to size the PDF output
Flags: needinfo?(fchasen)

(In reply to Daniel Holbert [:dholbert] from comment #1)

(I initially was thinking we could "just" pre-select the author-provided @page size in our print Paper Size dropdown, but that's not sufficient because the author-provided size might be some bogus page size that doesn't match any of the name/predefined sizes in our dropdown.)

Yeah, we can't do this in the general case because printers just list all of their supported paper sizes, and not what size paper they actually are loaded with. But we should definitely do this for Save-to-PDF, and I think we should be able to just tell it any paper size too?

We should possibly ensure we don't save a paper size selected in this way as the new default/last used size, too.

(In reply to Daniel Holbert [:dholbert] from comment #1)

[...] the author-provided size might be some bogus page size that doesn't match any of the name/predefined sizes in our dropdown.

For completeness: here's an example of this scenario with an author-specified non-standard page size.

(Right now, we don't offer any way to use this size as the actual paper size, with our save-to-PDF backend. We just let the user pick from a dropdown of named standard sizes. In contrast, Chrome forces the user to use the author-specified page size.)

(er -- I still had some "A5" terminology in the text of the previous attachment. I've updated the attachment to remove that, to avoid confusion.)

Attachment #9297892 - Attachment is obsolete: true
Attachment #9297892 - Attachment description: testcase 2 (custom non-standard "4in by 12in" page size) → testcase 2 (custom non-standard "4in by 12in" page size) [IGNORE, better version attached later]
Assignee: nobody → fchasen
Status: NEW → ASSIGNED

Adds a HonorPageRuleSize setting to allow overriding default the default paper size when print to a PDF file.

Print preview now checks for at-page size rules and if honoring them will display the preview at the specified page size.

The preview will also return the page width and height (in inches) during its callback for the frontend to use to override the default paper settings.

Attachment #9300249 - Attachment description: WIP: Bug 1793220 - Honor at-page size rules when printing to PDF → Bug 1793220 - Honor at-page size rules when printing to PDF r=dholbert
See Also: → 1807985

As noted on phabricator, I think we need a part 2 to handle & regression-test size:0.

WPT test would look something like this, as e.g. testing/web-platform/tests/css/printing/page-size-zero-001-print.html

<!DOCTYPE html>
<meta charset="utf-8">
<title></title>
<meta name="assert" content="">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/8335">
<link rel="match" href="page-size-zero-print-ref.html">
<style>
  @page { size: 0 }
</style>
Hello

...with a title filled in, and a sentence added to the content attribute of the assertion metatag.
We should have -002 and -003 variants that are the same except with e.g .size: 3in 0 and size: 0 3in

All of the testcases should be able to share a reference case, named something like page-size-zero-print-ref.html (that has to match the match tag above). It'd have the same content except no style block (or at least no @page rule), and no match tag.

I just tested something like that^ locally and confirmed that it fails in Firefox but passes in Chrome. My expectation about correctness here is based on the assumption that the size should be treated like auto -- I've just filed https://github.com/w3c/csswg-drafts/issues/8335 to confirm that & get it reflected in the spec.

Setting an at-page size where the width or height is zero is valid CSS but is unprintable, so a size with zero in it will be ignored with this change.

See Also: → 1814236
Attachment #9300249 - Attachment description: Bug 1793220 - Honor at-page size rules when printing to PDF r=dholbert → Bug 1793220 - Use at-page size rules as paper size when printing to PDF r=dholbert
Attachment #9300249 - Attachment description: Bug 1793220 - Use at-page size rules as paper size when printing to PDF r=dholbert → Bug 1793220 - Use at-page size rule as paper size when printing to PDF r=dholbert
Blocks: 1815555
Blocks: 1815565

Having just finished producing a workflow for rendering PDFs with Firefox Nightly (via Puppeteer), I'm glad this is being worked on. Will this be able to produce PDFs with pages of different sizes? Also, I've noticed in the Firefox 110 release notes:

Firefox now supports CSS named pages, allowing web pages to perform per-page layout and add page-breaks in a declarative manner when printing.

If I understand correctly, elements can request pages of certain characteristics (size, margins, etc.) to which to break?

(In reply to Dan Burzo from comment #11)

Having just finished producing a workflow for rendering PDFs with Firefox Nightly (via Puppeteer), I'm glad this is being worked on. Will this be able to produce PDFs with pages of different sizes? Also, I've noticed in the Firefox 110 release notes:

Firefox now supports CSS named pages, allowing web pages to perform per-page layout and add page-breaks in a declarative manner when printing.

If I understand correctly, elements can request pages of certain characteristics (size, margins, etc.) to which to break?

Unfortunately we aren't currently able to create PDFs with different sizes or orientations of paper per page, so only the first size will be used for the paper size.

Named pages can still adjust the margins (for instance swapping left / right pages margin for page spreads) but differently sized or oriented pages will scale up or down to fit within the given paper size.

For a comparison of this behavior you can view: https://www.print-css.rocks/lesson/lesson-named-pages

Duplicate of this bug: 1815555
Blocks: 1818845
Pushed by fchasen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/56d615e5385a
Use at-page size rule as paper size when printing to PDF r=dholbert,AlaskanEmily
https://hg.mozilla.org/integration/autoland/rev/a65d3c61d9a4
Handle at-page size rules that use zero as width or height r=dholbert
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/38726 for changes under testing/web-platform/tests
Regressions: 1819226
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 112 Branch
Upstream PR merged by moz-wptsync-bot
Blocks: 1820651

Note: when testing this, I noticed that this doesn't seem to work for PDFs themselves (i.e. if you view a PDF and try to save it to PDF, you get our standard paper-size dropdown instead of using the PDF's own size). See that bug for more details.

See Also: → 1836025
See Also: → 1820651
See Also: → 1836028
Blocks: 1874947
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: