apache-fop

apache fop embedded png is not rendering


i have trouble with embedding images in my pdf (it worked 2 years ago, but now it fails)

Dependencies are there:

    implementation("org.apache.xmlgraphics:fop:2.9")
    implementation("org.apache.xmlgraphics:xmlgraphics-commons:2.9")

the PNG file is also valid, but for some reason i still get

The file format is not supported. No ImagePreloader found for data:image/png;base64

The full config is here: https://github.com/Black-Forrest-Development/open-event/blob/development/src/main/resources/fop/fop.xconf

The template (which is preprocessed by velocity) is here https://github.com/Black-Forrest-Development/open-event/blob/development/src/main/resources/fop/event1.vm

And the usage is here

https://github.com/Black-Forrest-Development/open-event/blob/development/src/main/kotlin/de/sambalmueslie/openevent/core/logic/export/EventPdfExporter.kt

i have no idea whats wrong. I debugged a little and figured out, that even when the file has the correct PNG-Signature the PreloaderRawPNG fails, cause its input stream is pointing to the fop.xconf file which is of course no png file.

I debugged with that file: https://open.psm.church/assets/img/logo.png

It also fails if i embedd the base64 encoded png directly.

Any ideas?

Regards Oli


Solution

  • I found my mistake

    I called the public static FopFactory newInstance(final URI baseURI) instead of the public static FopFactory newInstance(File fopConf)

    after changing it to

        private val config = loader.getResource("classpath:fop/fop.xconf").getOrNull()!!
        private val fopFactory: FopFactory = FopFactory.newInstance(File(config.toURI()))
    
    

    it worked.