Showing images in PDF embeded in a web app.

Sunrita Bagchi Basu <[email protected]>
Newsgroups gmane.text.xml.fop.user
Message-ID <CAOFXZSJJPAC-2tGshB=siFaYF-apyOJYAuy5tjZR4tKuhcWNgA@mail.gmail.com>
Hi,

I am struggling to show images and data in PDF within a web application.
I could make the stand alone work easily. But in web it fails to get the
images.

I have tried the following:

Approach 1: [Here i tried using the ServletContextURIResolver to resolve
the images]

URIResolver uriResolver = new ServletContextURIResolver(servletContext);
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg
= cfgBuilder.build(GeneratePDFWithFOP.class.getResourceAsStream("/fop.xconf"));
ResourceResolver resolver = new ResourceResolver() {
            public OutputStream getOutputStream (
                                                 URI uri)
                                                         throws IOException
{
                URL url = servletContext.getResource(uri.toASCIIString());
                return url.openConnection().getOutputStream();
            }

            public Resource getResource (
                                         URI uri)
                                                 throws IOException {
                return new
Resource(servletContext.getResourceAsStream(uri.toASCIIString()));
            }
        };
FopFactoryBuilder builder = new FopFactoryBuilder(new File(".").toURI(),
resolver).setConfiguration(cfg);
final FopFactory fopFactory = builder.build();

In the xsl for images I have put:

<fo:external-graphic content-height="0.32in" scaling="non-uniform"
content-width="0.30in" src="url(servletcontext: /arrow-pdf-header.png)" />

But this doesn't load the images.
SAX error show invalid URI for image. Though the same is accessible via
browser

Approach 2: [Here i used the Local path, so the images are coming through
but the data is not getting printed]

String appPath = servletContext.getRealPath("");
Configuration cfg = cfgBuilder.buildFromFile(new
File(appPath+"/WEB-INF/classes/fop.xconf"));
FopFactoryBuilder builder = new FopFactoryBuilder(new
File(appPath).toURI()).setConfiguration(cfg);
final FopFactory fopFactory = builder.build();

In the xsl for images i have put:
<fo:external-graphic scaling="non-uniform" content-height="0.40625in"
content-width="0.40625in" src="url(/arrow-pdf-header.png)" />

Though this one loads the images, the data fails to show up!. I also get a
few warning in the console such as table width was adjusted, and few fonts
were not found.

Thanks,
Sunrita
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.