I have to display the rows of alternate colors based on some condition in PDF format. The same code is working in HTML but not working while render as PDF.
If anyone have work around, please let me know...
I have to display the rows of alternate colors based on some condition in PDF format. The same code is working in HTML but not working while render as PDF.
If anyone have work around, please let me know...
Last I heard the underlying PDF rendering engine used by Visualforce was based on Flying Saucer (I'm not sure if this if officially acknowledged anywhere, but I believe it to be true). As @cricketlang commented, this limits you to a subset of CSS 2.1.
With the various nth
selectors being CSS3 specific, you can't use them in the PDF output.
There is a workaround covered in How would I go about shading every other row? by Felix Grund using the adjacent sibling selector.
The only way to achieve an nth-child-alike effect is to look at fallbacks for old IE browsers using CSS only. There is only one way that I know of, using the adjacent sibling selector. It's pretty ugly and you might need a log of CSS code if your tables are big. But in general it works fine (I tested it).
/* row 1 */ tr,
/* row 3 */ tr + tr + tr,
/* row 4 */ tr + tr + tr + tr + tr { background: #ccc; }
/* ..repeat as often as necessary.. */
/* row 2 */tr + tr,
/* row 4 */ tr + tr + tr + tr,
/* row 6 */ tr + tr + tr + tr + tr + tr { background: #fff; }
/* ..repeat as often as necessary.. */
Are you using your over controller for the page? You could put something there to use as a toggle for the row styles. Maybe a modulo operation on an id or index field?
See also: