+ Start a Discussion

How to use specific charset and css property in apex pdf document?

I have used toPdf() method of Blob object in an apex class that is triggered with a custom button for attach pdf document to a custom object. But pdf content can not be displayed Turkish character and also can not be use some property of css. For example:


 I have used following apex code:

global class AccountPDFGenerator
    webservice static void generateInvoicePDF(String accountId)
//        Account account = [SELECT Id,Name FROM Account WHERE Id=:accountId];
        String accId = accountId;
        String pdfContent = '';
            pdfContent = '<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"></meta></head><body>';           
            pdfContent = pdfContent + '<p style="color:red">' + 'öçşğüıÖÇŞĞÜİ' + '</p>';
pdfContent +=  '<table>' +                     
                                        '<tr>' +
                                           '<td align="center" style="border-top-style:dotted; border-bottom-style:dotted;">aaaaaaaa</td></tr></table>' + 
            pdfContent = pdfContent + '</body></html>';
        }catch(Exception e)
            pdfContent = pdfContent + '<P>THERE WAS AN ERROR GENERATING PDF: ' + e.getMessage() + '</P>';
 //       pdfContent = 'öçşğüıÖÇŞĞÜİ'; 
        Attachment attachmentPDF = new Attachment();
        attachmentPDF.parentId = accId;
        attachmentPDF.Name = 'Invoice.pdf';
//        attachmentPDF.body= Blob.valueOf(pdfContent);
        attachmentPDF.body = Blob.toPDF(pdfContent); //This creates the PDF content
        insert attachmentPDF;

 And this is javascript code of custom button:

sforce.apex.execute("AccountPDFGenerator","generateInvoicePDF", {accountId:"{!Account.Id}"});
window.alert("pdf created" );

Created of pdf file after clicking the custom button doesn't contain some character and some html feature as I mentioned. Output of the pdf document is öçüÖÇÜ for following line:

pdfContent = pdfContent + '<p style="color:red">' + 'öçşğüıÖÇŞĞÜİ' + '</p>';


 Do you have an any idea, can you help urgently?


Rajendra PatelRajendra Patel
Did you solve this issue? I have tried various combinations but couldn't find out proper solution. any workarround?