0

我需要在 pdf 文档中打印出土耳其字符,如“ş”、“ç”、“ü”等。我正在使用以下代码。

global class InvoicePDFGenerator {

    public static final String FORM_HTML_START = '<HTML><BODY>';
    public static final String FORM_HTML_END = '</BODY></HTML>';

    webservice static void generateInvoicePDF(String invoiceId){
        OppoInvoice__c invoice= [SELECT Id,Account_Name__c FROM OppoInvoice__c WHERE Id=:invoiceId];
        String pdfContent = '';
        try {
            pdfContent = '<html><head><meta http-equiv=content-type content=text/html;charset=iso-8859-9></meta></head><body>';

            pdfContent = pdfContent + '<P>' + invoice.Account_Name__c+ '</P>';
            pdfContent = pdfContent + FORM_HTML_END;
        }catch(Exception e){
            pdfContent = '' + FORM_HTML_START;
            pdfContent = pdfContent + '<P>THERE WAS AN ERROR GENERATING PDF: ' + e.getMessage() + '</P>';
            pdfContent = pdfContent + FORM_HTML_END;
        }

        Attachment attachmentPDF = new Attachment();
        attachmentPDF.parentId = invoice.Id;
        attachmentPDF.Name = 'Invoice.pdf';
        attachmentPDF.body = Blob.toPDF(pdfContent); //This creates the PDF content
        insert attachmentPDF;

    }
}

attachmentPDF.body = Blob.toPDF(pdfContent)我认为是从线引起的问题。你对这个问题有什么想法吗?

4

2 回答 2

0

我将带有土耳其字符的字符串常量推送到 pdfContent 中。对于输入值“öçşğüıÖÇŞĞÜİ”,输出为“öçüÖÇÜ”。

这是无需查询的代码。

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><head><meta http-equiv="content-type" content="text/html; charset=iso-8859-9"></meta></head><body>';           
            pdfContent = pdfContent + '<p style="color:red">' + 'öçşğüıÖÇŞĞÜİ' + '</p>';
            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;

    } 

}

这是为自定义按钮创建的javascript代码,其中设置>自定义>帐户>按钮和链接

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
sforce.apex.execute("AccountPDFGenerator","generateInvoicePDF", {id:"{!Account.Id}"});
window.alert("Account Id is sent." );

这是html文件内容

<html><head><meta http-equiv=content-type content=text/html;charset=iso-8859-9></meta></head><body><p>öçşğüıÖÇŞĞÜİ</p></body></html>
于 2012-12-10T08:02:47.550 回答
0

这可能是Blob.toPDF您应该向 Salesforce 报告的方法的限制。

我能想出的最接近的解决方案是escapeHtml4()在每个字符串上使用该方法,但这仅涵盖字符实体的子集。它将您的示例字符串转换'abcşidça''abcşid&ccedil;a'.

如果meta标签影响输出,您可以尝试使用 just 启动 HTML,<html><body>看看是否有帮助。

于 2012-12-06T17:55:39.330 回答