Can't get Meda Print to work

341 Views Asked by At

I'm trying to apply css to my PDF when using ABCPDF. I set the media type to MediaType.Print in the code behind like so:

doc.HtmlOptions.Media = MediaType.Print;

I then add the HTML using the AddImageHtml function.

In the HTML markup I added the following:

<head>
    <title></title>
    <meta name="GENERATOR" content="Microsoft Visual Studio 6.0">
    <style type="text/css">
        @media print {
            table {
                background-color: red;
            }
        }
</head>

Unfortunately this does not work and my tables do not change to red. If I change the CSS from @media print to @media screen it works perfectly fine, which is puzzling because I set the media type to print in the code. Is there another option I'm forgetting to set?

1

There are 1 best solutions below

0
Yufei Wang On

use Gecko as your engine;

doc.HtmlOptions.Engine = EngineType.Gecko;

Gecko engine supports both print and screen media types. The default MSHTML may only support screen.