0

In my former question I have touched a broader problem of paths and their recognizing inside an eXist-db app.

At the moment, I am not able to get images in to PDF files. I have tried 2 installations of eXist (2.2 and 3RC) and many possible scenarios. Of course, I have tested those pictures are reachable through the browser.

In the source file, I have tried:

1. <graphic url="img/tealover.jpg"/>
2. <graphic url="/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg"/>
3. <graphic url="http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg"/>

4. <graphic url="url(img/tealover.jpg)"/>
5. <graphic url="url(/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg)"/>
6. <graphic url="url(http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg)"/>

7. <graphic url="url('img/tealover.jpg')"/>
8. <graphic url="url('/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg')"/>
9. <graphic url="url('http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg')"/>

As expected, samples 3, 6 and 9 work but only if I have them in a form of hardcoded links in the source. If I build up the links in my XSLT stylesheet, they are exactly the same in the FO file but there is nothing in the produced PDF.

Equivalents produced in FO file:

1. <fo:external-graphic src="img/tealover.jpg"/>
2. <fo:external-graphic src="/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg"/>
3. <fo:external-graphic src="http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg"/>

4. <fo:external-graphic src="url(img/tealover.jpg)"/>
5. <fo:external-graphic src="url(/db/apps/karolinum-apps/data/2015080/img/tealover.jpg)"/>
6. <fo:external-graphic src="url(http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg)"/>

7. <fo:external-graphic src="url('img/tealover.jpg')"/>
8. <fo:external-graphic src="url('/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg')"/>
9. <fo:external-graphic src="url('http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg')"/>

When I hard-code those links into the source, in the stylesheet works src="{@url}". When I use the short version of url everywhere (url="img/tealover.jpg"), in the attribute stylesheet I use

<xsl:value-of select="concat('http://46.28.111.241:8081/exist/rest', $imgPath, @url)"/>

or directly in the template

src="concat('http://46.28.111.241:8081/exist/rest', $imgPath, @url)"

The $imgPath variable is passed as a param from the application:

let $bookUri := base-uri($resource)
let $imgPath := replace($bookUri, '[^/]*?$', '')

With this, links 1, 4 and 7 should work, the rest is a mess. I can copy these links in eXide and they still work in the browser.

When I am testing, everything looks fine. In the PDF, there is still no picture. I guess there has to be a tiny detail I am missing now.

Honza Hejzl
  • 874
  • 8
  • 23
  • My suggestion is to look at the XSL-FO generated by your code, before you pass it to the FO processor. This will probably reveal a problem in the way you're constructing the URL. My FO resembles your method #9. – Joe Wicentowski Jan 27 '16 at 14:29
  • Yes, that is what I don’t understand to—I am testing that and see those links in the right pane. They are right, I have pasted them above (those samples are from the fo file. – Honza Hejzl Jan 27 '16 at 14:41
  • Right pane? I'm really having trouble understanding the exact situation you're trying to describe. – Joe Wicentowski Jan 27 '16 at 14:47
  • Another suggestion: getting a remote image to display in your PDF. Once that works, then try one stored in the database. Get one thing working, then move on - this is critical with XSL-FO, especially when generating it. – Joe Wicentowski Jan 27 '16 at 14:50
  • As I wrote, there is no problem when those links are hard-coded in the XML file (the link to the file stored in the DB simply works). [Personally, I am desperate because of some lags when eXist reflects my changes in the app, sometimes I have to restart it or re-save the file. This makes testing worse.] – Honza Hejzl Jan 27 '16 at 14:56
  • Sounds like you're hitting a couple of issues. I'd suggest joining exist-open mailing list and reporting things there. I seem to be the only one responding to you here. There you will find more people. – Joe Wicentowski Jan 27 '16 at 15:00
  • At the moment, the only one link working is the address: `` Nonsense, I know, but it is there. Ok, as for mailing list, I will try. – Honza Hejzl Jan 27 '16 at 15:00

1 Answers1

0

Got the solution. Unexpectedly, the best thing is to let urls as they are and focus on resolving of the root paths. With this the FOP processor is able to resolve relative paths and everything works as expected. In my case, I serve dynamic config file to the xslfo:render() function. The most important part is:

<hyphenation-base>{replace(request:get-url(), '/apps(.*?)$', '/rest')}/db/apps/karolinum-apps/modules/resources/hyph/</hyphenation-base>
<hyphenation-pattern lang="cs" country="CZ">cs</hyphenation-pattern>
<base>{replace(request:get-url(), '/apps(.*?)$', '/rest') || replace(base-uri($doc), '[^/]*?$', '')}</base>
<font-base>{replace(request:get-url(), '/apps(.*?)$', '/rest')}/db/apps/karolinum-apps/modules/resources/fonts/</font-base>

Now I am able to store everything inside the project and use relative paths in my source files. Hope this solution will survive next testing! If you knew more elegant way how to do this, please, let me know (ok, first of all I could put those clumsy path operations into variables).

Honza Hejzl
  • 874
  • 8
  • 23