New issue
Advanced search Search tips

Issue 889226 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Nov 10
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Windows , Chrome , Mac
Pri: 3
Type: Bug



Sign in to add a comment

Save as PDF ignores print stylesheet when printing selected text

Reported by andy.bue...@gmail.com, Sep 25

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0

Steps to reproduce the problem:
1. Select text in a webpage
2. Click print
3. Select "Save as PDF"
4. Check "Selection Only"

What is the expected behavior?
The PDF uses the print stylesheet

What went wrong?
The PDF does not use the print stylesheet

Did this work before? N/A 

Chrome version: 69.0.3497.100  Channel: stable
OS Version: 10.0
Flash Version: 

Please see attached screenshot, it shows the issue with a tiny sample page:

<html>
  <head>
    <style>
      body {
        font-family: Verdana;
      }
    </style>
    <style media="print">
      body {
        font-family: Times;
      }
    </style>
  </head>
  <body>
    This is some test text.
  </body>
</html>

When i print the whole page then it's fine, font Times is used in the PDF.
But when i select a text to print then the produced PDF apparently ignores the print CSS and uses font Verdana
 
SelectionPrintAsPdf.mp4
875 KB View Download
Labels: Needs-Triage-M69
Cc: ajha@chromium.org
Components: Internals>Printing
Labels: Target-71 M-71 FoundIn-71
Status: Untriaged (was: Unconfirmed)
Able to reproduce the issue on the latest canary 71.0.3562.0 on Windows-10, same behavior is seen on older chrome version 60.0.3112.20 as well.

Triaging this as non-regression issue for furthre investigation. Attaching the html and pdf files for testing this.
889226.html.pdf
42.4 KB Download
889226.html
260 bytes View Download
Owner: thestig@chromium.org
Status: Assigned (was: Untriaged)
Sending to thestig@ since this is a printing issue.
Labels: -Pri-2 -M-71 -Needs-Triage-M69 -Target-71 OS-Chrome OS-Linux OS-Mac Pri-3
Cc: yosin@chromium.org
Chrome's printing code calls into Blink via WebLocalFrameImpl::SelectionAsMarkup(), which in term calls Document::UpdateStyleAndLayoutIgnorePendingStylesheets() and FrameSelection::SelectedHTMLForClipboard().

I would suggest adding WebLocalFrameImpl::SelectionAsMarkupForPrinting(), which does something similar to SelectionAsMarkup(), but takes print media CSS into account.
Or on the Chrome side, we can enter print mode, and SelectionAsMarkup() will just do the right thing.
Project Member

Comment 8 by bugdroid1@chromium.org, Nov 10

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/59184f71318ad456c2fd7133209c728e0a2264dc

commit 59184f71318ad456c2fd7133209c728e0a2264dc
Author: Lei Zhang <thestig@chromium.org>
Date: Sat Nov 10 10:02:27 2018

Print selections with print media.

PrepareFrameAndViewForPrint::CopySelection() generates HTML + CSS to
support printing only the selection. By making it do the generation in
print mode, the generated output will have print media CSS applied.

BUG= 889226 

Change-Id: Ia57d4c0429b93d72cb412545eda7579b53570e6c
Reviewed-on: https://chromium-review.googlesource.com/c/1308604
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607118}
[modify] https://crrev.com/59184f71318ad456c2fd7133209c728e0a2264dc/components/printing/renderer/print_render_frame_helper.cc

Status: Fixed (was: Assigned)
Thank you!
Able to reproduce the issue on reported chrome version #69.0.3497.100 using Windows 10 by following steps as per comment#0.

Verified the fix on Mac 10.14 and Windows 10 on latest chrome #72.0.3608.0. Attached screenshots for reference.
Note: Unable to verify fix on Linux as Adobe Acrobat is not getting installed.
Thanks.!
889226Mac(M-72).png
177 KB View Download
889226Win(M-72).png
294 KB View Download
Cc: swarnasree.mukkala@chromium.org
Labels: Needs-Feedback
The fix is already verified on Win and Mac but unable to verify this on Linux as facing issue with  Adobe Acrobat installation on Linux.
thestig@ Could you please confirm if any alternate PDF tool available on Linux to check the font format so that we can verify the fix on Linux as well.
Thanks.!
re: comment 12 - any PDF viewer on Linux will be able to verify the output.

Sign in to add a comment