Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mahaairong opened this issue Apr 22, 2021 · 5 comments
Open

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

mahaairong opened this issue Apr 22, 2021 · 5 comments

Comments

@mahaairong
Copy link

mahaairong commented Apr 22, 2021

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
Copy link
Member

abelsromero commented Apr 22, 2021

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
Copy link
Author

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
Copy link
Member

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
Copy link
Member

abelsromero commented Apr 23, 2021

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
Copy link
Author

mahaairong commented Apr 26, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants