In my pdf download, I have a code that downloads a particular section of a web page in pdf. There are images on the page as well, so the pdf renders the images on the page along with other HTML contents. It download though but when I check my download files, the downloaded file does not show the PDF icon. However, upon double-clicking the downloaded file, I will be given options with different applications that can be used to open the pdf file (like Adobe reader, Adobe illustrator, Notepad etc...). May I please know why the icon pdf is not showing on this downloaded file?
If I use the same download code and add code to send to an email, and when the user receives the file and downloads from the email, the downloaded file shows the pdf icon.
Here is what I mean, the icon at the far left is just a blank file icon, it should have the pdf file icon.

Could it be that I need to update my itext package libraries from NuGet manager?
protected void Button3_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlCommand cmd = new SqlCommand("SELECT * FROM TableReceipt WHERE reference =@reference ", con))
{
cmd.Parameters.AddWithValue("@reference ", lblprefix.Text);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
byte[] image = (byte[])dr["logo"];
imgFileUpload.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(image);
byte[] bytes = (byte[])dr["signature"];
Image2.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(bytes);
File.WriteAllBytes(Server.MapPath("logo.jpg"), image);
File.WriteAllBytes(Server.MapPath("sign.jpg"), bytes);
Image2.ImageUrl = GetUrl("sign.jpg");
imgFileUpload.ImageUrl = GetUrl("logo.jpg");
}
var ImagUrl = imgFileUpload.ImageUrl;
var ImgeUrl = Image2.ImageUrl;
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
Panel1.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
PdfWriter PdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
cssResolver.AddCssFile(Server.MapPath("~/css/style2.css"), true);
IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(pdfDoc, PdfWriter)));
var worker = new XMLWorker(pipeline, true);
var xmlParse = new XMLParser(true, worker);
pdfDoc.Open();
xmlParse.Parse(sr);
xmlParse.Flush();
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + nameLbl.Text + " Receipt - " + DateTime.Now.ToString("MMM dd, yyyy") + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
File.Delete(Server.MapPath("sign.jpg"));
File.Delete(Server.MapPath("logo.jpg"));
Image2.ImageUrl = ImgeUrl;
imgFileUpload.ImageUrl = ImagUrl;
Response.End();
con.Close();
}
}
}
catch (SqlException ex)
{
string msg = "Error:";
msg += ex.Message;
throw new Exception(msg);
}
}