我立即生成一個pdf文件並將其保存到服務器端,但我需要將它保存到客戶端機器。如何實現此目的..如何在mvc3客戶端機器上保存pdf文件?
Document doc = new Document();
MemoryStream memoryStream = new MemoryStream();
string PDFName = ProjectName + ".pdf";
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("~/ProjectFiles") + "/" +
PDFName, FileMode.Create));
doc.Open();
//PDF Content
doc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + PDFName);
Response.Buffer = true;
Response.Clear();
Response.OutputStream.Write(memoryStream.GetBuffer(), 0, memoryStream.GetBuffer().Length);
Response.OutputStream.Flush();
Response.End();
In Response.OutputStream.Write(memoryStream.GetBuffer(), 0, memoryStream.GetBuffer().Length);
memoryStream長度爲0.我需要將保存的pdf下載到Cleint機器中。 請幫我解決這個問題..
看來你不隨地填寫的MemoryStream。在OutputStream.Write中使用FileStream與在PdfWriter.GetInstance中相同。 – mswietlicki
如何編寫@mswietlicki ...任何代碼? –
它是否保存在服務器上 - 你可以打開pdf文件嗎? –