0

I have an html string and I want to print it out. I'm okay with it opening the confirm or print preview dialog box I just want a function like this

HtmlPrinter.PrintHtml("<html><body>Page I'm printing</body></html>");

anyone know anything that will work like this?

1
  • there's a "printf" in C language... maybe you should try that! :-D (being sarcastic here) Commented Aug 12, 2009 at 23:29

2 Answers 2

3

Web browsers give you the ability to print the current page. You can trigger the print dialog box via javascript and you can use CSS to style that page such that the printed output bears little resemblance to what's shown on the screen, but that's about it as far as printing goes.

Going beyond plain html, you might be able to use something like flash, silverlight, or another browser plugin. But really the closest you can get is something like this:

<html>
    <head>
        <style>
            @media print
            {
               .HidePrint { display:none; visible:none;}
            }
            @media screen
            {
                .HideScreen {display:none; visible:none;}
            }
        </style>
    </head>
    <body onload="window.print();">
        <div class="HideScreen">
            Page I'm printing
        </div>
        <div class="HidePrint">
            Other content...
        </div>
    </body>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, thanks! Didn't know you could use @media to specify different style sheets for printing.
0

Joels answer is correct, obviously.

To help you understand why; C# runs on the server, JavaScript runs on the client. If you did try and print from C#, you'd be printing from your server machine :)

2 Comments

Makes sense, thanks for the explanation. Probably should have posted this as a comment though, I'm guessing that's why your answer got down voted.
shrug, didn't make sense as a comment to his post or yours, IMHO, but I'm new here. I don't mind being downvoted because my information is still correct :)

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.