Bradley Gatewood
Bradley Gatewood

Reputation: 248

Printing a PDF Document in ASP MVC Without Showing it First

I've got some code that builds a PDF document and opens it in a new tab but what I'd really like to do is send it straight to the printer.

There is a lot going on behind this code but basically it boils down to I make call to the controller from the view

<a href="~/Controller/GetReport/" target="_blank">Report</a>

The method goes and builds a PDF document and returns it as a file.

public ActionResult GetReport()
{
    return File(a byte[] containing the content, "application/pdf");
}

The resulting PDF is displayed in a new tab.

What I'd rather happens is the user clicks the link and the document starts printing or just the print dialog opens and the user clicks ok to print.

I'm also using iTextSharp to handle some of the PDF functionality if that can be used to simplify the problem.

Upvotes: 0

Views: 1096

Answers (1)

Bradley Gatewood
Bradley Gatewood

Reputation: 248

Well I never got it to go directly to the printers but I did find that by specifying the download file name it causes it to immediately save and then open which is good enough for this requirement.

Upvotes: 1

Related Questions