Failed to load pdf document in c#
<p>Hi This is my C# code :</p>

<pre><code>Byte[] bytes;

int orderID = Convert.ToInt32(e.CommandArgument);

var templateData = ordersBL.GetTemplateDetails(orderID);

using (MemoryStream ms = new MemoryStream())
{

using (Document document = new Document(PageSize.A4, 10, 10, 10, 10))
{
PdfWriter writer = PdfWriter.GetInstance(document, ms);
foreach (var temp in templateData.ToList())
{

string message = temp.Message;
string tempimage = Convert.ToBase64String(temp.logo);
string base64 = tempimage;
byte[] imageBytes = Convert.FromBase64String(base64);
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imageBytes);
if (image.Height &gt; image.Width)
{
float percentage = 0.0f;
percentage = 700 / image.Height;
image.ScalePercent(percentage * 100);
}
else

{

float percentage = 0.0f;
percentage = 140 / image.Width;
image.ScalePercent(percentage * 100);
}

if (!document.IsOpen())
{

document.Open();
}
document.Add(image);
using (var htmlWorker = new HTMLWorker(document))
{

using (var sr = new StringReader(message))
{


htmlWorker.Parse(sr);
}
}
Paragraph paragraph = new Paragraph();
paragraph.SpacingBefore = 10;
paragraph.SpacingAfter = 10;
paragraph.Alignment = Element.ALIGN_LEFT;
// paragraph.Font = FontFactory.GetFont(FontFactory.HELVETICA, 12f, BaseColor.GREEN);

document.Add(paragraph);
document.NewPage();
}
bytes = ms.ToArray();
document.Close();

}
}
Response.ContentType = "application/pdf";
string pdfName = "User";
Response.AddHeader("Content-Disposition", "attachment; filename=" + pdfName + ".pdf");
Response.Buffer = true;
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
Response.Close();
Response.Flush();
}
</code></pre>

<p>Pdf is downloaded but it shows failed to load pdf document.</p>

<p>Failed to load pdf document in c#</p>

<p>I didn't find where I mistake in code.</p>

<p>Please give me correct code </p>

<p>Thanks.</p>