tea-school icon indicating copy to clipboard operation
tea-school copied to clipboard

Not able to render image

Open Yuvraj102 opened this issue 2 years ago • 2 comments

I do have a pug file which has an image tag, inside src i have specified address, i have tried suppling relative address as well as absolute address

here is my script code

async function createLR(createLrPdfDto): Promise<Buffer> {
  const teaSchoolOptions: GeneratePdfOptions = {
    // both of these pug and scss WORKS now in landscape mode
    styleOptions: {
      file: path.resolve(process.cwd(), "template-new.scss"),
    },
    htmlTemplatePath: path.resolve(process.cwd(), "template-new.pug"),
    htmlTemplateOptions: createLrPdfDto,
    pdfOptions: {

      path: "np4.pdf",
      format: "A4",
      printBackground: true,
      margin: { top: "1cm", bottom: "0cm" },
      landscape: true,
    },
    puppeteerOptions: { headless: true, args: ["--no-sandbox"] },
  };
  console.log("generating pdf");
  return await generatePdf(teaSchoolOptions);
}

template-new.pug

// Use !{var} to use unescaped conent
style(type="text/css") !{compiledStyle}
doctype html
html(lang='en')
  head
    meta(charset='UTF-8')
    meta(name='viewport' content='width=device-width, initial-scale=1.0')
    title LR-Format
    link(rel='stylesheet' href='style.css')
  body
        img.img-logo(src='./logo.png' alt='logo alternate ')

things i have tried in above case

  1. img.img-logo(src='./logo.png' alt='')
  2. img.img-logo(src='logo.png' alt='')
  3. img.img-logo(src='/logo.png' alt='')
  4. img.img-logo(src='Users/xyz/Desktop/logo.png' alt='')

each time i generate pdf it generates it with logo alternate which is the alternate text what is the right way to do it ?

Yuvraj102 avatar Nov 19 '22 08:11 Yuvraj102

Hi! Well, I'm not sure about the address here as I'm not sure where you're trying to run this (locally, or on the cloud?). Anyway - my suggestion (at least that's what I did), is to upload this to a cdn and put that address.

AmirTugi avatar Nov 19 '22 21:11 AmirTugi

uploading to a CDN did work, i was trying to run it locally, like i had the pug, scss and png in same folder and tried giving relative & absolute address it didnt pickup the image but either ways cdn did go well

Yuvraj102 avatar Nov 20 '22 13:11 Yuvraj102