Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

CSS: @media print attributes

by AlexTape (Monk)
on Sep 13, 2011 at 12:05 UTC ( #925687=perlquestion: print w/replies, xml ) Need Help??
AlexTape has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
<style type="text/css"> @media print { BODY {background-color: inherit !important;background-image: inherit ! +important;} } table.hbc {border-width:0;border-spacing:0;} table.hbc {border-width:0;border-spacing:0;} table.hbc tr, table.hbc td{border:0;margin:0;padding:0;} table.hbc td{text-align:center;} table.hbc td.hbc_on,table.hbc td.hbc_off {width:2px;height:100px;} table.hbc td.hbc_on {background-color:#000;color:inherit;} table.hbc td.hbc_off {background-color:#fff;color:inherit;} </style> <body> <table class="hbc"> <tr> <td class="hbc_on"></td><td class="hbc_off"></td><td class="hbc_on"></ +td><td class="hbc_off"></td><td class="hbc_on"></td><td class="hbc_on +"></td><td class="hbc_on"></td><td class="hbc_on"></td><td class="hbc +_off"></td><td class="hbc_on"></td><td class="hbc_on"></td><td class= +"hbc_off"></td><td class="hbc_on"></td><td class="hbc_off"></td><td c +lass="hbc_off"></td><td class="hbc_off"></td><td class="hbc_on"></td> +<td class="hbc_off"></td><td class="hbc_on"></td><td class="hbc_off"> +</td><td class="hbc_off"></td><td class="hbc_on"></td><td class="hbc_ +off"></td><td class="hbc_on"></td><td class="hbc_on"></td><td class=" +hbc_off"></td><td class="hbc_off"></td><td class="hbc_on"></td><td cl +ass="hbc_on"></td><td class="hbc_off"></td><td class="hbc_off"></td>< +td class="hbc_on"></td><td class="hbc_off"></td><td class="hbc_on"></ +td><td class="hbc_off"></td><td class="hbc_off"></td><td class="hbc_o +n"></td><td class="hbc_on"></td><td class="hbc_off"></td><td class="h +bc_off"></td><td class="hbc_on"></td><td class="hbc_off"></td><td cla +ss="hbc_off"></td><td class="hbc_on"></td><td class="hbc_off"></td><t +d class="hbc_on"></td><td class="hbc_off"></td><td class="hbc_off"></ +td><td class="hbc_on"></td><td class="hbc_on"></td><td class="hbc_off +"></td><td class="hbc_on"></td><td class="hbc_off"></td><td class="hb +c_off"></td><td class="hbc_on"></td><td class="hbc_off"></td><td clas +s="hbc_on"></td><td class="hbc_off"></td><td class="hbc_on"></td><td +class="hbc_off"></td><td class="hbc_off"></td><td class="hbc_off"></t +d><td class="hbc_off"></td><td class="hbc_on"></td><td class="hbc_off +"></td><td class="hbc_on"></td><td class="hbc_off"></td><td class="hb +c_on"></td><td class="hbc_on"></td><td class="hbc_on"></td><td class= +"hbc_on"></td><td class="hbc_off"></td><td class="hbc_on"></td></tr>< +tr><td colspan="73">barcode</td> </tr> </table> </body>
im not able to get this *'$"# barcode printed with the printer :-( whats the weakness? it is only working if i set this
user_pref("print.printer_<printername>_(DIRECT).print_bgcolor", true); user_pref("print.printer_<printername>_(DIRECT).print_bgimages", true) +;
in about:config @firefox.
im tired to waste my time with this silly thing. glad to get a solution...

$perlig =~ s/pec/cep/g if 'errors expected';

Replies are listed 'Best First'.
Re: OT: CSS: @media print attributes
by MidLifeXis (Monsignor) on Sep 13, 2011 at 13:11 UTC

    FYI - this is pretty well off topic for PerlMonks.

    This is how the browser works. It will not print the background colors of an element without being told to do so. If you wish to have this work the way you are specifying it, perhaps something like filling each cell with a 2px wide image of either on or off would be better. Then the displayed item is in the foreground instead of the background.

    If I have a web page with a black background (or even better, a @media print setting of a black page), would you want the browser to, by default, print this? Or would you want the browser to make it as readable as possible on the selected media?

    Use a foreground element of some sort (<img> for example) to generate what you want to display.


Re: CSS: @media print attributes
by onelesd (Pilgrim) on Sep 13, 2011 at 18:12 UTC
    Since this is a perl website, I recommend you write some perl to make a printable version of the page and be done with it: http://domain.tld/page?print=1
      use strict; use CGI::Carp qw(fatalsToBrowser); use CGI ':standard'; use HTML::Barcode::Code93; my ($cgi,$code,$media); $media =<<END; @media print { BODY {background-color: inherit !important;background-image: inherit ! +important;} } END $cgi = new CGI; print $cgi->header(); print $media; $code = HTML::Barcode::Code93->new(text => 'code'); print $code->render; 1;
      it still is a perl output..
      $perlig =~ s/pec/cep/g if 'errors expected';

        But it has nothing to do with perl :)

        Its not interpreted by perl

        Its not validated by perl

        Its not displayed by perl

        Its a browser that refuses to print the background colors because that is a feature of the browser

        Its a browser user feature

        You can't circumvent this browser feature

        If a browser allowed random websites/htmlfiles to circumvent user features, it wouldn't be a very secure browser

        Think about it

        When users want to print pictures, browsers are pretty smart in actually printing pictures, maybe you want to give users a real picture (png/gif)

Re: CSS: @media print attributes
by Anonymous Monk on Sep 14, 2011 at 04:23 UTC

    im not able to get this *'$"# barcode printed with the printer :-( whats the weakness?


      said the callcenter agent ?! ;-)
      $perlig =~ s/pec/cep/g if 'errors expected';

        Yes :) I explain before but apparently not well enough, hope I do better this time

        Return a real gif/png, browsers like to print those

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://925687]
Approved by AR
Jar. Jar!...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2018-07-16 16:11 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (344 votes). Check out past polls.