itextsharp:pdf保存位置 [英] itextsharp: pdf save location

查看:117
本文介绍了itextsharp:pdf保存位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在创建一个pdf文件.现在,它将直接下载给用户默认的浏览器下载.我希望此pdf仅保存在指定的位置,而无需用户通知.稍后,我将在另一个网格中为相同的pdf提供下载选项给用户.
我为此尝试了以下方法...

Hi,
I am creating a pdf. now it is directly downloading to the users default browsers downloads. I want to this pdf to only save at the specified location without user notification. I will provide download option to user later in another grid for the same pdf.
I tried the following for this...

HttpResponse response = HttpContext.Current.Response;
        response.Clear();
        Response.Buffer = true;

        //string path = Server.MapPath("~/desktopmodules/Downloads/");
        //string filepath = path + budgetName;
        //PdfWriter.GetInstance(document, new FileStream(filepath, FileMode.Create));

        response.ContentType = "application/octet-stream";
        string path = Server.MapPath("~/DesktopModules/Downloads/");
        response.AddHeader("Content-Disposition", "filename=" + budgetName + ".pdf");
        
        // step 1: creation of a document-object
        //Document document = new Document(PageSize.LETTER);

        // step 2: we create a writer that listens to the document
        //PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);



但我不会成功,所以请帮助我设置pdf的下载路径.
请帮忙.......
<编辑并="="添加=" code =" block =" mark ="-=" milind =">



but i wont get succeed so please help me to set the download path of the pdf.
please help.......
<edited and="" added="" code="" block="" mark="" -="" milind="">

推荐答案

这是我以前使用过的东西.您的情况可能有所不同,但PDFDocument的用法将相同.
This is something i have used earlier. Your scenario could be different, but PDFDocument usage will be same.
using System;
using System.IO; 
using iTextSharp.text.pdf;

namespace TestApplication
{
    public partial class dialog : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            PdfPTable SummaryTable = new PdfPTable(2);             
            using (FileStream fs = new FileStream(Server.MapPath("YourRelativeFilePath"), FileMode.Create))
            {
                using (iTextSharp.text.Document doc = new iTextSharp.text.Document())
                {
                   
                    PdfWriter writer = PdfWriter.GetInstance(doc, fs);
                    
                    doc.Open();
                    doc.Add(SummaryTable);
                    
                    doc.Close();

                }
                fs.Close();
            }
        }

         
    }
}



``YourRelativeFilePath''的用法示例:



Sample usage of ''YourRelativeFilePath'':

FileStream fs = new FileStream(Server.MapPath("~\\MailUploads\\SearchReport\\" + sFileName), FileMode.Create)


MailUploads是我项目中的一个文件夹,并且在其中有一个子文件夹SearchReport,sFileName是字符串变量,其中包含应保存pdf的名称.

希望对您有所帮助.


MailUploads is a folder inside my project and inside it there is a subfolder SearchReport, sFileName is the string variable which holds the name with which the pdf should be saved.

hope this helps.




请参阅下面的链接.我认为这可能会对您有所帮助.

http://aspalliance.com/259_downloading_files__forcing_the_file_download_dialog [ ^ ]

谢谢,
Viprat
Hi,

See the below link. I think it might be help you.

http://aspalliance.com/259_downloading_files__forcing_the_file_download_dialog[^]

Thanks,
Viprat


这篇关于itextsharp:pdf保存位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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