function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hemant Gulati 4Hemant Gulati 4 

Unable to save a dynamic image in a PDF attachment

Hello All,

I am using a canvas HTML element (with other elements of form) in my VF page. Onclicking on submit button, i am trying to save what has been written on canvas by the user as an Image with the other data in the form in the PDF attachment to the record.
Here, i am getting an issue "common.apex.runtime.impl.ExecutionException: An error occurred while parsing the input string."

//Canvas image code (base64 image string)
 String imageScreen=string.valueOf(canvasImage);

Code for attachment:-
1.  Attachment attachmentFile  = new Attachment();
2.  attachmentFile.parentId = parentId;
3.  attachmentFile.Name =  'abc.pdf';
4.  attachmentFile.body =blob.toPdf('<HTML><BODY><div>Test File</div><br/><img src='+imageScreen+' /></BODY></HTML>');
5.  insert attachmentFile;

Error is  in line 4.

and if i'll give static path of an image stored in Document object , it won't generate an error.

I request you all to please help me in this.