0
Precise limit the number of printouts of an HTML document.
Currently if the file is generated (via PHP), record in the database a flag sts_impresso = 1
, however, there are times when the user has not printed for some situations:
- You clicked the cancel button;
- Closed the window;
- There were internet connectivity issues at the time of downloading the file to be printed.
And in the three situations above, it had already been marked as printed and the document is unable to be printed again.
So I thought to carry out the control via Javascript:
function imprimir() {
url = URL_DO_DOCUMENTO_IMPRESSO; // url do documento
var nw = window.open(url, "popView" , 100, 100, "yes", "yes", true); // abro em nova janela
$(nw).ready(function () { // assim que carregou, chama o print
nw.print();
});
}
How to detect if user clicked button Print out or on the button Cancel on the browser print screen, or if it simply closed the window?
From the confirmation that there was printing, I want to make an AJAX request to mark as printed and then close the window.
This is just an idea of implementation to solve the problem described in the title of this question.
Different viable implementations for problem solving will be welcome.
Note: I know that everything in the browser can be swindled and I cannot trust the code coming from the CLIENT (Browser), but I need to at least minimize this problem.
You just discovered one of the problems of doing web stuff. Actually anything that depends on the client controlling and informing the server will have problems. Have you heard that can never trust what comes from the customer? Even if you create a mechanism that helps, you cannot trust it. It can fail and it can be swindled. It will continue with the problem. In a native application it is more difficult to fail, easier to detect and more difficult to circumvent (assuming that it doesn’t matter much if it is printed several times, since this can always be circumvented by the customer).
– Maniero
That’s exactly what @bigown said, it also has the option to print in PDF, and so it will be able to print as many times as you want afterwards, from the generated PDF..
– Marco Giovanni
Also that the bigown and @Marcogiovanni already said, you don’t even know how many copies the person chose in each print "request".
– Bacco
@bigown, Marcogiovanni and Bacco... would there be any way to at least minimize the problem? ... at least detect if user clicked to print or cancel?
– Allan Andrade
No. Nor is it universalized among browsers. Anything that needs minimal custom control will suffer from the limits of Web applications, as @bigown commented. Even a print-only media would only be accessed by the person seeing the preview. There’s not much to do.
– Bacco