How to add image to html string variable that will later generate a PDF?

@manoelpereiraeng has asked:

Is there a way to add an image to an html string variable that will later generate a PDF? Ps.: I tried adding svg inline and it didn’t work.

@vinicius.belnuovo Do you know how to help Manoel here?

Do you have an example of the code you are using to generate the PDF? I’d think the SVG would work fine, as any other html should.

You can try using a public image from your existing website to test quickly. Also, you could use a url field from a record or use any variable in your low low code.

@manoelpereiraeng e @marcos.figueiredo

A melhor opção é incluir ela na base 64 dentro do código.
Abaixo um exemplo de como pegar uma imagem de uma coluna do tipo image, converter para base 64 e colocar no html.

$myTable = Jestor.loadData(‘mytab’, [‘where’ => [‘id_mytab’ => 1]])[0];
$image = base64_encode(Jestor.getContentFile($myTable[“my_image”]));

< img width=‘128px’ src=‘data:image/png;base64,".$image."’>

Espero que tenha te auxiliado.

The best option is put the image in base 64 format in your html code.
Follow below an example how to convert an image from image column to base64 text and use in html.

$myTable = Jestor.loadData(‘mytab’, [‘where’ => [‘id_mytab’ => 1]])[0];
$image = base64_encode(Jestor.getContentFile($myTable[“my_image”]));

< img width=‘128px’ src=‘data:image/png;base64,".$image."’>

I hope this can be helpful for you.

We don’t need it to be dynamic (from a record).
We just want to add a static image either from a url or a downloaded one (svg, jpeg or png).
I assume we can’t use ‘<img src="…"’/> 'cause it won’t render in a browser.

The code goes something like:
Part 1:


Part 2:

Later in the code, we use this $attchementFile into a Jestor.create(). It does work, just not with the image.

This should work with an SVG, and I would prefer everyone use more SVGs. Perhaps it is the code when trying to use it that has some issues with the various symbols such as the single and double quotation marks? That always trips me up.

Either way, one solution might be to perhaps use an external tool to convert you SVG into base64 entirely, and then decode it where you would like. PHP: base64_decode - Manual

Maybe an example using an SVG I converted into base64:

$qavi_img = "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItYWxlcnQtb2N0YWdvbiI+PHBvbHlnb24gcG9pbnRzPSI3Ljg2IDIgMTYuMTQgMiAyMiA3Ljg2IDIyIDE2LjE0IDE2LjE0IDIyIDcuODYgMjIgMiAxNi4xNCAyIDcuODYgNy44NiAyIj48L3BvbHlnb24+PGxpbmUgeDE9IjEyIiB5MT0iOCIgeDI9IjEyIiB5Mj0iMTIiPjwvbGluZT48bGluZSB4MT0iMTIiIHkxPSIxNiIgeDI9IjEyLjAxIiB5Mj0iMTYiPjwvbGluZT48L3N2Zz4="

$html_total = $html_pt1 . base64_decode($qavi_img) . $html_pt2 . $html_pt3;

You may need to move part of the pt1 to pt2 to make that work. I hope this helps! I’m still learning.