Images not reproduced when converting a Blob from HTML to PDF

后端 未结 1 1705
终归单人心
终归单人心 2021-01-06 09:13

I want to convert HTML emails into a PDF. I have written the following piece of code.

      var txt = msgs[i].getBody();
      /* We need two blob conversion         


        
相关标签:
1条回答
  • 2021-01-06 09:40

    Interesting problem. Makes sense as to why this doesn't work - PDF conversion doesn't bother "rendering" the HTML to go fetch the image src.

    I did a quick test and confirmed that Data URI's (inline images without requiring a separate HTTP call) worked with images.

    So, one hacky solution could be go fetch the images and then convert them to Data URI. This has a few downsides - hard to find these images (regex would be fragile or not comprehensive), lots of UrlFetch calls (even with some caching, most automated email senders add trackers so that you end up re-fetching the same image) and slow.

    Convert -

    <img src="http://images.myserver.com/myimage.png..."/>

    To (you can check the content type dynamically as well)-

    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhE..."/>

    0 讨论(0)
提交回复
热议问题