grails renderpdf插件,它是如何工作的? [英] grails renderpdf plugin, how does it work?
问题描述
我试图用renderpdf grails插件渲染PDF,
,但它们的文档非常短。
我在gsp视图中做了一个按钮/ file
< button type =button> PDF Me!< / button>
和
ByteArrayOutputStream bytes = pdfRenderingService.render(template:/ pdfs / report,model:[data:data])
用于绑定图像
< rendering:inlinePng bytes =$ {imageBytes}class =some-class/>
模型数据为domainInstance,我如何将此按钮与此renderpdf连接?
可能是我应该更多地指定我的代码
$ pre $ def $ inv $ = .get(params.id)
def aa = vermittlungInstance.lieferungen.id
def lieferungInstance = Lieferung.get(aa)
def bb = lieferungInstance.packete.id // .id
def packetInstance = Packet.findAllByIdInList(bb)
if(!vermittlungInstance&!lieferungInstance){
flash.message = $ {message(code:'default.not.found.message',args:[message(code:'vermittlung.label',default:'Vermittlung'),params.id])}
redirect(action :list)
}
else {
if(vermittlungInstance.rechnungen.id!= null || vermittlungInstance.lieferungen.id!= null || lieferungInstance.packete.id!= null ){
def a = vermittlungInstance.rechnu ngen.id
def rechnungList = Rechnung.findById(a)
def b = vermittlungInstance.lieferungen.id
def lieferungList = Lieferung.findById(b)
def c = lieferungInstance.packete.id
// println c
def packetList = Packet.findAllByIdInList(c)// findById(c)
def d = packetInstance .artikel.id // id
def artikelList = Artikel.findAllByIdInList(d)// findById(d)
def e = lieferungInstance.adressen.id
def adresseList = Adresse .findById(e)
[vermittlungInstance:vermittlungInstance,
rechnungInstanceList:rechnungList,
lieferungInstanceList:lieferungList,
packetInstanceList:packetList,
artikelInstanceList:artikelList,
adresseInstanceList:adresseList
]
//System.out.println(c)
}
else {
def rechnungList = Rechnung。 all
def lieferungList = Lieferung.all
def packetList = Packet.all
def artikelList = Artikel.all
def adresseList = Adresse.all
[ vermittlungInstance:vermittlungInstance,
rechnungInstanceList:rechnungList,
lieferungInstanceList:lieferungList,
packetInstanceList:packetList,
artikelInstanceList:artikelList,
adresseInstanceList:adresseList
]
$ b}
}
这是我在一个控制器中的def,我试图把这个renderpdf放在很多地方,但它不会渲染页面,实际上我正在改变html中的一些值(浏览器),所以它应该rende r在html中。
控制器似乎是renderpdf的错误地方,但是没有.gsp的渲染函数。
感谢
添加一个新动作,生成发票的pdf版本,并将它们从您的视图中链接起来。
以下是您的链接:
< g:link action =downloadInvoiceid =$ {yourInvoiceID}>下载发票< / g:link>
在您的控制中添加以下内容:
renderPdf(template:'/ templates / pdf /发票',型号:[发票:发票],文件名:yourTitle)
}
您的发票模板是一个简单的gsp视图,您可以放置所有HTML(包括图片)和CSS:
< ;!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Strict // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
< html>
< head>
< title>发票< / title>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
< link rel =stylesheethref =$ {resource(dir:'css',file:'your.css')}/>
< / head>
< body>
< img src =$ {resource(dir:'images',file:'invoiceLogo.png')}/>
< h1>发票:$ {invoice.id}< / h1>
。
。
。
< / body>
< / html>
希望这个例子有所帮助!
i´m trying to render PDF with renderpdf grails plugin, but their documentation is very short.
i made a button in my gsp view/file
<button type="button">PDF Me!</button>
and
ByteArrayOutputStream bytes = pdfRenderingService.render(template: "/pdfs/report", model: [data: data])
in a view for binding images
<rendering:inlinePng bytes="${imageBytes}" class="some-class" />
model data is domainInstance and how do i connect the button with this renderpdf?
may be i should more specify my code
def invoice ={
def vermittlungInstance = Vermittlung.get(params.id)
def aa = vermittlungInstance.lieferungen.id
def lieferungInstance = Lieferung.get(aa)
def bb = lieferungInstance.packete.id // .id
def packetInstance = Packet.findAllByIdInList(bb)
if (!vermittlungInstance & !lieferungInstance) {
flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'vermittlung.label', default: 'Vermittlung'), params.id])}"
redirect(action: "list")
}
else {
if(vermittlungInstance.rechnungen.id!=null || vermittlungInstance.lieferungen.id!=null || lieferungInstance.packete.id!=null ){
def a = vermittlungInstance.rechnungen.id
def rechnungList = Rechnung.findById(a)
def b = vermittlungInstance.lieferungen.id
def lieferungList = Lieferung.findById(b)
def c = lieferungInstance.packete.id
//println c
def packetList = Packet.findAllByIdInList(c)//findById(c)
def d = packetInstance.artikel.id//id
def artikelList = Artikel.findAllByIdInList(d)//findById(d)
def e = lieferungInstance.adressen.id
def adresseList = Adresse.findById(e)
[vermittlungInstance: vermittlungInstance,
rechnungInstanceList:rechnungList,
lieferungInstanceList:lieferungList,
packetInstanceList: packetList,
artikelInstanceList: artikelList,
adresseInstanceList: adresseList
]
//System.out.println(c)
}
else{
def rechnungList = Rechnung.all
def lieferungList = Lieferung.all
def packetList = Packet.all
def artikelList = Artikel.all
def adresseList = Adresse.all
[vermittlungInstance: vermittlungInstance,
rechnungInstanceList:rechnungList,
lieferungInstanceList:lieferungList,
packetInstanceList: packetList,
artikelInstanceList: artikelList,
adresseInstanceList: adresseList
]
}
}
}
this is my def in a controller, i tried to put this renderpdf on many places, but it won't render the page, actually i am changing some values in html (browser), so it should render in html.
the controller seems to be a wrong place to renderpdf than, but there is no render function for .gsp
thanks
Add a new action which generates the pdf version of your invoice and link them from your view.
Here is your link:
<g:link action="downloadInvoice" id="${yourInvoiceID}">Download invoice</g:link>
In your controlle add following:
def downloadInvoice = {
def invoice = Invoice.get(params.id) //replace with your logic
renderPdf(template: '/templates/pdf/invoice', model: [invoice: invoice], filename: "yourTitle")
}
Your invoice template is a simple gsp view where you could place all your HTML (including images) and CSS:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Invoice</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="${resource(dir:'css',file:'your.css')}" />
</head>
<body>
<img src="${resource(dir:'images',file:'invoiceLogo.png')}" />
<h1>Invoice: ${invoice.id}</h1>
.
.
.
</body>
</html>
Hope that example helps!
这篇关于grails renderpdf插件,它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!