[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: Re: [docbook-apps] Embedding DocBook â PDF transformation in a Java web app
This is an old problem that I looked into some time ago.
I use my ant4docbook project daily to generate pdfs, from docbook, markdown and docbook xsl1.xx.
Surely there are some interesting things to take in there.
The next step is to use xsltng + an html to pdf converter (chromium cef pdf?).
On 29 Jul 2023, at 13:48, Paul Hoadley <paulh@logicsquad.net> wrote:I'll put together a minimal example and see if you can put me in the right direction.To recap, I'm building a Java project that will encapsulate the DocBook stylesheets and some classes to do some transformations, all packaged as a JAR to become part of a larger web app. The project uses the standard Maven layout, and Saxon-HE 12.3. I've put the XSL in src/main/resources/xsl:paulh@elmo xsl % pwd/Users/paulh/Projects/Java/janus/src/main/resources/xslpaulh@elmo xsl % ls -ltotal 688drwxr-xr-x@ 48 paulh staff  1536 29 Jul 2020 docbook-xsl-1.79.2-rw-r--r--  1 paulh staff  16681 24 Jul 10:41 header-footer.xsl-rw-r--r--  1 paulh staff  7494 28 Jul 14:23 juno-driver.xsl-rw-r--r--  1 paulh staff  8689 24 Jul 14:33 table.xsl-rw-r--r--  1 paulh staff 307717 18 Jul 12:49 titlepage.xsljuno-driver.xsl is the top-level customisation stylesheet, and it imports the others:ÂÂ<xsl:import href="docbook-xsl-1.79.2/fo/docbook.xsl" /> <xsl:import href="titlepage.xsl" /> <xsl:import href="table.xsl" /> <xsl:import href="header-footer.xsl" />To be clear, addressing the XSL stylesheets as files on the filesystem works just fine. That is, this does exactly what it should:private Document transformDocument(Document document) throws TransformerException, FileNotFoundException {DOMResult result = new DOMResult();TransformerFactory factory = TransformerFactory.newInstance();factory.setURIResolver(new StandardURIResolver());InputStream is = new FileInputStream(new File("/Users/paulh/Projects/Java/janus/src/main/resources/xsl/juno-driver.xsl"));Source source = new StreamSource(is, "file:/Users/paulh/Projects/Java/janus/src/main/resources/xsl/juno-driver.xsl");Transformer transformer = factory.newTransformer(source);transformer.transform(new DOMSource(document), result);return (Document) result.getNode();}What I want to do, though, is reference the stylesheets as classpath resources.ÂStandardURIResolver claims to be able to handle the "classpath URI scheme", so I tried this:private Document transformDocument(Document document) throws TransformerException, FileNotFoundException {DOMResult result = new DOMResult();TransformerFactory factory = TransformerFactory.newInstance();factory.setURIResolver(new StandardURIResolver());InputStream is = XmlTest.class.getResourceAsStream("/xsl/juno-driver.xsl");Source source = new StreamSource(is, "classpath:/xsl/juno-driver.xsl");Transformer transformer = factory.newTransformer(source);transformer.transform(new DOMSource(document), result);return (Document) result.getNode();}Which results in:Error XTSE0165: I/O error reported by XML parser processing classpath:xsl/docbook-xsl-1.79.2/fo/docbook.xsl: unknown protocol: classpathjavax.xml.transform.TransformerConfigurationException: net.sf.saxon.s9api.SaxonApiException: I/O error reported by XML parser processing classpath:xsl/docbook-xsl-1.79.2/fo/docbook.xslat net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:158)at net.sf.saxon.jaxp.SaxonTransformerFactory.newTransformer(SaxonTransformerFactory.java:112)at net.logicsquad.janus.XmlTest.transformDocument(XmlTest.java:142)If StandardURIResolver can handle classpath URIs, have I just got the syntax or other usage wrong somewhere?
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]