Reputation: 41
I have created a series of .html documents that have a footer appearing at the end of each printed page, without showing up on the screen. I also have the page breaks explicitly declared, so that they fall in non-disruptive places. This is done using the CSS combination of:
@media screen {
.bottom, .split {
display: none;
}
}
@media print {
.bottom {
display: block;
text-align: center;
width: 8in;
position: fixed;
bottom: 0;
}
.split {
page-break-before: always;
}
.whole {
page-break-inside: avoid;
}
}
The bottom class is used for the footer, the split class for the page breaks, and the whole class for data tables, so that they're not split in the middle. This works quite wonderfully when printing the individual documents via the browser's print command.
However, these documents have to be ran through a batch script that generates PDF copies of them for some other business processes (PHP using DOMPDF). Initially, none of the @media print CSS references were recognized. Then I changed the DOMPDF_DEFAULT_MEDIA_TYPE to "print", and it started recognizing the page breaks, but still refuses to print the footer. Again, the footer prints out just fine when printing directly from the browser.
I need to rectify this issue ASAP. Any input would be appreciated.
EDIT: I have confirmed that the HTML in the documents validates against HTML5 standards.
Upvotes: 1
Views: 2159
Reputation: 13944
Looking at the source it looks like dompdf is pretty much slurping up styles for all media types except the default (or something like that ... I'll have to look at the code a bit more to see whats really going on).
case "media":
$acceptedmedia = self::$ACCEPTED_GENERIC_MEDIA_TYPES;
$acceptedmedia[] = $this->_dompdf->get_option("default_media_type");
$media = preg_split("/\s*,\s*/", mb_strtolower(trim($match[3])));
if ( count(array_intersect($acceptedmedia, $media)) ) {
$this->_parse_sections($match[5]);
}
break;
[ref]
You didn't specify the version you're using, but in 0.6.2 (the last version to use the configuration file. I'd say try using a combined media selector like @media print,dompdf
to get dompdf to recognize the print styling.
Upvotes: 1