how can i disable printing a webpage using PHP or Javascript??
any code??

my system will go like this:
the user can print the webpage (html) only once
and then when he/she will attempt to print again that page,
there will be an alert or message that he/she can't print anymore
(CTRL + P or using File> Print)

i have alreay one field in my database with the value 1 or 0.
If 1, he can no longer print.and if 0 he can print.

Now my problem is how can i disable printing? both using ctrl+p
or using the File Menu.

thanks in advance..

Recommended Answers

All 8 Replies

You can try to achieve this, but there are so many ways around this, that it is impossible to solve.

You can't control that on a web page, once its downloaded they got it to print as mmuch as they want

try fooling around with, css
some code that chances the class of the body to "noprint" one with a style @media print{.noprint{display:none;}} remembered in a cookie or a value in the user table, easily bypassed but so is everything else,
I dunno, something like

// database connection code etc
// some ajax to confirm active connection so it isnt being run locally
echo '<body class="';
if($setting<>"0") echo 'noprint ';
echo 'bodytext" onload="stuff">';
// some ajax to crate a print button and update $setting in the user table when it is clicked

not complete code just thoughts

how will i know if the user already printed?
is there any way that i can update my database table field
if the user printed a document??

in php code.

In most cases you won't know. You can add a print button on your page, and notify a PHP script if it gets clicked. However, if they use the browser's menu, you won't get a notification. Even if they use your button, they can always set the number of copies in the print dialog, you'll never know how much they printed.

is there any other way to achieve want i want??
i was able to disable printing with ctrl + P
and what i did when the user uses file>print, there will be no
display when he/she prints.

now, is there a way that i can automatic print??so that the user
will not be able to type how many copies he.she wants to print?

i searched google with many suggestions to bypass print dialog box but they all
didn't work.

As has been mentioned by each poster...there is no guarantee in this. Even if you disabled all of the browser's print functions they could technically copy/paste the page (granted there be no design elements) into a text file and print it from there.

And companies that make browsers do not want site developers to have control over a user's browser due to malicious intent that some might have. There are ways as suggested above to try to make it more difficult to print it out after a first time and then MAYBE it'd be too much work for someone to bother printing it again but if someone really wanted to, they could do it.

It depends on how smart the user is, some users will be stuck and give up when ctrl+p don't work, no display after using file>print will probably confuse a lot of people.

Then you will get quite computer savvy people who will be able to print anything soon as they have received the webpage and you won't know how many anyone has printed, you will only know the prints where people have used the button. Like rockstar said, by copying the source out and just overwriting the css hiding the print or just print it unformatted.

It's something so fundamental you'd have to ask every os & browser to start stopping their users print whatever they want which i doubt will happen, once its printed you could even scan it and re-print the scan

You are going to have to use some other method to track and price whatever it is, such as just paying for the pdf then you get unlimited prints of it or print them yourself and mail them.

You're hitting the same problem the music and film industry have with piracy, it's impossible to stop all of it just make the money where you can with 1 sale per pdf

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.