Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Adobe could not open 'receipt[1].pdf' because it is either not a supported file type or because the file has been damaged(for example it was sent as an email attachment and wasn't correctly decoded)

C#
StringBuilder str = new StringBuilder();
            BAL.EmailForVerification ObjEmailVer = new BAL.EmailForVerification();//FROM EmailForVerification.cs BAL
            DataTable dt = ObjEmailVer.SelectPrepetsPartForReceipt();
            if (dt.Rows.Count > 0)
            {       
                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment;filename=Receipts.pdf");
                Response.ContentType = "application/pdf";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string status = string.Empty;
                    if (Convert.ToString(dt.Rows[i]["Resident Category"]).ToLower() == "yes")
                    {
                        status = "Couple";
                    }
                    else if (Convert.ToString(dt.Rows[i]["Resident Category"]).ToLower() == "no")
                    {
                        status = "Single";
                    }
                    //str.Append("<h2 style='page-break-before: always;'> </h2>");
                    str.Append("<table width=100% cellpadding=3 cellspacing=0 border=0 style=border:solid 1px #000000;>");
                    str.Append("<tr><td align=center colspan=2 valign=top><table width=100% cellpadding=0 cellspacing=0 border=0><tr><td align=left width=10%><img src=http://prepets.rotarydombivlieast.org/App_Themes/images/RotaryLogo_wh-k.jpg width=60 height=60  /></td><td align=center width=90% style=font-size:16pt; font-weight:bold; font-family:Times New Roman; >Rotary Club of Dombivili East<br/><span style=font-size:10px>Dist. 3140</span> <br/>PREPETS ROYALE 2011</td></tr></table> </td></tr>");
                    str.Append("<tr><td style=width:70%> </td><td style=width:30%; align=left valign=top ><br/>Receipt No: " + Convert.ToString(dt.Rows[i]["ReceiptNo"]) + "<br/>");
                    str.Append("Receipt Date: " + Convert.ToString(dt.Rows[i]["ReceiptDate"]) + "</td></tr>");
                    str.Append("<tr><td align=left valign=top colspan=2><br/>Received from Rtn. " + Convert.ToString(dt.Rows[i]["Name"]) + " Rs. " + Convert.ToString(dt.Rows[i]["AmountPaid"]) + " towards registration charges (" + status + ") for PREPETS 2011. </td></tr>");
                    str.Append("<tr><td align=left valign=top colspan=2><br/>Cheque/DD No.: " + Convert.ToString(dt.Rows[i]["TransactionChequeNo"]) + "     Date: " + Convert.ToString(dt.Rows[i]["TransactionChequeDate"]) + "      Drawn On: " + Convert.ToString(dt.Rows[i]["DrawnonBankName"]) + "</td></tr>");
                    str.Append("<tr><td align=center valign=top colspan=2 > </td></tr>");
                    str.Append("<tr><td align=left valign=top colspan=2 style=padding-left:320px; ><br/>PP Dr. Madhav Baitule <br/>");
                    str.Append("Treasurer <br/>");
                    str.Append("PREPETS Organizing Committee <br/>");
                    str.Append("Rotary Club of Dombivli East </td></tr>");
                    str.Append("</table>");
                    str.Append("<h2 style='page-break-after: always;'> </h2>");
                    //str.Append("<br/>");
                }
                Response.Output.Write(str.ToString());
                Response.Flush();
                Response.End();
            }
Posted
Updated 18-Jan-12 5:40am
v3
Comments
Orcun Iyigun 18-Jan-12 11:40am    
Added tags.
[no name] 18-Jan-12 11:44am    
Do you have an actual question?
darkDercane 18-Jan-12 11:50am    
Adobe? you don't add any header to tell the browser that is an actual pdf file, u can't render like that any file :P
if u will render a pdf file you can look these links maybe help u
http://stackoverflow.com/questions/5778803/asp-net-c-sharp-generate-and-download-pdf-file
http://www.codeproject.com/KB/aspnet/Creating_PDF_documents_in.aspx
Amod Kumar Jaiswal 19-Jan-12 5:24am    
how to export string builder to pdf?

Hi,
check this once:CodeProject[^]
 
Share this answer
 
you can use iTextSharp library for generating PDf Files dynamically

check following link :
http://aspdotnetcodebook.blogspot.com/2008/07/how-to-export-content-of-gridview-to.html
 
Share this answer
 
v2
Uh, the content you're putting in that StringBuilder is HTML. Do you even know what the format of a PDF file looks like?

It is possible to create PDF files directly; the spec is (at least it used to be) available on Adobe's website. But it is probably going to be a lot easier for you to use a third party tool like iTextSharp.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900