Apache FOP to load images with data url in PDF using xsl-fo

Edward (4)

Usenet Archive
Joined
Jan 27, 2006
Messages
17
Reaction score
0
I am trying to use Apache FOP to load images with data url into a PDF using XSL-FO. My application has no trouble loading images when they are loaded from a file or from a servlet generated image using fo:external-graphic.

I have a requirement to generate these images without an external file or servlet embedded in xsl-fo but with a string of Base64 data passed as a parameter. I have not been able to get to this work. I have an application that a former co-worker wrote that was able to accomplish this and I have tried cloning their code but still cannot succeed in this.

I see in the other application there is a line of code (which I added to my application):

System.setProperty("java.protocol.handler.pkgs","org.apache.fop.util.protocols");

which I assume is used to tell FOP where to look for its protocols. The other application also has added in two classes in a similar package that looks like it was acquired from Apache (I added these classes as well, in the same package):

org.apache.fop.util.protocols.data/Handler.java
org.apache.fop.util.protocols.data/RFC2397URLConnection.java

Within Handler is a variable that I assume defines the data protocol:

public static final String PROTOCOL = "data";

and within RFC2397URLConnection is a class:

public void connect {
if (data != null) {
return;
}
ParsedURLDataProtocolHandler handler = new
ParsedURLDataProtocolHandler;
data = handler.parseURL(getURL.toString);
headerFields.put("content-type", data.contentType);
}

All well and good. But here is the rub, in my application this code never gets called, while in the application that I am trying to copy it does (verified by putting simple System.out.println's in the methods to see when they are called).

Thinking that perhaps the other application had different libraries, I deleted all of the common libraries from my application and added them into mine, using the same classpath as the other (and triple checked to make sure that fop.jar and batik.jar were the same). Also note that for testing purposes the image is a simple hard-coded Base64 string that I put in both applications to make sure that my problem was not related to the way that the data was generated.

Note also that the working code runs as a standalone Java program while my code is a servlet based web app running in WSAD and I have been doing this testing in WSAD 5.0.0.

In both the working and non-working apps the external-graphics are identical:

<fo:external-graphic
src="url('data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7')" height="3cm" width="3cm" />

Anybody have any idea what I am missing? Or can anyone point me to any good FOP resources/forums? I have been searching and have not been able to find any yet. I also cannot even find from where within http://xmlgraphics.apache.org/fop/ that my ex-colleague even got the org.apache.fop.util.protocols.data package or the java.protocol.handler.pkgs code. Please help!

Thanks.

Edward
 
Joined
May 18, 2007
Messages
1
Reaction score
0
Issue with FOP XSL FO to RTF document and base64 encoded images

Version 0.93 of FOP includes the patch as outlined below, allowing base64 encoded images to be translated automatically to the output. This works fine with PDF output, but when I attempt to use the same transform to an RTF document I get a null pointer exception in the setURL method call in org.apache.fop.render.rtf.RTFHandler.putGraphic method.

This appears to be because the originalURI property in the FOPImage.imageInfo object hasn't been set (and is still null) when the setURL method is trying to instantiate a URL object with it.

Is there any simple resolution to this issue, rather than patching the FOP lib code? I'm constrained to using RTF as the output and would greatly prefer to using the base64 encoded images in the data XML msg (rather than a redirecting to a servlet that would dig the image out of the session, say).

Any help greatly appreciated.

Thanks in advance.


Richard Wheeldon said:
Edward wrote:
> I am trying to use Apache FOP to load images with data url into a PDF
> using XSL-FO.


Either download the latest subversion snapshot or apply this patch:
http://issues.apache.org/bugzilla/attachment.cgi?id=17336

See the bug report for details:
http://issues.apache.org/bugzilla/show_bug.cgi?id=38135

If you have any problems with it, email me,

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top