2
Answers

How To Convert Page Into Image In ASP.NET

prathap k

prathap k

8y
303
1

What I have tried:

protected void Page_Load(object sender, EventArgs e)
{
//saveURLToImage("http://localhost:2564/Pagetoimage.aspx?OrderId=7");
saveURLToImage("http://www.w3schools.com/");

}

private void saveURLToImage(string url)
{
if (!string.IsNullOrEmpty(url))
{
string content = "";

System.Net.WebRequest webRequest = WebRequest.Create(url);
System.Net.WebResponse webResponse = webRequest.GetResponse();
System.IO.StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
content = sr.ReadToEnd();
//save to file
byte[] b = Convert.FromBase64String(content);
System.IO.MemoryStream ms = new System.IO.MemoryStream(b);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);

string folderPath = Server.MapPath("~/ImagesFolder/"); //Create a Folder in your Root directory on your solution.
string fileName = "IMageName" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".jpg";
string imagePath = folderPath + fileName;
img.Save(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg);

img.Dispose();
ms.Close();
}
}
but i am getting error like this

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

please help me.
 
 
 
 
Answers (2)
0
Krishna Rajput Singh

Krishna Rajput Singh

NA 5.5k 2m 8y
Hi below links helpful for you ..
 
http://forums.asp.net/t/1961796.aspx?How+to+convert+whatever+in+the+web+page+into+image+
 
http://converthtmltoimage.com/Convert-html-to-image-in-asp.net.html
 
 
if find helpful mark as correct answer 
 
0
ramya bharath

ramya bharath

NA 922 0 8y
You can check this http://www.codeproject.com/Questions/392213/Error-in-decoding-method check for the input that it's not corrupted