chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.39k stars 467 forks source link

windows: PrintToPDF and print preview requires additional PrintCompositorLPAC config in M125+ #3725

Closed binarynate closed 4 months ago

binarynate commented 5 months ago

Describe the bug

First, I want to say that I love CEF and hugely appreciate your immense amount of work on it. Thank you! I recently upgraded from CEF 111 to 125 and discovered that CefBrowserHost::PrintToPDF() now silently fails on Windows (it works correctly on macOS). By silently fails, I mean that the PDF is not created and the CefPdfPrintCallback isn't invoked. I then tested the Windows 64-bit builds of the cefclient application and found that starting with CEF 125, the "Print to PDF" option from the Tests dropdown fails silently, too (i.e. the PDF is not created and it doesn't show a UI dialog indicating that the PDF was created). Here are are findings testing with different versions of cefclient:

Do you have any ideas for how I can resolve this issue? The debug.log file for cefclient 125 doesn't appear to have any details about the error: debug.log

To Reproduce Steps to reproduce the behavior:

  1. Download and run the cefclient sample app for CEF 125 or newer.
  2. Click Tests -> "Print to PDF"
  3. Observe that the PDF is not created and there is no UI dialog indicating that the PDF was created.

Expected behavior The PDF is created and cefclient displays a UI dialog confirming that the PDF was created.

Versions (please complete the following information):

edgardogho commented 4 months ago

Does it fail on every page? can you access www.google.com and generate a PDF out of it? I had the same issue on CEF 126 (Linux) and some pages failed to generate the PDF and others would work (google for instance would work but pages containing google ads would fail).

binarynate commented 4 months ago

Does it fail on every page?

Yes, it fails on every URL that I try.

can you access www.google.com and generate a PDF out of it?

No, this fails. It also fails for other URLs I have tried, such as https://news.ycombinator.com

magreenblatt commented 4 months ago

Works fine for me in M126 and M127 on Windows 11.

  1. Run cefclient.exe
  2. Click Tests -> "Print to PDF"
  3. The "output.pdf" file is created successfully.

cefclient 126 stable and 127 beta: Tests -> "Print to PDF" fails silently

What version, specifically, did you test? Are you passing any command-line flags to cefclient?

binarynate commented 4 months ago

Thank you for investigating this, Marshall. I just tested again with 126.2.10+g61241e4+chromium-126.0.6478.127, which I downloaded by going to the CEF builds page and clicking the link next to "Sample Application" from the "Current Stable Build" section for Windows 64-bit. I tested it on both Windows 11 and Windows 10 and found that the "Print to PDF" option failed for both. I didn't pass any command-line flags and am running cefclient.exe by double-clicking it. I attached a video from demonstrating this on Windows 11:

demo.mp4

If there's any additional info that would be helpful for me to send, please let me know.

magreenblatt commented 4 months ago

Thanks for the additional details. I can reproduce the issue with the 126.2.10 and 127.0.8 official Sample Application but not with a local CEF M127 build (Debug or Release). This suggests that the issue may be related to variations (features) that are enabled or disabled for non-Official builds only. This is what I see in chrome://version/ for my local M127 Debug build that appears PDF or printing-related:

OutOfProcessPrintDriversPrint:Enabled_20230912
PdfOcrDesktop:Enabled
PdfOutOfProcessIframe:Enabled

However, running the Official M127 build with --enable-features=EnableOopPrintDrivers,PdfOopif doesn't appear to help.

Here is the comprehensive list of M127 variations that are enabled in my working build in case someone wants to do a more exhaustive test of various feature flags to identify the culprit.

magreenblatt commented 4 months ago

PDF-related features (at M127) can be found here, and print-related features can be found here.

magreenblatt commented 4 months ago

Running cefclient with --enable-logging=stderr --v=1 shows the following after PrintToPDF:

[297668:292520:0708/141223.900:ERROR:sandbox_win.cc(840)] Sandbox cannot access executable. Check filesystem permissions are valid. See https://bit.ly/31yqMJR.: Access is denied. (0x5)

This error does not appear with the local Release build so it's likely related.

magreenblatt commented 4 months ago

This fixes PrintToPDF and print preview for me in official M126 and M127: --disable-features=PrintCompositorLPAC

magreenblatt commented 4 months ago

This can also be fixed by correctly setting permissions via icacls. See the related Chromium issue here. This is the preferred solution, and the same as Google Chrome's installer.

magreenblatt commented 4 months ago

See either of the above solutions.

binarynate commented 4 months ago

Thank you so much for pinpointing this, Marshall! This resolved the issue for me. I truly appreciate your help.