I've been working on PDF printing last few days. I used print preview mechanic to implement the feature and it seems working. Client code looks like this:
- Code: Select all
// start printing
CefPdfPrintSettings settings;
settings.selection_only = 0;
settings.landscape = 0;
settings.should_print_backgrounds = 1;
settings.margin_type = 3;
settings.margin_left = 100;
settings.margin_right = 50;
settings.margin_bottom = 50;
settings.margin_top = 50;
browser.GetHost()->PrintToPDF(outputPath, settings);
// receive notification in OnProcessMessageReceived
if (message->GetName() == "PrintToPDF_Finished") {
auto arguments = message->GetArgumentList();
bool validArguments = arguments->GetSize() == 2
&& arguments->GetType(0) == VTYPE_STRING
&& arguments->GetType(1) == VTYPE_BOOL;
if (validArguments) {
auto path = arguments->GetString(0).ToWString();
auto noError = arguments->GetBool(1);
// do something...
}
}
I'm not sure whether IPC handler is a good place for onFinish notification or not because there is no IPC here, just direct calling IPC handler. And probably the code should be better integrated with existing printing interface of CEF. However I hope my patch may help someone. I tested it with Chromium 39.0.2171.95 and corresponding CEF branch.