MVC print PDF without displaying in view with print dialog - pdf

I have an MVC app where the intention is for the the user to click Print, and in the subsequent print dialog, verify the target printer, number of copies, etc, and click Print. I'm rendering the PDF document and returning the document thusly:
return File(printJob.Bytes, "application/pdf");
This displays the document quite nicely in the browser. In both Chrome and Edge, when the user clicks Print, they get a preview of the page in the print dialog. So the user experience is they click Print, see a preview, click print, see a preview again and then click print. Does anyone know if it's possible to render the PDF document without displaying it in the browser and instead just present the user with the print dialog box?
Thx in advance!

When you return the PDF from your website, the browser is then acting as a PDF viewer instead of a web browser, so you need to get the PDF to request the print dialog on open, not the website.
You can achieve this by adding the document javascript this.print(true) into the PDF that you are generating.
You can test this in Adobe Acrobat by going to Javascript -> Edit All Javascripts and just pasting this.print(true) at the top outside of any named function.
Tested and working on Chrome, as soon as you open the PDF it displays the print dialog.
Acrobat Javascript Reference is here, the reference to the print function is on page 179.

Related

Disallow users to download, save or print document shown in an iframe

I'm showing pdf document in an iframe. The pdf resides in the same domain. I don't want to allow users to download, save or print the document.
I've removed Print and Download option from the top toolbar by applying CSS but still user can save or print the document on right click. I tried disabling right click using below code but it's not working on the iframe.
document.addEventListener('contextmenu', event => event.preventDefault());
Is there any way to disallow users to download, save or print document shown in an iframe? Any help will be appreciated.

Disable PDF printing in Firefox by web developer

I am developing a web page to show PDF (in .NET platform). The PDF is inside a iframe. One of the requirement is NOT allow client to print the PDF. I have already made the PDF to be password protected (with pdfsharp). I further hide the toolbar by setting toolbar=0. In Chrome & IE, this works fine. But for Firefox, the story is totally different.
In Firefox, the toolbar will be shown even append #toolbar=0 in the src link. Further, the password protected pdf can be printed by simply clicking the icon in the toolbar.
Can anyone suggest some ways to disable pdf printing in firefox.
Note: I need to show the PDF in the webpage. So, download the PDF is not a option.
You will not be able to control the toolbar or the ability to print (not all PDF viewers respect the permissions set by the password) if you rely on the native browser or OS level PDF viewer by using an iFrame. Different browsers will interpret those settings differently. Even different applications within the same browser will yield different results (Chrome vs Dropbox in Chrome)
You'll need to display the PDF using something like PDF.js or another such library if you want any kind of consistency in appearance and behavior.

Is it possible to have a hyperlink open in a new tab that is inside a pdf that is inside of a frame in classic asp?

I Have a classic asp site i am working on. The page has two frames one directly below the other. A Customer has to be able to view a pdf to continue onto the next page. To get to the next page they have to click on a hyper link inside of the pdf that is being viewed. If they cannot see the pdf then they have to download adobe reader which i have included a link to in the top frame.(The top frame has some text and the link) now the bottom frame(contains the pdf) this works fine except when i click the link that is in the pdf the page then opens in that same bottom frame that contained the pdf. It needs to be target _blank. Or whatever you would call it to basically either over ride the two frames and just open in the browser or open in a new tab or window which i cant get either to do. This problem is in IE and Firefox but in chrome it over rides the two frames and opens correctly. Is there any way to get this to occur in IE and Firefox?
I've found this resource about your issue:
http://forums.adobe.com/thread/853394
They say there's no target attribute to set. But they think (and i also think) that if you place a :
javascript:window.open('http://yoururl.com');
it should work, always if you can accept the security alert message (Abobe PDF is trying to execute a script... blah blah)
If your continue reading carefully it seems they solved the problem using Adobe scripting inside inDesign
Hope this helps...

Embedded PDF prints off-center

<embed width="100%" height="100%" src="filename.pdf" type="application/pdf">
I can embed a PDF file into a web page using the simple code above. But when I go to print the web page (using CTRL+P), only half the PDF appears on the print preview as it has been off-centred. The same happens on this web page: http://pdfobject.com/examples/simplest-full-window.html.
Here is an example of a 'Print Version' web page where the embedded PDF centres when it is printed (CTRL+P): http://www.bbc.co.uk/food/recipes/our_paella_92328.pdf. This example is also responsive, which is useful as the print appearance remains consistent no matter the size of the browser window.
Firstly how do I centre the embedded PDF upon printing? Secondly, how do I make the embedded PDF responsive?
When you want to print an embedded PDF, you must use the print command from the PDF plugin, not the print command from the web browser.
In the first example the Javascript code loads the PDF plugin and replaces the HTML document with the PDF document. If you hit CTRL+P then the print dialog from Internet Explorer is shown. If you click into the PDF plugin then press CTRL+P, then the print dialog from Adobe PDF plugin is shown.
In second example you open directly the PDF file. In this case the PDF plugin is loaded and activated automatically. No need to click in it. Pressing CTRL+P brings its own print dialog.

Printing pdf without opening

I want to open a PDF-print dialog (not regular browser dialog) without visually opening the document so that I can print a pdf without having the header and footer information from a regular webpage print.
I know this is possible, because I have seen it in the past on a postal service website for printing postage labels, but cannot remember where.
As far as I know, printing it from an iframe doesnt work, as it only opens regular browser print dialog and gives me ugly page and url information:
frames['name'].focus();
frames['name'].print();
I found this:
http://www.fpdf.org/en/script/script36.php
I embedded that in an invisible iframe. It prints onload, and the PDF stays invisible.