PHP - Capturing the moment of print?
Discussion
I need to log every time someone prints from my app. Currently we use CSS which works a treat, but the class that I'm now using to create PDF prints doesn't support background-image
{{{
<?php
if ($BeenPrinted =='1') {
$BGImage = "background-image:url(logit.php?RecordNo=$RecordNo&DBForLogit=db04)";
}
else {
$BGImage = "background-image:none;";
}
?>
}}}
Can anyone think of another way of capturing the moment someone prints?
{{{
<?php
if ($BeenPrinted =='1') {
$BGImage = "background-image:url(logit.php?RecordNo=$RecordNo&DBForLogit=db04)";
}
else {
$BGImage = "background-image:none;";
}
?>
}}}
Can anyone think of another way of capturing the moment someone prints?
I'm assuming they're printing from the browser's menu rather than a dedicated print button in the app?
(haven't you mentioned this before on here, btw? Sounds familiar)
ETA - how about just making it a regular <img >, ie <img width='1' height='1' src='logit.php?etcetc' >
The tricky bit was setting the 'BeenPrinted' var.
(haven't you mentioned this before on here, btw? Sounds familiar)
ETA - how about just making it a regular <img >, ie <img width='1' height='1' src='logit.php?etcetc' >
The tricky bit was setting the 'BeenPrinted' var.
Edited by Famous Graham on Saturday 4th September 12:05
I have and the above suggestion has been working admirably I just need to find something else that I can trigger when the @media print event occurs. I do have a print button, but it could be circumvented with <ctrl>p
So how would you call an image solely at print time? I can only use a limited set of inline CSS at this juncture.
So how would you call an image solely at print time? I can only use a limited set of inline CSS at this juncture.
BliarOut said:
I have and the above suggestion has been working admirably I just need to find something else that I can trigger when the @media print event occurs. I do have a print button, but it could be circumvented with <ctrl>p
So how would you call an image solely at print time? I can only use a limited set of inline CSS at this juncture.
Ah, I thought you could put a 1x1 img in the html. Then change the src via PHP&CSS, like you were the background-image. So how would you call an image solely at print time? I can only use a limited set of inline CSS at this juncture.
ETA - ignore that. Can't change the src in CSS. Could have sworn that you could. Nuts.
Edited by Famous Graham on Saturday 4th September 15:26
Is it necessary that it logs an actual successful print event or merely generation of a print dialogue box. Onafterprint is only triggered when sent to queue/cache not actually printed and is IE specific.
Even though your print media css file is a clever workaround, surely a log would be triggered just using print-preview, so not %100 accurate.
If you use FPDF and a bit of JS you can use a single link to dynamically generate the pdf file, open it in a new window, trigger a print dialogue box and log each time the url has been called. This would give a pretty accurate log of printing.
Are you developing it locally or is there a link to the site, so we can have a gander
Even though your print media css file is a clever workaround, surely a log would be triggered just using print-preview, so not %100 accurate.
If you use FPDF and a bit of JS you can use a single link to dynamically generate the pdf file, open it in a new window, trigger a print dialogue box and log each time the url has been called. This would give a pretty accurate log of printing.
Are you developing it locally or is there a link to the site, so we can have a gander
BliarOut said:
No can gander unfortunately... And Preview doesn't trigger it. Well I don't think it does but I won't know until tomorrow
The CSS works very well as it's cross browser and you can't circumvent it with <ctrl>p
Pretty sure it will as its still calling the background image just for the preview. The CSS works very well as it's cross browser and you can't circumvent it with <ctrl>p
What are you using to set the value of $BeenPrinted ?
Famous Graham said:
So you can only change the bold bits? And only replace/amend it with another style?
{{{
<?php
if ($BeenPrinted =='1') {
$BGImage = "background-image:url(logit.php?RecordNo=$RecordNo&DBForLogit=db04)";
}
else {
$BGImage = "background-image:none;";
}
?>
}}}
The only bit that really matters is logit.php?RecordNo=$RecordNo&DBForLogit=db04) When that's called it updates the record to indicate it's been printed then puts an entry in the audit table. I need to somehow get that to run at print time. A print button is an option but that can be side stepped.{{{
<?php
if ($BeenPrinted =='1') {
$BGImage = "background-image:url(logit.php?RecordNo=$RecordNo&DBForLogit=db04)";
}
else {
$BGImage = "background-image:none;";
}
?>
}}}
How about approaching it the other way? Have an @media screen CSS and set a div to not display that somehow calls logit.php? Could that work and if so how would I call it?
Yeah, I understand that you need to call logit.php and pass the parameters.
What I was trying to determine was just how much freedom you have to do that.
ie if you're free to simply run some php in that if statement, then you can just use http-get or fsockopen (if http-get isn't installed), and not have to worry about CSS at all.
ETA - cos from that code you've posted, you've already handled the actual print event, thus setting $BeenPrinted, no?
What I was trying to determine was just how much freedom you have to do that.
ie if you're free to simply run some php in that if statement, then you can just use http-get or fsockopen (if http-get isn't installed), and not have to worry about CSS at all.
ETA - cos from that code you've posted, you've already handled the actual print event, thus setting $BeenPrinted, no?
Edited by Famous Graham on Monday 6th September 12:31
$BeenPrinted is set by logit.php which won't currently run so the status of the record's printed field always remains at 'No' $BeenPrinted is a throwback to some old code which I no longer really need but haven't tidied as yet.
It could really do with altering to
{{{
$Printed = $row_Recordset['Printed'];
if ($Printed=="No") {
$gen = ' (Original)';
} else {
$gen = ' (Duplicate)';
}
}}}
What about calling some ajax to run logit.php attached to the onbefore and onafterprint events. It means i will only be able to print from IE but that's not the end of the world...
It could really do with altering to
{{{
$Printed = $row_Recordset['Printed'];
if ($Printed=="No") {
$gen = ' (Original)';
} else {
$gen = ' (Duplicate)';
}
}}}
What about calling some ajax to run logit.php attached to the onbefore and onafterprint events. It means i will only be able to print from IE but that's not the end of the world...
Keith Lard said:
Can you give us a quick overview of the application?
What's the nature of the documents your outputting. Are users having to pay to view/print these documents?
I'm sure with a bit more info someone here can help you.
It's just a document but I'm afraid I can't give you an overview as it's CIC. Basically the first time it prints it will say original but from then on it will say duplicate and each time it is printed it is audited....What's the nature of the documents your outputting. Are users having to pay to view/print these documents?
I'm sure with a bit more info someone here can help you.
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff