Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir,
how to get the path of the downloaded pdf file
bellow is my code
please help me
protected void Button1_Click(object sender, EventArgs e)
       {
           GeneratePDF();
       }
       private void GeneratePDF()
       {
           DataTable dtTemp = new DataTable();
           dtTemp.Columns.Add("Customer ID");
           dtTemp.Columns.Add("First Name");
           dtTemp.Columns.Add("Last Name");
           dtTemp.Columns.Add("Address");
           dtTemp.Rows.Add("0001", "Peter", "p", "2376, 00800, calicut");
           dtTemp.Rows.Add("0002", "Alfred", "k", "3453, 00800, calicut");
           dtTemp.Rows.Add("0003", "Alice", "n", "6056, 00800, calicut");
           dtTemp.Rows.Add("0004", "Denis", "h", "5672, 00800, calicut");
           dtTemp.Rows.Add("0005", "Paul", "k", "8734, 00800, calicut");
           Document pdfDoc = new Document(PageSize.A4, 30, 30, 40, 25);
           System.IO.MemoryStream mStream = new System.IO.MemoryStream();
           PdfWriter writer = PdfWriter.GetInstance(pdfDoc, mStream);
           int cols = dtTemp.Columns.Count;
           int rows = dtTemp.Rows.Count;
           pdfDoc.Open();

           iTextSharp.text.Table pdfTable = new iTextSharp.text.Table(cols, rows);
           pdfTable.BorderWidth = 1;

           pdfTable.Padding = 1;
           pdfTable.Spacing = 1;

           //creating table headers
           for (int i = 0; i < cols; i++)
           {
               Cell cellCols = new Cell();
               Font ColFont = FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.BOLD);
               Chunk chunkCols = new Chunk(dtTemp.Columns[i].ColumnName, ColFont);
               cellCols.Add(chunkCols);
               pdfTable.AddCell(cellCols);

           }
           //creating table data (actual result)
           for (int k = 0; k < rows; k++)
           {
               for (int j = 0; j < cols; j++)
               {
                   Cell cellRows = new Cell();
                   Font RowFont = FontFactory.GetFont(FontFactory.HELVETICA, 12);
                   Chunk chunkRows = new Chunk(dtTemp.Rows[k][j].ToString(), RowFont);
                   cellRows.Add(chunkRows);
                   pdfTable.AddCell(cellRows);

               }
           }

           pdfDoc.Add(pdfTable);
           pdfDoc.Close();
           Response.ContentType = "application/octet-stream";
           Response.AddHeader("Content-Disposition", "attachment; filename=Report.pdf");

           Response.Clear();
           Response.BinaryWrite(mStream.ToArray());

           Response.End();

       }
Posted
Updated 9-Oct-13 19:25pm
v6
Comments
Sunny_Kumar_ 10-Oct-13 0:23am    
please share your code what you've tries so far and where is the problem.
vineethnair 10-Oct-13 0:39am    
sir,
how to get the path of this downloaded pdf file..
vineethnair 10-Oct-13 1:39am    
any one knows please help me....

1 solution

looks to me like you're not actually creating a file onthe hard disk

yeah look

System.IO.MemoryStream mStream = new System.IO.MemoryStream();


and

PdfWriter writer = PdfWriter.GetInstance(pdfDoc, mStream);


so

http://api.itextpdf.com/itext/com/itextpdf/text/pdf/PdfWriter.html[^]

PdfWriter

protected PdfWriter(PdfDocument document,
OutputStream os)
Constructs a PdfWriter.
Remark: a PdfWriter can only be constructed by calling the method getInstance(Document document, OutputStream os).

Parameters:
document - The PdfDocument that has to be written
os - The OutputStream the writer has to write to.




and given you're writing to a memory stream....

http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx[^]

Creates a stream whose backing store is memory.


so i reckon you need to have a wee think about that

Bryce
 
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