toondaey / nestjs-pdf

Nest js pdf generator
MIT License
83 stars 37 forks source link

How to load local images? #118

Closed dacxjo closed 7 months ago

dacxjo commented 3 years ago

I can't load images stored on the server, i have tried with the juice config webResources, relativeTo and reabaseRelativeTo, but it doesn't work..

Please help.

silvaignacio commented 2 years ago

I'm too, I wanna resolve this soon :(

dacxjo commented 2 years ago

Hola @silvaignacio , al parecer este repositorio quedó sin mantenimiento, lo que yo hice fue utilizar puppeteer con su método pdf (https://pptr.dev/#?product=Puppeteer&version=v13.2.0&show=api-pagepdfoptions) y handlebars para los templates, es un poco más de trabajo pero me funcionó perfectamente

silvaignacio commented 2 years ago

Eso estaba viendo, Pupetter, gracias por la acotación.

v4ssi404 commented 1 year ago

It works if you use base64 data image. Inspired by this: https://stackoverflow.com/questions/49938443/e-mail-doesnt-display-base64-image-using-handlebars-js

Example:

const options = {
      locals: {
        headerImgSrc: 'data:image/gif;base64,R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==',
      },
    };

return this.pdfService.toStream('templateName', options);
    <div class="header">
        <img src="{{headerImgSrc}}" >
    </div>