3

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...

2
  • You'd need to post the code for your page before any of us could provide you with advice on what to do. Please take the time to visit the Help center and read How do I ask a good question. The more details you provide, particularly code you've written, the more likely it is that someone will respond to your question with an answer that you'll find helpful.
    – crmprogdev
    Commented Jul 12, 2015 at 20:00
  • 3
    Make sure you are using css2 compliant styles as the pdf rendering engine doesn't support anything css3 right now. Commented Jul 12, 2015 at 20:46

1 Answer 1

1

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:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .