I'm creating an HTML string that I put in a in blob.toPDF to send PDFs as attachments

public static Messaging.EmailFileAttachment attachmentBuilder(String fileName, string attachEmailInHTML){
        Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
        attach.body = blob.toPdf(attachEmailInHTML);
        return attach;

However, I saw that when I put CSS style in a header in the character string it is not taken into account

So I put CSS values ​​in attributes of HTML elements

I managed to fix HTML table borders not showing by putting border="1"

Colors of fonts with the color attribute display fine

On the other hand, I can't display a color in the background in cells

Here is my code for the HML table with several tries to show the background:

 htmlDesTableauxTournees = htmlDesTableauxTournees 
+ '<table border="1">' 
+ '<tr>' 
+ '<th style="font-size: 9px;color:green;background:#e15494";>Company</th>' 
+ '<th style="color:green;background-color:red":>Contact</th>' 
+ '</tr>' 
+ '<tr>' 
+ '<td style="color:green;background -color:#e15494;">zz</th>' 
+ '<td style="color:green;background-color:rgb(111,111,111);">xx</th>' 
+ '</tr>' 
+ '</table>';

Here is the current rendering in the PDF file sent by email: enter image description here

Do you have an idea ?

1 Answer 1


I found the solution : in HTML there is the attribute bgcolor

<th style="font-size: 9px;color:green;" bgcolor="#e15494">Company</th>

enter image description here

You must log in to answer this question.

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