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

Discussion in 'Java' started by Edward, Feb 3, 2006.

  1. Edward

    Edward Guest

    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

    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

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


    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):


    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) {
    ParsedURLDataProtocolHandler handler = new
    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

    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!


    Edward, Feb 3, 2006
    1. Advertisements

  2. Richard Wheeldon, Feb 3, 2006
    1. Advertisements

  3. Edward


    May 18, 2007
    Likes Received:
    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.

    DerekLittle, May 18, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.