Click here to Skip to main content
15,905,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I save a report as jpg format in SQL server 2008. I want to show the report as pdf format when click a button. Please help me. I have given my code :
code for save
C#
if (picUpload.FileName.ToString() != "")
{
    string StrImgName = picUpload.FileName.ToString();
    string ImgFileExtension = System.IO.Path.GetExtension(StrImgName);
    string picPath = "SCDoc/" + txtSCCode.Text.Trim() + "-P" + ImgFileExtension;
    DRLocal["ContImagePath"] = picPath;
}

Code for show report
C#
string DocUrl;
getvalue = Request.QueryString["SCCode"].ToString();

DataTable DTLocal;

DTLocal = new DataTable();

ConManager.DBConnection("TERMSCOM");
string strSQL = "SELECT ContImagePath from tblSalesContract where SCCode='" + getvalue + "'";
ConManager.OpenDataTableThroughAdapter(strSQL, out DTLocal, true);
DTLocal.TableName = "Item";
ConManager.CloseConnection();
DocUrl = DTLocal.Rows[0]["ContImagePath"].ToString();
Response.ContentType = "Application/pdf";
Response.WriteFile(Server.MapPath(DocUrl));
Response.End();
Posted
v2

1 solution

SQL
I think you will have to convert the image to a PDF before showing it. Google iTextSharp which is a library which will allow you to create PDF. In your case, you will have to temporarily create pdf and show it. OR, for all the images saved, create a pdf and store it on file system and store the path in the database. On button click, show the pdf instead of getting the image path. Hope this helps.

Happy coding..!!
 
Share this answer
 
Comments
Sumon562 20-May-14 3:16am    
Thanks for your suggestion. Please can you help me how can I use iTextSharp
Nayan Ambaliya 20-May-14 20:02pm    
Refer to the below on code project:
http://www.codeproject.com/Articles/277065/Creating-PDF-documents-with-iTextSharp

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