You need to sign in to do that
Don't have an account?
Tejas DJ
Blob.toPDF() dosen't support Chinese characters
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)
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)
If solved mark it as solution.. So that it can help others
Thanks for the reply, I tried Blob.valueof(targetString) this dosen't work.
Also I am specifically using Blob.toPdf(targetString) method because I want to create a well formatted PDF, I.e If you wish to create a PDF with all the tables and images we need to use Blob.toPDF() method which can also accept HTML content as input parameter and create a well formatted PDF.
Thanks & Regards,
-Tejas
Can you please try creating a PDF document with the above code and can you please suggest any corrections required?
This issue has become very critical for me.
I have tried Blob.valueof but it is creating a corrupted pdf document for me.
Thanks
Tejas
Hope it may resolve your issue..
Hi @Tejas DJ - 6 years after and I'm facing this issue also.
Did you find a solution for it? (Blob.valueOf didnt work for me also).
take a look at this URL it may help
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_output_pdf_render_in_apex.htm