java - unable to render image in pdf :grails -


below code-

    applicationtaglib applicationtaglib = new applicationtaglib()     string html = applicationtaglib.include(controller: 'survey', action: 'pdf', params: [id: id])     html = html.replaceall('&', '&')     html = html.replaceall('&#', '&#')     html = html.replaceall(' ', ' ')      bytearrayoutputstream baos = new bytearrayoutputstream();     string baseurl = "http://localhost:8080/"     itextrenderer renderer = new itextrenderer();     renderer.setdocumentfromstring(content);     renderer.layout();     renderer.createpdf(baos);     byte[] data = baos.tobytearray();      response.setheader("content-disposition", "attachment;filename=report.pdf")     response.setcontenttype("application/pdf")     outputstream out = response.getoutputstream();     out.write(data);     out.flush();     out.close() 

in pdf action of survey contrller-

render(view: 'download') 

download.gsp

<g:img dir="assets/common" file="pointer.jpg"/> <img src="assets/common/pin.png"/> 

pdf getting have data except these image

note-while hitting direct pdf action of survey contrller renderring image fine.[localhost:8080/survey/pdf]

when generating pdf relative path/source not work static resources. have provide absolute path/source them.

you should not hard code baseurl. can inject grailslinkgenerator bean baseurl available @ grailslinkgenerator.serverbaseurl.

so can baseurl in controller through grailslinkgenerator , pass through model view. img tag can following

    <img src="${baseurl}/assets/common/pin.png"/> 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -