2016-09-28 60 views
0

我创建了一个动态的PDF与GSP,我想添加一个图像,但我不知道如何做到这一点因为简单地在gsp中使用<img src="${resource(dir: 'images/vip', file: 'heading.png')}"/>似乎没有工作。在创建电子邮件时,您在.sendMail中使用inline 'pic1', 'image/jpg', resourceLoader.getResource("/images/bawHeader3.png").getFile(),所以我想知道是否可以为pdf执行类似操作。这是我到目前为止:grails - 在控制器访问图像在pdf中使用

def downloadBooking() { 
    def result = Booking.findById(params.id) 
    renderPdf(template: "/pdf/booking/vipConfirmation", model : result) 
} 

上述工作正常,我只是不知道如何添加图像到它。另请告诉我如何访问gsp内的图像。

+0

? –

+0

不确定,我想我正在使用pdfRenderingService – PrintlnParams

+0

好吧,这意味着您使用“grails pdf render” –

回答

1

您需要将图像的字节码发送到“pdfRenderingService”。这里是下面的配置。

//convert image to bytecode and pass it to the padf rendring service. 
def imageBytes=grailsResourceLocator.findResourceForURI('/images/user.png').file.bytes 

将值传递给pdfrendering服务。

ByteArrayOutputStream reportBytes = pdfRenderingService.render(template: "/pdf/booking/vipConfirmation", model: [result: result, "imageBytes": imageBytes]) 

您使用 “Grails的PDF渲染” 访问图像模板

<div> <rendering:inlinePng bytes="${imageBytes}" class="header-img"/> </div> 
+0

Hi @L。 Grobler请试试这个,如果你有任何让我知道的? –

+0

@ L. Grobler是你的主题所解决的。 –

相关问题