現時点で PDF ファイルをどのように作成しているかはわかりませんが、1 つの方法はGrails Rendering Pluginを使用して PDF を生成することです。これにより、任意のビュー/テンプレートを使用して pdf ファイルを生成できます。
これらの PDF をバックエンドから送信するには、次のものが必要です。
ビュー:
<html>
<head>...</head>
<body>
<h1>Your PDF Content</h2>
<g:each in="${images}" var="image">
<img src="${createLink(action:'displayImage', id:image.id)}" alt="${image.name}"/>
</g:each>
</body>
</html>
コントローラーのアクション:
def displayImage = {
def image = Image.get(params.id)
response.setHeader("Content-disposition", "attachment; filename=${image.name}")
response.contentType = image?.mimeType
response.contentLength = image?.data.length
response.outputStream.write(attachment?.data)
}
マルチパート メールを ( mail プラグインを使用して) レンダリングされた pdf と共に送信する grails ジョブ:
def execute() {
def pdfBytes = pdfRenderingService.render(template: '/path/to/your/template', model: [images: yourImages]).toByteArray()
sendMail {
multipart true
to "yourmail"
subject "yoursubject"
body (view: "/path/to/your/mailview", model: yourModel) attachBytes "yourTitle.pdf", CH.config.grails.mime.types['pdf'], pdfBytes
}
}
コードは完全ではなく、基本を示しているだけです。
それが役立つことを願っています!