0

I have pdfs being generated on a website, and am trying to implement a print button for that pdf. I know about being able to print a specific div and it's associated html, but is it possible to have a button that opens up a pdf generated by my website in the chrome print preview without having to download it first?

I appreciate any help.

3
  • 1
    Short answer is no. Commented Jun 21, 2016 at 5:36
  • 1
    No as @StephenMuecke mentioned. But you can display your pdf in an <iframe> or <object>. The displayed pdf will have native controls one of which is the print button, beware that you can't control or code behind those controls as those are just browser features. Viewing of pdf may vary per browser. Commented Jun 21, 2016 at 5:45
  • Thanks for the information! Commented Jun 21, 2016 at 6:22

3 Answers 3

3

The pdf file that is generated on the server has to come down to the client (i.e. downloaded) so cannot really print something that is not on the client. In case you want to bypass the file saving action (explicitly done by the user) and go directly to print preview, you can try something like this before returning the file:

var pdfFileName = "Some Filename"; if (Request.Browser.Browser == "InternetExplorer" || Request.Browser.Browser == "IE") { Response.AppendHeader("content-disposition", @"attachment;filename=""" + pdfFileName + @".pdf"""); } else { Response.AppendHeader("content-disposition", @"inline;filename=""" + pdfFileName + @".pdf"""); } byte[] pdfBytes = ... // get the file data into this variable return File(pdfBytes, "application/pdf") 
Sign up to request clarification or add additional context in comments.

1 Comment

Genius! This is a great solution. Works well for Crystal Reports pdf as well.
0

I don't think so. The PDF still has to be downloaded and rendered by the PDF library before it can be printed, unlike HTML which is the browser's native format.

Comments

0

Use Datatables.Net Export tables

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.