tea-school
tea-school copied to clipboard
Not able to render image
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
- img.img-logo(src='./logo.png' alt='')
- img.img-logo(src='logo.png' alt='')
- img.img-logo(src='/logo.png' alt='')
- 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 ?
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.
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