I am generating a PDF from a trigger, the problem comes when displaying the styles.
It does not work in any way, I have tried:
But the styles in the pdf do not apply:
An example of the code I am working with:
String htmlBody = '<html><head><style type="text/css">table{border: 1px solid black;}</style></head><body><table><tr><th>HI</th></tr></table></body></html>';
Blob bodyData;
try {
bodyData = Blob.toPDF(htmlBody);
} catch (Exception e) {
}
Attachment attachmentPDF = new Attachment();
attachmentPDF.parentId = 'ID OF RELATED RECORD';
attachmentPDF.Name = 'Attach.pdf';
attachmentPDF.body = bodyData;
attachmentPDF.ContentType = 'pdf';
insert attachmentPDF;