下载多个PDF [英] download multiple pdf
问题描述
我想下载多个PDF作为在我的asp.net application.I附件创造了一些模板和填充使用pdfstamper(iTextSharp的)值。我能够填补值,但无法下载。
I am trying to download multiple pdf's as attachments in my asp.net application.I have created some templates and filling values using pdfstamper(itextsharp). I am able to fill the values but not able to download.
private void FillForm(string path, DataTable BridgeValues, DataTable Comments, DataTable Maintenance,string Newfilename)
{
try
{
string pdfTemplate = path;
string newFile = Newfilename;
string Pathser = "";
if (!System.IO.Directory.Exists(Server.MapPath(@"~/PDF/")))
{
System.IO.Directory.CreateDirectory(Server.MapPath(@"~/PDF/"));
}
if (Directory.Exists(Server.MapPath(@"~/PDF/")))
{
Pathser = Server.MapPath(@"~/PDF/" + Newfilename);
}
System.IO.MemoryStream mStream = new System.IO.MemoryStream();
// create a new PDF reader based on the PDF template document
PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(Pathser, FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;
DataColumn dc = null;
for (int i = 0; i < BridgeValues.Columns.Count - 1; i++)
{
dc = BridgeValues.Columns[i];
pdfFormFields.SetField(dc.ColumnName.ToString(), BridgeValues.Rows[0][dc].ToString());
}
pdfStamper.FormFlattening = true;
// close the pdf
pdfStamper.Close();
////Response.ContentType = "application/octet-stream";
Response.ContentType = "application/pdf";
////Response.AddHeader("Content-Disposition", "attachment; filename=Report.pdf");
Response.AddHeader("Content-Disposition", "attachment; filename=" + Newfilename + "");
////Response.BinaryWrite(mStream.ToArray());
Response.TransmitFile(Server.MapPath(("~/PDF/"+ Newfilename)));
Response.Clear();
Response.End();
}
catch (System.Threading.ThreadAbortException lException)
{
// do nothing
}
}
我第一次尝试创建一个PDF,它的工作,但后来当我试图下载它一声execption多个文件。
无法因为code优化或本机框架是在调用堆栈的顶部,以评估前pression。
First time I tried to create one pdf ,it worked but later when I tried to download multiple files it gave an execption. Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
推荐答案
我不认为你可以通过一个请求,并从动作返回集合下载多个文件。我会建议它,你需要允许用户下载ZIP你他们的多个文件和流存档到浏览器中。
I don't think you can download multiple files by making one request and returning a collection from the action. I would suggest that it you need to allow user to download multiple files you ZIP them and stream the archive down to the browser.
下面是压缩和解多个文件的一个例子:<一href=\"http://devpinoy.org/blogs/keithrull/archive/2008/01/25/how-to-create-zip-files-in-c-with-sharpziplib-ziplib.aspx\" rel=\"nofollow\">http://devpinoy.org/blogs/keithrull/archive/2008/01/25/how-to-create-zip-files-in-c-with-sharpziplib-ziplib.aspx
Here is an example of zipping multiple files: http://devpinoy.org/blogs/keithrull/archive/2008/01/25/how-to-create-zip-files-in-c-with-sharpziplib-ziplib.aspx
这篇关于下载多个PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!