Reputation: 29586
I have an ASP.NET website and from one of the web pages I need to generate a PDF document that contains the output of a set of web pages that the user selects. I call it "batch PDF". Basically, the user is asked to choose which web pages she needs to put into the PDF and then clicks a button which creates a PDF with all the selected web pages in it.
To do that, I send the list of selected pages (their IDs) via query string and, on the server, for each web page ID in the query string, it generates an http request to the localhost and gets the page's PDF from this request (i have Request.Filter
that does conversion from HTML to PDF). Then it combines all PDF streams into a single PDF and dumps it into the response stream. Everything works.
But i would like to do it using AJAX. Currently, a new browser window opens and the user has to wait for the server to finish before she can see the page. Instead, I would like to send an AJAX request and, when PDF generation has completed, to show the PDF.
One way to do this is to write the PDF into a file on the server when AJAX sends a request and then redirect to this file, but is there a way to avoid messing with files? For example, can i put the entire PDF into the session? Any other ideas?
Thanks.
Upvotes: 2
Views: 342
Reputation: 3472
Instead of session, why not put everything into a memory stream? Read the content of the HTML pages, generate your byte output, and do something like:
[HttpGet]
public ActionResult PreviewPDF()
{
// ...
// The PDF file stream.
MemoryStream pdf = PDF.Render(xmldata, xslfo);
return new FileStreamResult(pdf, "application/pdf");
}
Also, a quick question: how on earth did you transform your web pages into a PDF, are you using a 3rd party tool?
Upvotes: 0