OutputStream is not available when a custom TextWriter is used.
- by Pinu
this is my function which converts pdf to png image, it's throwing an error on
this line-- stream.WriteTo(Response.OutputStream); Is there some thing wrong??
protected void CreatePngFromPdf()
{
try
{
string PDFLocation = string.Format(@"\\XXXX\{0}\{1}\{2}.pdf", Yr, Loc.Substring(0, 4), Loc.Substring(4, 4));
Utilities.WebPDF.PDF WebPDF = new DocuvaultMVC.Utilities.WebPDF.PDF();
WebPDF.Credentials = new NetworkCredential(@"xyz", "xyz");
byte[] png = WebPDF.StreamPdfPageAsPngResize(PDFLocation,PageNumber, 612, 792);
MemoryStream ms = new MemoryStream(png);
MemoryStream stream = new MemoryStream();
int newWidth = 612;
int newHeight = 792;
System.Drawing.Image newImg = System.Drawing.Image.FromStream(ms);
Bitmap temp = new Bitmap(newWidth, newHeight, newImg.PixelFormat);
Graphics newImage = Graphics.FromImage(temp);
newImage.DrawImage(newImg, 0, 0, newWidth, newHeight);
newImg.Dispose();
temp.Save(stream, ImageFormat.Png);
stream.WriteTo(Response.OutputStream);
temp.Dispose();
stream.Dispose();
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}