如何获取下载的pdf文件的路径 [英] how to get the path of the downloaded pdf file

查看:388
本文介绍了如何获取下载的pdf文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,

如何获取下载的pdf文件的路径

贝娄是我的代码

请帮帮我

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();

       }

推荐答案

看起来就像你实际上并没有创建一个文件硬盘



是啊看看



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









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





so



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



PdfWriter



protected PdfWriter(PdfDocument文档,

OutputStream os )

构造一个PdfWriter。

备注:只能通过调用getInstance方法构造PdfWriter(Documen) t document, OutputStream os )。



参数:

document - The必须编写的PdfDocument

os - 作者必须写的OutputStream。









并且给你写一个内存流....



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



创建一个后备存储为内存的流。





所以我想你需要考虑一下这个



布莱斯
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


这篇关于如何获取下载的pdf文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆