I am making an invoice website while learning ASP.net MVC, and so far so good. The problem I am running into is when I update an invoice in my app, then try and download it as a pdf, I get the initial content of the page and none of the updates. I'd like to display the pdf before someone downloads it which is working just fine. So I don't know if my problem has something to do with the stream not getting the changes on the page.
If possible I would also like a Guid returned in the URL and have no idea how to do that with how things are currently set up.
Any help would be amazing!
Note: I published the site but ABCpdf errors out (possibly due to it being the trial version), however, locally I can generate a PDF
View
@Html.ActionLink("Download PDF", "DownloadPDF", null, new { @class = "btn btn-action", @target = "_blank" })
Controller
public ActionResult DownloadPDF()
{
Doc pdf = new Doc();
MemoryStream stream = new MemoryStream();
pdf.Rect.Inset(40, 40);
pdf.HtmlOptions.Engine = EngineType.Gecko;
pdf.HtmlOptions.UseScript = true;
pdf.AddImageUrl("http://local.completeinvoice.com/");
byte[] data = pdf.GetData();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=invoice-001.pdf");
Response.AddHeader("content-length", data.Length.ToString());
Response.BinaryWrite(data);
Response.Flush();
Response.End();
pdf.Flatten();
pdf.Save(stream);
stream.Close();
pdf.Clear();
return View("Index");
}