So i have this task where i have to convert the image uploaded in Notes and Attachment object to PDF. For that i created a trigger(before insert) on Attachment object and used the below mentioned code,
I used the standard EncodingUtil to convert the image Body in the proper format,
I tried this code
attachmentObj.Body = blob.toPdf(attachmentObj.Body.toString());
But i get the error message "BLOB is not a valid UTF-8 string",
So after some research i also used tried this,
String encodeStringBody = EncodingUtil.base64Encode(attachmentObj.Body);
attachmentObj.Body = blob.toPdf(encodeStringBody);
But the attachment created have ineligible body. I cannot see anything when i 'view file' in the attachment object.
I expect the file to be converted to PDF but both the code i used have problems.
Please help me with this if anyone find solution to the problem.