Does anyone know how to get images to work using t...
# suitescript
u
Does anyone know how to get images to work using the
render
module's
xmlToPdf
? For context, I made a test suitelet that ideally renders a basic PDF page that loads an image with the
<img>
tag, with the entire xml template as a template literal in the script. The src for the
<img>
tag points to an expression, and I can't seem to get it to render an image in File Cabinet that's already been marked as "Available without Login" on and off multiple times. I've attached a snippet of the test script here. I'm still unsure if the issue is the url I'm plugging in, since I've tried plugging in the public url on the image's File Cabinet page, as well as swapping out the ampersand with the Freemarker-friendly
&
replacement. Any and all input would be very appreciated, thanks!
i'm replying the code block as I don't want to occupy too much space on the thread feed:
Copy code
var xml1 = `<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd"> <pdf> <head> </head>
<body padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
<table> <tr>
<td>Pic goes here: <div overflow="visible">
              <img src="${sig}" style="align:center; width: 100%; height: 100%;" />
</div></td>
</tr>
</table>
</body>
</pdf>
`;

try {
    var pdfFile = render.xmlToPdf({ xmlString: xml1 });
    context.response.writeFile(pdfFile);
} catch (e) {
    log.debug({
        title:"why",
        details:e
});
context.response.write(xml1);
b
the usual is not escaping the url
the usual recommendation is to escape it in the template
the secondary choice is to escape it in code
1
u
thanks @battk. I decided to create a separate xml file for the template to reduce script clutter and have the escaping done via script. I wasn't aware of the escaping topic until you linked me to it, so thanks for that as well.