Bug 262156

Summary: PDF.js UI is printed when printing a PDF document
Product: WebKit Reporter: Michael Catanzaro <mcatanzaro>
Component: PDFAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: bugs-noreply, mcatanzaro, ntim, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: PC   
OS: Linux   

Description Michael Catanzaro 2023-09-26 17:36:22 PDT
When printing a PDF document, WebKit should integrate with PDF.js's print functionality and not print the PDF.js UI itself.
Comment 1 Michael Catanzaro 2023-09-26 17:39:25 PDT
(In reply to Michael Catanzaro from comment #0)
> When printing a PDF document

Specifically, the problem occurs when printing the document using the browser's print UI rather than PDF.js's print UI. Presumably it wouldn't happen if using the print button in PDF.js itself. That button is actually broken, but it looks like bug #260771, so I'll expand the scope of that bug instead of reporting a new one.
Comment 2 Radar WebKit Bug Importer 2023-10-03 17:37:16 PDT
<rdar://problem/116435714>
Comment 3 Tim Nguyen (:ntim) 2023-10-08 11:10:59 PDT
I would suggest as a starter to use `@media (print)` in the custom stylesheets to make printing behave as expected + somehow force the print button to load all the PDF pages.

Alternatively, there might be a better way if you somehow use messaging + PDF.JS APIs to print.
Comment 4 Michael Catanzaro 2023-10-09 05:45:15 PDT
(In reply to Tim Nguyen (:ntim) from comment #3)
> Alternatively, there might be a better way if you somehow use messaging +
> PDF.JS APIs to print.

This will be a better (and probably easier) solution. Basically we should forward WebKit's print command to PDF.js, which knows how to prepare the document properly.
Comment 5 Tim Nguyen (:ntim) 2023-10-09 19:57:14 PDT
(In reply to Michael Catanzaro from comment #4)
> (In reply to Tim Nguyen (:ntim) from comment #3)
> > Alternatively, there might be a better way if you somehow use messaging +
> > PDF.JS APIs to print.
> 
> This will be a better (and probably easier) solution. Basically we should
> forward WebKit's print command to PDF.js, which knows how to prepare the
> document properly.

You can look at how the custom context menu commands are handled for messaging to PDF.JS.