function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mustafatopmustafatop 

How to use some css features within pdf that is generated by apex code?

I have used toPdf() method of Blob object in an apex class, that is triggered with a custom button for pdf file is attached to Account record.

Some css style features as style="border-top-style:dotted;", style="font-family: Arial Unicode MS;" are not display in pdf file. This style features are working in apex page that using renderAs="pdf" attribute. But it isn't work when pdfContent variable is used as parameter by toPdf() method.

Can somebody help me?

 

global class AccountPDFGenerator{
    
    webservice static void generateInvoicePDF(String accountId){
//        Account account = [SELECT Id,Name FROM Account WHERE Id=:accountId];
        
        String accId = accountId;
        
        String pdfContent = '';
        try
        {                       
           pdfContent +=   '<html>' +
                                '<body>' +
                                    '<p align="left" style="font-family: Arial Unicode MS;">öçşığü</p>' + 
                                    '<br/><br/>' +
                                    '<table>' +                     
                                        '<tr>' +
                                           '<td align="center" style="border-top-style:dotted; border-bottom-style:dotted;">ÖÇŞİĞÜ</td>' +
                                        '</tr>' +                                        
                                    '</table>' +
                                '</body>' +
                            '</html>';
        }catch(Exception e)
        {
            pdfContent = pdfContent + '<P>THERE WAS AN ERROR GENERATING PDF: ' + e.getMessage() + '</P>';
        }
        
        Attachment attachmentPDF = new Attachment();
        attachmentPDF.parentId = accId;
        attachmentPDF.Name = 'Invoice.pdf';
        attachmentPDF.body = Blob.toPDF(pdfContent);
        insert attachmentPDF; 
    }
}

 This is javascript code of custom button.

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
sforce.apex.execute("AccountPDFGenerator","generateInvoicePDF", {accountId:"{!Account.Id}
Rajendra PatelRajendra Patel
Have you got any solution? Any workarround?