Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,
I have a challenge, I have to convert an html page, which is hosted on the server to png.
I have gone through many websites. They all are providing solution for windows based application.

Any help will be appreciated.


Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 7-Dec-12 15:17pm    
Why?!
--SA

I assume, you want to save on client side some sort of formatted text as image. There are ways to do that, but I suggest you do it on server side, and send it to the client as content. First of all, because you have more possibilities in a server os than in silverlight. And the content is also on the server, as you stated.
On server side you can call any tool, even IE - but that's complicated. You can simply spawn a process and call a command line tool that generates the image for you. If this could last long time, you might use some async callback to the client (but there are other options too). I have not found any free cli tools for windows, but commercial ones (http://www.coolutils.com/HTML-PNG-CommandLine[^] or http://www.verypdf.com/app/html-to-any/index.html[^]).
But you can also make your own tool (or no tool, just generate the image), starting from this great article: A Professional HTML Renderer You Will Use[^].
 
Share this answer
 
Comments
Gyandeep neema 7-Dec-12 23:29pm    
Thanks Zoltan,
I have tried this I mean I tried to convert html content into png on server. It works fine but the problem is Bitmap class.
WCF doesn't support WriteableBitmap and Silverlight doesn't support Bitmap.
Will you be able to suggest any other class which is supported by both.
Zoltán Zörgő 8-Dec-12 13:45pm    
But let's clarify: you want to let the user save this content from your silverligth client, or you want to display this content in the silverlight applet?
First case: check this out http://www.silverlightshow.net/items/Uploading-and-downloading-images-from-WCF-in-Silverlight.aspx (download part). Second case, this might help: http://www.dotnetcurry.com/ShowArticle.aspx?ID=220
Gyandeep neema 9-Dec-12 23:22pm    
Thanks Zoltan,
My ultimate goal is like I have a graph, which is generating by a third party tool. Those graphs will be hosted on the server. Now my problem is when I display this graph in silverlight HtmlHost, It sits on the whole application and it overlaps some of my app contents. So I want to create a png and display in an image control.
Zoltán Zörgő 10-Dec-12 12:32pm    
First of all, can you get this "third party tool" to output the graph in a png (or to i't standard output)? Or do you know any other way to get the graphical content as any kind of graphics from it?
Gyandeep neema 10-Dec-12 23:17pm    
No it gives standard output and I don't have any other option. The only option i have is to convert the HTML to png on server side and get the output through WCF.
There is no one "predefined" way to "convert" HTML to PNG, because the concepts are completely different.

HTML document does not have certain size and shape, its appearance depends on several factors like rendering engine, predefined styles depending on user preferences (it's rare that all styles are comprehensively described with CSS), and, most importantly, in the size of the browser windows used to view the page. In contrast, PNG is the bitmap with fixed size of the image in pixels.

If you explain your ultimate goals, you can get exact advice on what to do instead.

—SA
 
Share this answer
 
Comments
Gyandeep neema 7-Dec-12 23:25pm    
Thanks Sergey for you reply.
My ultimate goal is like I have a graph, which is generating by a third party tool. Those graphs will be hosted on the server. Now my problem is when I display this graph in silverlight HtmlHost, It sits on the whole application and it overlaps some of my app contents. So I want to create a png and display in an image control.
Sergey Alexandrovich Kryukov 8-Dec-12 0:14am    
If this is Silverlight graphics, it has nothing to do with HTML content. I don't really understand the problem because you did not completely describe it, but why can't you use original graphics generated by this tool, whatever it is? It it overlaps, you should try to change the layout, instead of loosing data, which always happens when you render some graphical data in a bitmap.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900