Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CefGlue silent printing to PDF

I have latests CefGlue version (3.2272.2035)

I need to save current page as PDF. I'd like to interact with my CEF somehow (JS/C#) and make it create PDF for me.

  1. I've tried to use javascript.window.print() for that purpose with no success, because, all i've got is such window.

enter image description here

  1. I've found OnPrintJob method in CefPrintHandler but I don't know what is the right way to call it + comments say: "Implement this interface to handle printing on Linux" and I need to handle printing to pdf on Windows environments (both x64/x86)

Any code example would be appreciated. Thanks in advance for any help.

like image 606
kravasb Avatar asked Nov 09 '22 16:11

kravasb


1 Answers

You'd need to merge this patch and recompile cef from source; Besides, you might have to add some glue logic to CefGlue. I tested the patch myself (on C++ API) and it worked fine.

EDITED: the patch will be merged in trunk.

If you only need to print some pages (specially if these pages are under your control), you will do just fine. However if you need (as I did at the time) to print almost anything, you'll probably face the fact that some web pages don't render anything useful to the print view. Also, even those well-behaved diverge significantly from what you see on the screen - and that's not a CEF behavior, as even google chrome showed the same issues. In my application this was a no-go so I dropped printing and started capturing the screen (and implemented saving that to a pdf using a pdf library in C++), but perhaps your application isn't as demanding as mine was. Cheers!

like image 155
Alexandre Pereira Nunes Avatar answered Nov 14 '22 21:11

Alexandre Pereira Nunes