xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sunrita Bagchi Basu <sunrita....@gmail.com>
Subject Showing images in PDF embeded in a web app.
Date Sat, 12 Mar 2016 17:11:52 GMT
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

Mime
View raw message