开发者

which Java / Groovy library to overlay text on an image

I am working on a web application (using Grails) which will generate a gif开发者_开发知识库t certificate. I'm thinking of a workflow like this:

  1. The user will pick a template which will be stored as an image.

  2. Then the text (name, date, amount etc) will be overlaid on the image to make the final certificate. There is a set of co-ordinates associated with each template which describes where to put each bit of text.

  3. There is a kind of 'live preview' in the browser which shows the user what the final certificate will look like.

  4. When the user is happy with the results, they download the certificate as a PDF and print it.

Can anyone recommend a library for Java (or Groovy) that will make it easy to do this? I'm not particularly worried about speed, as I suspect that the webapp will only be used by a few people at a time.

UPDATE: in the end I used the iText PDF library to overlay text on a PDF template using PDFStamper.


You can do this with the standard Java 2D graphics libraries - create a BufferedImage from the image, get its Graphics and use drawString() to put the text on top. Of course, the text would then be part of the bitmap in the resulting PDF, and not use the full printing resolution.


In addition to the answers above, I have come across the groovy library GraphicsBuilder and the Grails plugin j2D which are also potiential solutions.


You might consider using Batik to do this as SVG. Your image would be an <img> tag and your text would be one or more <text> tags. There's a converter (called FOP, I believe) which will get you PDF output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜