Storing Pdf in session?


It takes a while for a large pdf to be generated. The time is spent within this call:


I wonder if I could do the work ahead of the time where I need to display it in the browser. Do it while the user is busy doing other things. Keep the result in Session. When the user finally clicks [show me my PDF], I would retrieve it from the session and display it right away.

I know I could do it using a file. But this file is only useful one time so instead of saving it, serving it, then deleting it, I thought it is better to not use a physical file at all.

Any suggestions?




Thank you for considering Aspose.

I think you can save the pdf into a memory stream and write the stream into the Response when you want to display the pdf.


Can you post a few lines of sample code, if possible?



Here is a small example:

MemoryStream ms = new MemoryStream();

private void Page_Load(object sender, System.EventArgs e)
Pdf pdf = new Pdf();

pdf.Sections.Add().Paragraphs.Add(new Text("hello world"));

Response.Write("pdf prepared.");

private void Button1_Click(object sender, System.EventArgs e)
ms.Position = 0;
byte[] buf = ms.GetBuffer();