gpt4 book ai didi

grails - 如何在TagLib中使用pngRenderingService.render获取图像标签而不是

转载 作者:行者123 更新时间:2023-12-02 14:44:28 24 4
gpt4 key购买 nike

我使用Taglib <g:mediaitem bean="${item}" />将媒体标签可折叠以显示项目类型

def item=attrs['bean']    
if(item?.type=='img')
{
out << '<img src="'+item?.src+'" />'
}else if(item?.type=='audio') {
out<< '<audio src="'+item?.src+'" />'
}
//..........

当我使用此标签呈现pdf时,出现了end-tag错误,我在解决方案上进行搜索,发现 renderPngrendering:inLinePng。我不能在TagLib中使用它。

我的问题是:在gsp中渲染将要渲染为pdf的图像时,如何在taglib中使用渲染png插件不会出错。
如果我可以使用pngRenderingService.render,应该传递什么参数?

最佳答案

首先,您必须以字节为单位转换图片,然后使用渲染插件标签lib来渲染图片,例如,

 File imageFile = new File(servletContext.getRealPath("images/imageName.png"))
out << rendering.inlinePng(bytes: imageFile.bytes)

编辑................................................ ....................

我正在一个项目中,我也在其中使用渲染插件下载PDF格式的内容,而我上面发布的上述代码对我而言很好。

贝娄是我完整的标签,用于以PDF呈现图像。
class ComJftTagLib {
static final namespace = 'jft'

def image = { attrs ->
String dir = attrs.remove('dir')
String file = attrs.remove('file')
File imageFile = new File(servletContext.getRealPath("/${dir}/${file}"))
out << rendering.inlineGif(bytes: imageFile.bytes)
}
}

我的图像放置在图像/文件夹中。

编辑................................................ ....................
out << '<img src="data:'
out << 'image/png'
out << ';base64,'
out << new String(new Base64().encode(imageFile.bytes), "UTF-8")
out << '" />'

关于grails - 如何在TagLib中使用pngRenderingService.render获取图像标签而不是<img>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18060208/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com