PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 14, 2024 6:57 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Feb 23, 2009 2:13 pm 
Offline

Joined: Tue Dec 30, 2008 2:11 pm
Posts: 7
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();


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Feb 23, 2009 4:09 pm 
Offline

Joined: Mon Jan 05, 2009 8:15 pm
Posts: 3
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!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 24, 2009 9:40 am 
Offline

Joined: Tue Dec 30, 2008 2:11 pm
Posts: 7
Thank you!!!!. It was the binary write I was missing out when I was doing it. Thank yoiu very much


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group