asciidoctor / asciidoctorj

:coffee: Java bindings for Asciidoctor. Asciidoctor on the JVM!
http://asciidoctor.org
Apache License 2.0
624 stars 173 forks source link

how to use asciidoctorj api add style,like font size #1025

Open mahaairong opened 3 years ago

mahaairong commented 3 years ago

Hello!Thank you for reading! I successfully converted ADOC to PDF with asciidoctorj api , but I'm very upset how to add some style? image jdk1.8,asciidoctor v2.0.14 asciidoctorj v2.4.2 Please help me! Thank again for your reading and support.

abelsromero commented 3 years ago

To create attributes, use the AttributesBuilder, then inject them into the OptionsBuilder with attributesmethod. And if you are passing paths, pass the absolute path as a string.

mahaairong commented 3 years ago

AttributesBuilder

I used the method you provided, and I have two questions. First, I can't get the Builder.The prompt message is "Cannot resolve method 'builder()".I import org.asciidoctor.*. The other one, I added the font, how do I put the theme in? like XXX.yml. image image image Thank again for your reading and support.

mojavelinux commented 3 years ago

To learn how to add fonts for your PDF theme, please refer to this document: https://github.com/asciidoctor/asciidoctor-pdf/blob/v1.5.x/docs/theming-guide.adoc#fonts

abelsromero commented 3 years ago

First, I can't get the Builder.The prompt message is "Cannot resolve method 'builder()".I import org.asciidoctor.*.

I see the docs update from main branch and we made some changes not yet released. Use these:

        Asciidoctor asciidoctor = Asciidoctor.Factory.create();

        Attributes attributes = AttributesBuilder.attributes()
            .attribute("pdf-theme", "path_to_theme")
            .attribute("pdf-fontsdir", "path_to_fonts")
            .tableOfContents(Placement.LEFT)
            .icons("font")
            .get();

        Options options = OptionsBuilder.options()
            .backend("pdf")
            .attributes(attributes)
            .get();

        asciidoctor.convertFile(file("sample.adoc"), options);  

Not sure what is your use case, but you may be interested in having a look at the maven example to build PDF with CN fonts https://github.com/asciidoctor/asciidoctor-maven-examples/tree/main/asciidoctor-pdf-cjk-example. If you want to build docs in some automated way, maybe that's also al option and you don't need to deal with Asciidoctorj internals.

mahaairong commented 3 years ago

First, I can't get the Builder.The prompt message is "Cannot resolve method 'builder()".I import org.asciidoctor.*.

I see the docs update from main branch and we made some changes not yet released. Use these:

        Asciidoctor asciidoctor = Asciidoctor.Factory.create();

        Attributes attributes = AttributesBuilder.attributes()
            .attribute("pdf-theme", "path_to_theme")
            .attribute("pdf-fontsdir", "path_to_fonts")
            .tableOfContents(Placement.LEFT)
            .icons("font")
            .get();

        Options options = OptionsBuilder.options()
            .backend("pdf")
            .attributes(attributes)
            .get();

        asciidoctor.convertFile(file("sample.adoc"), options);  

Not sure what is your use case, but you may be interested in having a look at the maven example to build PDF with CN fonts https://github.com/asciidoctor/asciidoctor-maven-examples/tree/main/asciidoctor-pdf-cjk-example. If you want to build docs in some automated way, maybe that's also al option and you don't need to deal with Asciidoctorj internals.

Sorry to be late with the new one. I used this method and was happy to convert successfully, but there were formatting problems. image

When I use include, it generates a link, not a reference to its text. image image Could you please take a look at it again!Thank you!