AsciidoctorJ + Springboot + custom style/theme

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

AsciidoctorJ + Springboot + custom style/theme

Jeno
Hi guys,

Is there any way to set a custom css style that would be used during PDF generation? The app is a springboot app, provides an HTTP endpoint. POSTing data to this endpoint supposed to convert adoc template filled with data received in the request to PDF that would be sent in the HTTP response. The conversation works in memory, using String and ByteArrayOutputStream.

I tried to set the custom css file in the adoc template, like:
:stylesheet: theme.css

And I also tried to set the stylesheet "programatically", like:
        asciidoctor.convert(inStr, OptionsBuilder.options()
                .inPlace(true)
                .safe(SafeMode.UNSAFE)
                .attributes(AttributesBuilder.attributes()
                        .styleSheetName("theme.css")
                        .stylesDir("."))
                .backend("pdf").toStream(baos))

(as the stylesDir, I tried several settings - even the absolute path to the custom theme.css file, but it didn't work)

None of these worked - any ideas about the possible solution?

Thanks,
J.
Reply | Threaded
Open this post in threaded view
|

Re: AsciidoctorJ + Springboot + custom style/theme

Jeno
Okay, so the solution so far:

        val attributes = attributes()
        attributes.attribute("pdf-stylesdir", "/ABSOLUTE-PATH or RELATIVE-PATH")
        attributes.attribute("pdf-style", "base")

        val options = options()
                .backend("pdf")
                .toStream(baos)
                .safe(SafeMode.UNSAFE)
                .attributes(attributes).get()

        asciidoctor.convert(inStr, options)
Reply | Threaded
Open this post in threaded view
|

Re: AsciidoctorJ + Springboot + custom style/theme

abelsromero
Sorry for not answering.

Yes, your approach is the correct one. In case you want an example of a customized pdf, here is one https://github.com/asciidoctor/asciidoctor-maven-examples/tree/master/asciidoctor-pdf-with-theme-example.
And I assume you already found the docs https://github.com/asciidoctor/asciidoctor-pdf/blob/master/docs/theming-guide.adoc

If this for a rest service, you could send the style as an optional parameter so that clients can tune the end result.

Btw, just in case, my advice is to use POST multipart. You can send the different input files as different parts and even send other parameters (e.g. use a part to send a JSON sin attributes). A nice extra is that you can build a plain HTML form to invoke you service without any extra code.