Webview in CEFSharp to render HTML content - c#

My objective is to render the html content into text with its styles, indent and all others. I just done a workaround with CEFSharp v1.25.5 with the following code and it works like charm.
CefSharp.Wpf.WebView webView= new CefSharp.Wpf.WebView();
webView.LoadHtml("<p> this is <b>paragraph<b></p>");
Since I am developing a 64bit application,I'm not able to implement the same in my application. So, I found latest version of CefSharp v37.0.0 with 64bit support. But the sad part is I could not find the 'WebView' here. I tried the following code without any luck.
CefSharp.Wpf.ChromimWebBrowser browser= new CefSharp.Wpf.ChromimWebBrowser();
browser.LoadHtml = ("<p> this is <b>paragraph<b></p>","dummy:");
I need to show the html webcontent in webview container in a 64bit target platform like the webview in Cefsharp v1.25.5.

Hi there's a few things you should do, all covered in CefSharp Troubleshooting.
Initialise CEF
Add the browser to the Controls collection
I prefer to LoadHtml in a method attached to the browser.IsInitialisedEvent (and only load when the event.IsBrowserInitialised is true)
Hope these help. If there are any other issue do let us know!

Related

How do I dynamically load HTML into a Winforms WebViewControl?

The Visual Studio WebView component uses the Microsoft Edge browser and is the upgraded version of the WebBrowser control that used older Internet Explorer technology, but the API is different.
Does anyone know the equivalent WebView control call for:
WebBrowser.DocumentText = "<html>Dynamic page content</html>";
I agree with the suggestion given by the #aepot that you can use the WebView.NavigateToString to load the dynamic HTML.
webView2.NavigateToString("<html> Test code </html>");
If it is a file then you can do like this:
webView2.NavigateToString(System.IO.File.ReadAllText(Application.StartupPath + "/11.html"));
OR
webView2.NavigateToLocal(#"\12.html");

Use Telerik converter service through WebBrowser?

I'm trying to visit the webpage http://converter.telerik.com/ using a WebBrowser control in a WinForms application but the page contains script errors.
After ScriptErrorsSuppressed to True the main controls of the webpage are unable to load at this point i'm lost about using the WebBrowser control to this task so I've search other alternatives.
I've tried with the latest build of GeckoFX (29.0.X) from here: https://bitbucket.org/geckofx/
With the GeckoWebBrowser control the Telerik page loads perfectly but after pressing the "Convert" button from my GeckoWebBrowser the second "Textbox" gets crazy and is not properly displayed, so again I'm lost but I don't know what more alternatives I have.
In the past i've tried to use some builds of chrome for .Net but I was unable to compile them.
What I need to do to use the Telerik converter service using any kind of webbrowser from my app?
PS: Dependencies are not a problem for me, I just want to develop a personal application for my only usage to load/save snippets that I converted using the Telerik service accessing to its converter webpage from my app.
Personally I would take a look at SharpDevelop's NRefactory Library and see if I could utilize this in my application instead of using someone else's webservice which more than likely uses NRefactory as it's underlying engine.
The online version of the code converter is available at http://codeconverter.sharpdevelop.net/.
https://github.com/icsharpcode/SharpDevelop/wiki/Code-Converter
https://github.com/icsharpcode/SharpDevelop/wiki/NRefactory
About NRefactory:
ICSharpCode.NRefactory is freely available as a part of SharpDevelop IDE.
It is parser library for C# and VB.
It consists of a single Abstract Syntax Tree (AST) that can represent all constructs that are available in C# or VB (unlike System.CodeDom, which only represents constructs common to C# and VB).
By using the C# parser and a VB output visitor (or vice versa), you can do a code converter.
After parsing to AST, you can analyze and/or transform the AST and re-create source code from the (modified) AST, then re-insert the comments we saved from the parser into the output
For more info about NRefactory please see: sharpdevelop.net and NRefactory wiki.
You may try samples\NRefactoryDemo in the SharpDevelop source code to take a look how the AST parse source code.
Source: http://www.codeproject.com/Articles/262950/CodeConverter

Embed a PDF into a WPF application

I'm trying to embed/display a PDF in a WPF application. So far, I've tried those solutions, without success:
Display the PDF in a WindowsFormsHost hosting an AxAcroPdf
control, similarly to what's shown here. The problem is that my application sets AllowsTransparency
= True to create a style similar to Modern UI, but
that doesn't blend well with a WindowsFormsHost (the control
becomes invisible).
Display the PDF in a WebBrowser control. The problem is the same.
Set AllowsTransparency = False, but this causes a sluggish feeling in the application. Since I use WPF purposedly to enhance the look and feel of our business applications to the benefit of our end-users, this can't be a solution.
Use a second window with AllowsTransparency = False to display the WindowsFormsHost, and hack it to make it look like a child control of the main window, as it's described here. However, I don't like the code-behind approach since I'm using MVVM.
Find a native PDF control for WPF. However, I only found a couple of commercial ones and that's not an option right now.
What I need is to be able to:
Display a PDF or its representation (i.e. an image or a conversion to another format) in a WPF application.
Keep my style visually intact and fluid (AllowsTransparency must stay True).
Use an approach respecting the principles of MVVM (preferably no code-behind).
Include it in my application for free (for commercial usage).
I'm totally open to hand-made solutions, open-source libraries and even completely different approaches.
I have two solution for this:
Open your .pdf file and then print as an .xps (also you must be able for doint this in code), then this file you can embded this file in your app, and show it as a xps document. See this: Documents in WPF - MSDN - Microsoft (XPS)
To use a free library, I'm not very sure if this allows show pdf, but it generate them, you can take a look at EO-Pdf.
Hope this tips helps to solve the problem.
If you're opened to Open-Source solutions, I would recommend GhostScript. You can convert the PDF (with decent quality, for the most part) to individual image files of most any format you might want to work with.
The other option is to convert the PDF to HTML using pdf2htmlEX, but it will currently only compile for Linux.
I use both of the above solutions in several applications on both Linux and Windows. The advantage to the HTML way is that the text can be copied and pasted. The advantage of the GhostScript way is that the images might be more portable (smaller).
As with any open-source solution, you need to be aware of the terms of the license under which each product is released, and how that may impact your final result.
There is a good solution that I used before is to use CefSharp. It's the Chrome browser engine that supports previewing PDF documents.
Visit quick start page.
It is recommended to visit Troubleshooting page to set appropriate settings if you have problems.
If you want to show PDF files on your local drives you should also use these settings for the browser and then use file:/// protocol:
CefSharp.BrowserSettings browserSettings = new CefSharp.BrowserSettings();
browserSettings.FileAccessFromFileUrls = CefSharp.CefState.Enabled;
browserSettings.UniversalAccessFromFileUrls = CefSharp.CefState.Enabled;
browserSettings.TextAreaResize = CefSharp.CefState.Enabled;
my_bowser.BrowserSettings = browserSettings;

C# WebKit and CKEditor iframe scraping

Currently I am working on my project which involves using webbrowser control in c#. After many struggles I successfully accomplished joining WebKit to WinForms application and run website with CKEditor in it but it gave me 2 issues.
1 Image uploader works fine but it doesn't send callback or WebKit cannot process it. Is there any possibility to make it work?
2 When I try to scrape html document to get the iframe by doing this: webKitBrowser1.Document.GetElementById("cke_1_contents").LastChild I get iframe element but I have no idea how to get content of it because it says that i doesn't have any childs.
Anyone can suggest me what to do next or give any alternative for this?
I use VS2008 and .NET 3.5.
I can't answer this question in the context of the WebKit-based control, but I suggest that you try the native WinForms WebBrowser control. It works great as the host for CKEditor, once the WebBrowser Feature Control has been implemented.
Then, if I was to do web-scraping on a page with CKEditor, I'd try something like this to get the current editor content (from C#):
dynamic pageDocument = webBrowser.Document.DomDocument;
var ckeDocument = pageDocument.getElementsByClassName("cke_wysiwyg_frame").item(0).contentDocument;
MessageBox.Show((string)ckeDocument.documentElement.outerHTML);

Display HTML in a silverlight application

I need to display HTML in my silverlight application and cannot find a way of doing it. I cannot use the web browser control as it needs to be able to run in or out of a browser.
Does anyone know of a good way to do this, because all I can think of doing at the moment is running replace methods on the text to just replace the tags with C# equivalents eg(<br /> to \n).
The way I do it is to check if the application is running inside the browser and change the means of display accordingly. If running inside the browser, I overlay the application with an IFrame, as I describe in this article: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-6.aspx. Otherwise, I use the WebBrowser control. I have a control which does this all for you in the source code that accompanies my book, which is downloadable from the Apress website here: http://www.apress.com/book/downloadfile/4638.
Hope this helps...
Chris
I believe what you are looking for is HTML Bridge.
Edit I'm am actually now unsure if you'll still have access to javascript if you're running this OOB. I'm going to look into this some more and will further update. I'll still leave the answer up though for reference.
Second Edit Here is what I've found. HTML Bridge is disabled when you run silverlight out of browser. This disables access to the HTML DOM as well as Javascript. However, according to a comment on this site:
HTML Bridge is not available when you first install a OOB app. But you CAN force it if you modify the index.html in the folder where the app is installed just adding the enablehtmlaccess parameter.
It works!
You can even create dynamic HTML elements using the well-known methods of the HtmlPage class. You can even open a new browser window with the Navigate() method and its "_blank" parameter.
Keep in mind this information was posted about SL 3. Its possible that this may have changed, but I doubt it. So it seems that what you may want to do is build a script into the startup of your SL app that detects whether or not your app is running out of browser. If it is then you may want to have some script to call that can modify this file for you.
There recently was a similar question.
I posted a link there to an implementation that parses and displays HTML inline in Silverlight. Of course, it will work only with simple HTML, but maybe you can expand it to your needs.

Categories

Resources