Welcome Guest Search | Active Topics | Sign In | Register

MVCToPDF - save file without returning view to user Options
PDB
Posted: Thursday, February 4, 2016 11:07:45 AM
Rank: Newbie
Groups: Member

Joined: 12/14/2015
Posts: 2
Hi!

I’m using MVCToPDF to render reports selected by the user from a drop-down. Each report is created from a .cshtml-view. The user can choose to either view the report (in which case it opens in another tab) or save the report.
To save the report I’m overriding OnResultExecuted and saving HtmlToPdfResult.PdfDocument.

My question is: Is it possible to create a pdf with MVCToPDF and save it without returning the view to the user or having them receive the pdf as a download?
I really want the user to remain on the page where the drop-down is located.

Regards,
Robin
eo_support
Posted: Thursday, February 4, 2016 4:00:16 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

You can return the result as a download easily by setting this property to true:

http://www.essentialobjects.com/doc/eo.pdf.mvc.mvctopdf.resultasdownload.aspx

The tricky part is this would replace the contents in the current window with the PDF file by default. This is because HTTP works strictly by request/response pairs. Your browser sends a request to the server, gets a response and loads that response. That response can either be an HTML page (the same page that contains your drop down list) or the PDF file. It can not be both.

In order to achieve what you want to achieve, you must use an additional pair of request/response. An very common way to add another pair of request/response in your page is to use an iframe. The iframe can have its own form, post its own data and if your server side code for that iframe returns a download, the browser will prompt you as a download. Since it's an iframe, it is separate from your main contents.

Details about using an iframe to trigger a download is beyond the scope of our support --- it does not have anything to do with our product or even MVC at all. You can search online and you should be able to find plenty of information on this. If you still have any specific questions about our product while implementing this, please feel free to ask.

Thanks!
PDB
Posted: Friday, February 5, 2016 3:47:22 AM
Rank: Newbie
Groups: Member

Joined: 12/14/2015
Posts: 2
Hi,

Thanks for your answer.
English is not my first language and I realize my question was a bit misleading.
What I really want to achieve is to save the file (in OnResultExecuted) without returning anything to the user, neither a view nor a download. No download prompt or anything visible for the user.
Is that possible?

Regards,
Robin
eo_support
Posted: Friday, February 5, 2016 9:37:34 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Then you would set this property to false:

http://www.essentialobjects.com/doc/eo.pdf.mvc.mvctopdf.sendtoclient.aspx

You can take a look the commented out code in OnResultExecuted method in DemoController.cs of PDFMvc sample application for more information.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.