PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Response.Write Problem (Saving pdf to memory Stream) Help!! https://forum.pdfsharp.net/viewtopic.php?f=2&t=655 |
Page 1 of 1 |
Author: | matthewb [ Mon Feb 23, 2009 2:13 pm ] |
Post subject: | Response.Write Problem (Saving pdf to memory Stream) Help!! |
Below is working code which does what I want to do but I want to improve it. When I click on a button on my web page the method below runs. It creates the pdf (not shown below) and then saves it on my server. Next it makes a box appear on screen allowing a user to open the file or choose where to save it which is great. Now the problem.......... Since I will have many users accessing my site this method will not be great as many users will keep changing the pdf contents so when a user runs the method they may get the wrong contents as someone else may have run the method at the same time creating a differnet pdf. I am a web developer and usually I save a file to a 'memorystream 'or a 'file stream' so each user would save their pdf locally rather than on a server where users would change it. The problem is everytime i write code to save the pdf to a memory stream and try to use response.write an error keeps appearing saying corrupt file. Can anyone please show me how it can be done using c#.net? Also does this website take paypal donations as I would willingly donate as this software is fantastic many thanks Matt outputPdf.Save(filename); Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=apdf.pdf"); Response.Charset = ""; Response.ContentType = "application/vnd.pdf"; Response.WriteFile(filename); Response.End(); |
Author: | magick_67 [ Mon Feb 23, 2009 4:09 pm ] |
Post subject: | |
Dude, this works great for me. I call the object that makes the pdf and return it in a stream. PdfDocument PDoc = clsPdf.GenerateProductSheetPDF(ProductList); MemoryStream stream = new MemoryStream(); PDoc.Save(stream, false); Response.Clear(); Response.ContentType = "application/pdf"; Response.AddHeader("content-length", stream.Length.ToString()); Response.BinaryWrite(stream.ToArray()); Response.Flush(); stream.Close(); Response.End(); Enjoy! |
Author: | matthewb [ Tue Feb 24, 2009 9:40 am ] |
Post subject: | |
Thank you!!!!. It was the binary write I was missing out when I was doing it. Thank yoiu very much |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |