Question

I have c# dynamic aspx page after new property add I create for record brochure

http://veneristurkey.com/admin/Brochure.aspx?Admin=PropertiesBrochureA4&id=36

but I want to this convert image file I am searching on internet but all with webbrowser and windows forms. I need on page load show not css type also image file. jpg, png or tiff how i can do this. i need to see sample code..

saving aspx page into an image 2

Was it helpful?

Solution

As I mentioned in my comment, your best bet is to opt for attempting to render HTML to an image.

Here is the link for a library that will allow your to render html to an image:

http://htmlrenderer.codeplex.com/

Here is code that does exactly what you're asking:

http://amoghnatu.wordpress.com/2013/05/13/converting-html-text-to-image-using-c/

Now all you have left is to get the html, since I'm assuming you don't want this to render to the browser prior to generating this image - you should look into grabbing the rendered html from the aspx page on the server prior to returning it, and then just return the image. To render a page:

https://stackoverflow.com/a/647866/1017882

Sorted.

OTHER TIPS

If you do not mind using a commandline tool you can have a look at wkhtmltopdf. The package include a wkhtmltoimage component that can be used to convert HTML to image, using

wkhtmltoimage [URL] [Image Path]

Codaxy also wrote a wkhtmltopdf c# wrapper available through the NuGet package manager. I'm not sure if the wkhtmltoimage component was included, but it should be easy enough to figure out how they wrap the wkhtml components.

i fixed my problem with screenshot machine API they are my code..

public void resimyap() {

        var procad = WS.Satiliklars.Where(v => v.ForSaleID == int.Parse(Request.QueryString["id"])).FirstOrDefault();

        var imageBytes = GetBytesFromUrl("http://api.screenshotmachine.com/?key=xxxxxx&size=F&url=http://xxxxxxx.com/a4.aspx?id=" + procad.ForSaleID);
         string root = Server.MapPath("~/");

            // clean up the path
            if (!root.EndsWith(@"\"))
                root += @"\";

            // make a folder to store the images in
            string fileDirectory = root + @"\images\a4en\";

            // create the folder if it does not exist
            if (!System.IO.Directory.Exists(fileDirectory))
                System.IO.Directory.CreateDirectory(fileDirectory);

        WriteBytesToFile( fileDirectory + + procad.ForSaleID + ".png", imageBytes);

Yes i also try wkhtmltopdf c# wrapper but in pdf or image converting time my computer fan goin crayz. also i must upload server exe file and my hosting firm didnt support them

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top