Note that there are some explanatory texts on larger screens.

plurals
  1. POFOP: how to specify image src relative path?
    primarykey
    data
    text
    <p>This is my first question here, i hope i'm doing it right. Sorry for my bad English in advance :)</p> <p>I am using JSF 2.0 (Eclipse IDE) and i'm trying to generate some PDF files using Apache FOP 1.0.</p> <p>I was able to make simple PDF files using instructions on <a href="http://xmlgraphics.apache.org/fop/index.html">Apache Fop site</a> , but i can't insert any image from my application folder. My folder structure is like this: In my application WebContent i have (among else) pdf_transform/xslt/transformFile.xsl, and pdf_transform/xslt/logo.jpg</p> <p>In transformFile.xsl i have </p> <pre><code>&lt;fo:block&gt;&lt;fo:external-graphic src="url('logo.jpg')"/&gt;&lt;/fo:block&gt; </code></pre> <p>but when i clik 'showPDF' button in my servlet, i get PDF file without image (everything else is there), and this messages in console:</p> <blockquote> <p>SEVERE: The Source that was returned from URI resolution didn't contain an InputStream for URI: logo.jpg Nov 18, 2010 5:16:49 PM org.apache.fop.events.LoggingEventListener processEvent SEVERE: Image not found. URI: logo.jpg. (No context info available)</p> </blockquote> <p>I tried to use 'logo.jpg' instead of url('logo.jpg'), putting image on various places inside WebContent folder and using different navigation("./logo.jpg") but it didnt work.</p> <p>It works fine if i set absolute path (for example "d:/fop/images/logo.jpg") but i need resurces whitin my application. </p> <p>While searching, i found that this is related to fopFactory.setURIResolver() and/or userAgent.setBaseURL(). Tried something with that, but didnt succeed.</p> <p>I am new to both JSF and FOP, and this image situation has been bothering me quite a while. Can someone help me with this, or at least direct me to some tutorial on "how to configure FOP for relative path use"?</p> <p>EDIT: I don't want any absolute paths and app should work independently of its location on computer (to be publishable). My search tells me it has something to do with configuring FOP, but i don't know how to do it :)</p> <p>Thanks in advance.</p> <p>P.S. This is method which is called to display PDF:</p> <pre><code>public void printExchangeRateList(ActionEvent event) { BufferedOutputStream output = null; FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); HttpServletResponse response = (HttpServletResponse) externalContext.getResponse(); String path = externalContext.getRealPath("/"); try { response.reset(); response.setHeader("Content-Type", "application/pdf"); output = new BufferedOutputStream(response.getOutputStream(), 10240); File xsltfile = new File(path+"/pdf_transform/xslt/transformFile.xsl"); FopFactory fopFactory = FopFactory.newInstance(); FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); try { Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, output); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(new StreamSource(xsltfile)); Source src = new DOMSource(makeXML()); // my method Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); } finally { if (output != null) output.close(); /*try { out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ } } catch (Exception e) { // TODO Auto-generated catch block } facesContext.responseComplete(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload