5

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.

kravasb
  • 696
  • 5
  • 16
  • 1
    [There is a patch](https://code.google.com/p/chromiumembedded/issues/detail?id=1478) that enables printing to PDF, but it's not in current CEF trunk (so neither in CefGlue). You'll have to recompile both to use that – Sga Apr 05 '15 at 19:52

1 Answers1

1

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!

  • I have no experience in coding using C++, so it will be non trivial for me to recompile sources and add logic to CefGlue. For now we're using [SelectPdf](http://selectpdf.com/) library to generate pdf from HTML. It is simple, free, and performs everything we need for now. – kravasb May 28 '15 at 10:59
  • I'll ask on cef forum for the patch to be merged. As cef maintainer was aware of the patch, I do believe he'll see no problems merging in trunk. At least this way this feature will end up being available in the future. – Alexandre Pereira Nunes May 28 '15 at 12:28
  • The maintainer confirmed it'll eventually be merged. – Alexandre Pereira Nunes May 28 '15 at 17:17
  • Thanks a lot! I Hope it will be in CefGlue soon! – kravasb May 29 '15 at 08:30