2

I am trying to change style of printed document using css (@media print) and have defined a simple style to change the heading fontsize while printing. However the style for print media is not changed at all. Could anyone tell where I went wrong? Thanks! Here's what I did

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testmediacss.aspx.cs" Inherits="PrintDemo1.testmediacss" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css" >
   @media print { body {font: 50pt Arial;} h1 {font-size: 138pt;} h2 {font-size: 15pt; color: #000;} }
    </style>
    <script type="text/javascript" language="javascript">
        function CallPrint(strid){
            var prtContent = document.getElementById(strid);
           var WinPrint = window.open('', '', 'letf=1000,top=1000,width=1000,height=500,toolbar=0,scrollbars=0,status=0');
           WinPrint.document.write(prtContent.innerHTML);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
       }
  </script>
</head>
<body>
    <form id="form1" runat="server">
    <div  id="divprint">
        <p>hello this is the part to be printed in the printer.</p>

        <h1>hello world</h1>
        </div>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="CallPrint('divprint');" />

    </form>
</body>
</html>
3
  • though you have a typo in window.open i.e. letf(it shd be left), but still it works for me. even on IE 8 Commented Apr 10, 2013 at 7:34
  • Your CSS is valid. I just tested it. Commented Apr 10, 2013 at 7:34
  • @ScottBartell though it is valid it still donesn't show the desired result.Don't know why. Commented Apr 10, 2013 at 10:34

3 Answers 3

2

I have always used both media print and media screen when defining css.

@media print
{
  h1 {font-size: 138pt;}
}
@media screen
{
 h1 { font size: 95pt;}
}

It will show up on the screen as 95 point text, but print as the 138 point text.

Sign up to request clarification or add additional context in comments.

1 Comment

There's no need to specify screen because it's the default value.
0

Use this instead:

var WinPrint = window.open('', '', 'left=1000,top=1000,width=1000,height=500,toolbar=0,scrollbars=0,status=0');

Not letf

Comments

0

Sometimes, at least in Chrome, that CSS just gets ignored...after pressing Ctrl + R like 20 times, or even better clearing your cache, it will finally work...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.