xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Li, Jing" <jing.li....@roche.com>
Subject RE: image loading callback
Date Tue, 12 Jul 2011 19:46:41 GMT
Jeremias,

Thank you so much for taking time to reply me and give me the excellent advices in such short
period of time. 

I think I will take your first approach and use ImageGraphics2D for nicer display. I read
your Barcode4J source code. I think the solution fits mine.

Thanks a million.

Jing
A Apache FOP newbie

-----Original Message-----
From: Jeremias Maerki [mailto:dev@jeremias-maerki.ch] 
Sent: Tuesday, July 12, 2011 3:09 PM
To: fop-users@xmlgraphics.apache.org
Subject: Re: image loading callback

Hi Jing

How you approach that depends a bit on what information you need to pass
from FO to your image generator. If you can fit everything in an URI
(fo:external-graphic), then you could do this:
- Subclass javax.xml.transform.Source and provide a BufferedImage
through it.
- Write a URI resolver that turns the URI into such an "BufferedImageSource".
- Then you'll need an ImagePreloader that works on that
BufferedImageSource.
- Finally, an ImageLoader will wrap the BufferedImage in an
ImageBuffered instance which FOP then can consume.

Details for the image loading framework are found here:
http://xmlgraphics.apache.org/commons/image-loader.html

I know that sounds quite complicated but at least this would be
something that could even be placed in XML Graphics Commons in case
someone wants to do something similar.

The easier approach is to just encode the BufferedImage into a PNG in
the URIResolver and return a StreamSource. That doesn't require messing
with the image loader framework but you also lose performance because
the PNG has to be encoded and re-parsed immediately after that.

If, OTOH, you have some XML content that you turn into a BufferedImage 
(fo:instream-foreign-object), an ImageConverter (also from the image
loading frameworker) and again an ImagePreloader should do the trick to
convert your XML-Format to an ImageGraphics2D or ImageBuffered. The
ImagePreloader is mostly needed to establish the natural size of the
image.

A note on ImageGraphics2D: if you actually paint the image using
Java2D/Graphics2D, you might want to consider not directly creating a
BufferedImage but an ImageGraphics2D because that would allow you to
retain a vector graphic image which can look much nicer in a PDF than a
bitmap image. The image loader framework automatically converts a Java2D
image to a bitmap if the consumer doesn't support vector graphics.

Examples for plug-ins for the image loading framework can be found in
the following places: Barcode4J, JEuclid and my PDF plug-in for FOP.

HTH

On 12.07.2011 20:03:06 Li, Jing wrote:
> Dear All,
> 
> Recently I am searching an answer about the callback mechanism when loading images.
> 
> I am working on a project that creates a report as PDF format, using
> xml + xml-fo. I am thinking Apache FOP might be a way to go. But I have hard
> time to find the callback mechanism.  In my report, I have a lot of
> charts and images that created as BufferedImage on the fly that need to
> put in the pdf file. They are not static image files, read via io. 
> Ideally I can wrote customize image reader that I can plug-in to FOP,
> and use customize URIResovler to invoke it?
> 
> Anyone can help me point to the right direction?
> 
> Thank you in advance.
> 
> Jing




Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Mime
View raw message