0

I want to keep the track of how many times the print command is given in my AngularJS project.

here is my code for printing a div -

vm.printWholeJob = function () {
            vm.printCount++;  // It is my print count.
            setTimeout(function () {
                var popupWin = window.open('', '_blank', 'width=1000,height=600');
                popupWin.document.write('<html><head><link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"><style>.print-table th, .print-table td {border: 1px solid #34495E !important;}  .print-table td, .print-table th {padding-bottom:5px  !important;padding-top: 5px !important;}@page {margin-top: 5.0cm;margin-bottom: 3.0cm;margin-right:1.8cm;}.data{page-break-before: always;}</style></head><body>' + document.querySelector('#job-to-print').innerHTML + '</html>');
                setTimeout(() => {
                    popupWin.print();
                    popupWin.close();
                }, 500);
            }, 800);

Here is the catch, I dont want to increase the count on these two cases -

  1. When the windows pops up for print preview and the user cancels it.
  2. When somebody prints it as PDF.

So I just want to track the number of times the page is actually got printed through the printer only.

Thanks in advance.

0 Answers0