wpfchromiumcefsharp

WPF CEFSharp ChromiumWebBrowser - Render MemoryStream


I need to be able to retrieve a Pdf from our web server via a call to Web API and then render the document in the ChromiumWebBrowser for CEFSharp, all within memory and not saving the file locally.

Right now I'm at the point where I get back the file in a MemoryStream, but can't seem to get any further.

Is this possible? Any examples would be greatly appreciated.

Thanks.


Solution

  • You have two options, implement a Scheme Handler for your own custom scheme, e.g. client:// or implement a Resource Handler

    https://github.com/cefsharp/CefSharp/blob/cefsharp/41/CefSharp.Example/CefSharpSchemeHandler.cs#L46

    You can use the default ResourceHandlerFactory if your using just statically generated resources.

    https://github.com/cefsharp/CefSharp/blob/cefsharp/41/CefSharp.Example/CefExample.cs#L98

    or implement your own IResourceHandlerFactory

    https://github.com/cefsharp/CefSharp/blob/cefsharp/41/CefSharp/DefaultResourceHandlerFactory.cs

    Scheme Handler is more complicated, supports async callbacks though. Next version of CefSharp will include support for async resource handlers. (-pre release should be out sometime this week)