Greetings fellow coders!
I've done tons of research on this topic and can't manage to find any resources that truly depict how this process can be done (or if it can be done). So, I'm turning to you all for some advice!
The Issue:
So right now, I have a form that sends the filled out data back to the controller via HttpPost. At this point, I pass that form data to the model function to create the PDF. Now at this point, I have it returning the PDF file if the model function was successful.
PDFMemStream memstream = new PDFMemStream();
CreatePDFinfo formdata = new CreatePDFinfo();
if (ModelState.IsValid)
{
memstream = CreatePDF.Populate_PDFcontent(formdata);
if (memstream.retval.success)
{
// if creating pdf is successful, return file
return File(memstream.mstream, "application/pdf");
}
}
ViewBag.PageTitle = "Cool PDF Project";
ViewBag.TabTitle = "Really Cool PDF Project";
return View(formdata);
I can display this created PDF in a separate tab if I use the code below in the view. This assumes that the current view is called "createPDF". So this part works all fine and dandy.
$('#form').submit(function () { if ($('#form').valid()) { window.open('', 'createPDF'); this.target = 'createPDF'; } });
If I don't use the above code, after the button click, it will remain on the current page and reload the page with only the pdf content in the native browser PDF viewer.
The Needed Solution:
As I stated, everything works perfectly if I wanted the PDF to be populated in at new tab or the existing one. HOWEVER, what I need, is a way to view the PDF on the same page either in a partial view or embedded on the existing page. I could even deal with the PDF being embedded in a new view as long as I could pass the model data to the new view for other sections of that page.
Resources & Articles:
Here's all of the articles and resources I've already looked into and read (so please do not post the same ones):
using ITextSharp to extract and update links in an existing PDF
Displaying a pdf to webpage using iTextSharp?
MVC Application to Display embedded PDF documents
https://www.codeproject.com/Questions/890372/How-Can-I-Display-A-Pdf-From-Byte-Array-In-Mvc
https://www.codeproject.com/Articles/66948/Rendering-PDF-views-in-ASP-MVC-using-iTextSharp
C# ASP.NET MVC Create PDF from view Rotativa or iTextSharp?
Convert PartialView Html to String for ITextSharp HtmlParser
How to open a PDF file in an <iframe>?
How to render an ASP.NET MVC View in PDF format
Now some of the articles aren't completely relevant but I included them just in case they may be helpful.
UPDATE:
In case anyone else runs into a similar issue, what I ended up doing was processing the non-PDF related method first, returned a new view with the model data, and then made an AJAX call to a route that creates/generates the PDF. Hopefully that makes sense. Haha. :)
Any suggestions, tips or advice?...