I've seen a few questions like this around SO but couldn't find anything that's right for me. The chain of events that I would like to occur is as follows:
- User clicks an ASP.NET button control
- This fires that button's onclick event, which is a function foo() in the C# codebehind
- foo() calls some other (unimportant) function which creates a PDF which ends up saved to the server's disk. That function returns the path to the PDF
- Without any other user interaction, once the PDF is generated, the print dialog box opens in the user's browser to print that PDF
What do I need to do to accomplish step 4? Ideally, it would be something I can call in foo(), passing in the path to the PDF, that will trigger the print dialog box in the user's browser (printing the PDF and not the page the from which the onclick fired).
I think that I might be able to forward to the URL of the PDF document, and embed some Javascript in the PDF that automatically prints it, but I would rather not - I don't necessarily want to print the PDF every time it's opened (in a browser). Any other good way to do this?