CefPrintHandler
Header: cef_print_handler.h
Interfaces: CefPrintDialogCallback, CefPrintJobCallback, CefPrintHandler
Category: Browser Handlers
Overview
User-implemented handler interfaces returned from CefClient and registered with CefBrowserHost.
CefPrintDialogCallback
Source File: include/cef_print_handler.h
Process / Thread Context: Browser process / UI thread. USER-CALLED (source=library).
Purpose: Async continuation for print-dialog requests.
Methods
void Continue(CefRefPtr<CefPrintSettings> settings)
Parameters:
settings: Print settings to use.
Return Value: None.
Usage Instruction: Continue printing with the specified settings.
Threading Constraint: Threading constraint not specified per-method; class comment for CefPrintHandler says UI thread.
void Cancel()
Parameters:
- None.
Return Value: None.
Usage Instruction: Cancel printing.
Threading Constraint: Threading constraint not specified per-method.
CefPrintJobCallback
Source File: include/cef_print_handler.h
Process / Thread Context: Browser process / UI thread. USER-CALLED (source=library).
Purpose: Async continuation for print-job completion.
Methods
void Continue()
Parameters:
- None.
Return Value: None.
Usage Instruction: Indicate completion of the print job.
Threading Constraint: Threading constraint not specified per-method.
CefPrintHandler
Source File: include/cef_print_handler.h
Process / Thread Context: Browser process / UI thread. USER-IMPLEMENTED (source=client); returned from CefClient::GetPrintHandler(). Header explicitly notes: "Implement this interface to handle printing on Linux." and "If a print handler is not provided then printing will not be supported on the Linux platform."
Purpose: Handle Linux printing: receive print start/stop notifications, populate print settings, show print dialog, send print job, and provide PDF paper size.
Methods
CefSize GetPdfPaperSize(CefRefPtr<CefBrowser> browser, int device_units_per_inch)
Parameters:
browser: The browser.device_units_per_inch: DPI for the device.
Return Value: CefSize paper size in device units; default is empty CefSize().
Usage Instruction: Used with CefBrowserHost::PrintToPDF().
Threading Constraint: UI thread per class comment.
Usage Example
class MyPrintHandler : public CefPrintHandler {
public:
void OnPrintStart(CefRefPtr<CefBrowser>) override {}
void OnPrintSettings(CefRefPtr<CefBrowser>, CefRefPtr<CefPrintSettings> s,
bool defaults) override {
if (defaults) s->SetOrientation(true);
}
bool OnPrintDialog(CefRefPtr<CefBrowser>, bool has_sel,
CefRefPtr<CefPrintDialogCallback> cb) override {
// Show GtkPrintDialog; on OK: cb->Continue(settings); else cb->Cancel();
return true;
}
bool OnPrintJob(CefRefPtr<CefBrowser>, const CefString& name,
const CefString& pdf_path,
CefRefPtr<CefPrintJobCallback> cb) override {
// Send pdf_path to printer; then:
cb->Continue();
return true;
}
void OnPrintReset(CefRefPtr<CefBrowser>) override {}
CefSize GetPdfPaperSize(CefRefPtr<CefBrowser>, int dpi) override {
return CefSize(8.5 * dpi, 11 * dpi); // US Letter
}
IMPLEMENT_REFCOUNTING(MyPrintHandler);
};
// MyClient::GetPrintHandler() returns this.