title: Parsing HTML String to Blob - Salesforce Apex
body: <p>I have a simple html code that looks like this:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;html&gt;
    &lt;body&gt;
      &lt;h3&gt;Test&lt;/h3&gt;
      &lt;img src="https://www.muycomputerpro.com/wp-content/uploads/2019/05/stack-overflow-brecha-seguridad.jpg" width="80" height="60" /&gt;
    &lt;/body&gt;
  &lt;/html&gt; </code></pre>
  </div>
  </div>
  </p>
  <p>This is a HTMLValue variable in an EmailTemplate record.
  Whit Apex I Want to try to get this Html value and save in a Content Version,
  but The parsing its no possible with the following code:</p>
  <pre><code>EmailTemplate  tmp = [SELECT Id, HtmlValue from EmailTemplate WHERE ID = '....' LIMIT 1];
  
  ContentVersion cVersion = new ContentVersion();
  cVersion.ContentLocation = 'S'; 
  cVersion.PathOnClient = fileName + '.pdf';
  cVersion.Title = fileName;
  cVersion.Origin = 'H';
  cVersion.OwnerId = caso.OwnerId;
  cVersion.VersionData = EncodingUtil.base64Decode( EncodingUtil.base64Encode(Blob.toPDF( tmp.HtmlValue )) );
  Insert cVersion;
  </code></pre>
  <p>Its Fail when html has an image (img) inserted; there is a way to parse an html value to blob whithout lose information?</p>
  <p>Thanks.</p>