Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6657525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:46:44+00:00 2026-05-26T01:46:44+00:00

UPDATE2: I got it working completely now! Scroll way down to find out how…

  • 0

UPDATE2: I got it working completely now! Scroll way down to find out how…
UPDATE: I got it working! Well… partially. Scroll down for the answer…

I’m trying to get my FO file to show an external image upon transforming it to PDF (or RTF for that matter, but I’m not sure whether RTFs are even capable of displaying images (they are)) with FOP, but I can’t seem to get it working. (The question asked here is different than mine.)

I am using IKVM 0.46.0.1 and have compiled a FOP 1.0 dll to put in .NET; this code worked fine when I didn’t try to add images:

private void convertFoByMimetype(java.io.File fo, java.io.File outfile, string mimetype)
{
    OutputStream output = null;

    try
    {
        FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
        // configure foUserAgent as desired

        // Setup outputput stream.  Note: Using BufferedOutputStream
        // for performance reasons (helpful with FileOutputStreams).
        output = new FileOutputStream(outfile);
        output = new BufferedOutputStream(output);

        // Construct fop with desired output format
        Fop fop = fopFactory.newFop(mimetype, foUserAgent, output);

        // Setup JAXP using identity transformer
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer(); // identity transformer

        // Setup input stream
        Source src = new StreamSource(fo);

        // Resulting SAX events (the generated FO) must be piped through to FOP
        Result res = new SAXResult(fop.getDefaultHandler());

        // Start XSLT transformation and FOP processing
        transformer.transform(src, res);
    }
    catch (Exception ex)
    ...
}

However, when I (or rather a DocBook2FO transformation) added the following code:

<fo:external-graphic src="url(images/interface.png)" width="auto" height="auto" content-width="auto" content-height="auto" content-type="content-type:image/png"></fo:external-graphic>

into the FO file, the image did not show. I read through a bit of the FAQ on Apache’s site, which says:

3.3. Why is my graphic not rendered?

Most commonly, the external file is not being found by FOP. Check the
following:

Empty or wrong baseDir setting.

Spelling errors in the file name (including using the wrong case).

…

Other options did not seem to be my case (mainly for the reason below – “The Weird Part”). I tried this:

...
try
{
    fopFactory.setBaseURL(fo.getParent());
    FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
    foUserAgent.setBaseURL(fo.getParent());
    FOURIResolver fourir = fopFactory.getFOURIResolver();
    foUserAgent.setURIResolver(fourir);
    // configure foUserAgent as desired
...

with no avail.

The Weird Part

When I use the command-line implementation of FOP, it works fine and displays my image with no problem. (I don’t want to go the run-command-line-from-program route, because I don’t want to force the users to install Java AND the .NET framework when they want to use my program.)
The png file is generated from GDI+ from within my application (using Bitmap.Save). I also tried different png files, but none of them worked for me.
Is there anything I might be missing?

Thanks a bunch for getting this far

UPDATE and possible answer

So I might have figured out why it didn’t work. I put some time into studying the code (before I basically just copypasted it without thinking about it much). The problem is indeed in the wrong basedir setting.

The key is in this chunk of code:

    // Setup JAXP using identity transformer
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(); // identity transformer

    // Setup input stream
    Source src = new StreamSource(fo);

    // Resulting SAX events (the generated FO) must be piped through to FOP
    Result res = new SAXResult(fop.getDefaultHandler());

    // Start XSLT transformation and FOP processing
    transformer.transform(src, res);

What happens here is an identity transformation, which routes its own result into an instance of FOP I’ve created before. This effectively changes the basedir of the routed FO into that of the application’s executable. I have yet to figure out how to do this without a transformation and route my input directly into FOP, but for the moment I worked around this by copying my images into the executable’s directory.

Which is where another problem came in. Now whenever I try to execute the code, I get an exception at the line that says transformer.transform(src, res);, which confuses the pants out of me, because it doesn’t say anything. The ExceptionHelper says:

java.lang.ExceptionInInitializerError was caught

and there is no inner exception or exception message. I know this is hard to debug just from what I wrote, but I’m hoping there might be an easy fix.

Also, this e-mail seems vaguely related but there is no answer to it.

UPDATE2

Finally, after a few sleepless nights, I managed to get it working with one of the simplest ways possible.

I updated IKVM, compiled fop with the new version and replaced the IKVM references with the new dlls. The error no longer occurs and my image renders fine.

I hope this helps someone someday

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:46:44+00:00Added an answer on May 26, 2026 at 1:46 am

    Here’s a post not to leave the question unanswered, see “Update 1” and “Update 2” in the original post for the solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: Solved, with code I got it working, see my answer below for the
Update: We are still using XP at work and I got my solution working,
I've started working with ASP.net AJAX (finally ☺). and I've got an update panel
UPDATE2: I think I got it now: <?php /* * @name Lawler's algorithm PHP
I've got a .NET 3.5 Application that was working well. The installation was also
I got this error when trying to update an image. It was a cross-thread
I've got an ASP.NET app using NHibernate to transactionally update a few tables upon
Update 3 : Never mind. I kinda got what I was looking for. The
I've got about 25 tables that I'd like to update with random data that's
I've got the following type of SQL: UPDATE photo AS f LEFT JOIN car

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.