• Tejas DJ
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hello Everyone,

I have observed a wired behavior with "Blob.toPDF(<string>)" Salesforce Apex API's , this method strips off Chinese characters and there is no option to set character encoding, please find below the sample code.


String targetString = 'Before - 測試中文字 - After';

Attachment attachmentPDF = new Attachment();
attachmentPDF.parentId = '<parent record id>';
attachmentPDF.Name = 'Test' + '.pdf';
attachmentPDF.ContentType = 'application/pdf; charset=UTF-8';
attachmentPDF.body = Blob.toPdf(targetString); //This creates the PDF content
insert attachmentPDF;

I have also tried encoding Chinese character content to UTF-8 but this displays all the encoded characters in PDF,

String targetString = 'Before - 測試中文字 - After';
String encodedString = EncodingUtil.urlEncode(targetString,'UTF-8');
System.debug('##encodedString:-'+encodedString);

Attachment attachmentPDF = new Attachment();
attachmentPDF.parentId = '<parent record id>';
attachmentPDF.Name = 'Test' + '.pdf';
attachmentPDF.ContentType = 'application/pdf; charset=UTF-8';
attachmentPDF.body = Blob.toPdf(encodedString); //This creates the PDF content
insert attachmentPDF;

Please help.

Thanks
-Tejas(+91 9663266726)
Hello Everyone,

I have observed a wired behavior with "Blob.toPDF(<string>)" Salesforce Apex API's , this method strips off Chinese characters and there is no option to set character encoding, please find below the sample code.


String targetString = 'Before - 測試中文字 - After';

Attachment attachmentPDF = new Attachment();
attachmentPDF.parentId = '<parent record id>';
attachmentPDF.Name = 'Test' + '.pdf';
attachmentPDF.ContentType = 'application/pdf; charset=UTF-8';
attachmentPDF.body = Blob.toPdf(targetString); //This creates the PDF content
insert attachmentPDF;

I have also tried encoding Chinese character content to UTF-8 but this displays all the encoded characters in PDF,

String targetString = 'Before - 測試中文字 - After';
String encodedString = EncodingUtil.urlEncode(targetString,'UTF-8');
System.debug('##encodedString:-'+encodedString);

Attachment attachmentPDF = new Attachment();
attachmentPDF.parentId = '<parent record id>';
attachmentPDF.Name = 'Test' + '.pdf';
attachmentPDF.ContentType = 'application/pdf; charset=UTF-8';
attachmentPDF.body = Blob.toPdf(encodedString); //This creates the PDF content
insert attachmentPDF;

Please help.

Thanks
-Tejas(+91 9663266726)
Hello Everyone,

I have observed a wired behavior with "Blob.toPDF(<string>)" Salesforce Apex API's , this method strips off Chinese characters and there is no option to set character encoding, please find below the sample code.


String targetString = 'Before - 測試中文字 - After';

Attachment attachmentPDF = new Attachment();
attachmentPDF.parentId = '<parent record id>';
attachmentPDF.Name = 'Test' + '.pdf';
attachmentPDF.ContentType = 'application/pdf; charset=UTF-8';
attachmentPDF.body = Blob.toPdf(targetString); //This creates the PDF content
insert attachmentPDF;

I have also tried encoding Chinese character content to UTF-8 but this displays all the encoded characters in PDF,

String targetString = 'Before - 測試中文字 - After';
String encodedString = EncodingUtil.urlEncode(targetString,'UTF-8');
System.debug('##encodedString:-'+encodedString);

Attachment attachmentPDF = new Attachment();
attachmentPDF.parentId = '<parent record id>';
attachmentPDF.Name = 'Test' + '.pdf';
attachmentPDF.ContentType = 'application/pdf; charset=UTF-8';
attachmentPDF.body = Blob.toPdf(encodedString); //This creates the PDF content
insert attachmentPDF;

Please help.

Thanks
-Tejas(+91 9663266726)