Asciidoctor Font

921 views Asked by At

How do I add the default font of Asciidoctor HTML to Asciidoctor pdf? Can I use the Webfont example: "@import url(https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700); " to my attributes file for the pdf format?

1

There are 1 answers

0
Kiroul On

The webfont example you gave works for HTML output, when the styling is done with CSS. For Asciidoctor-pdf, the styling is not done with CSS but through a YML file, here is the default Asciidoctor-pdf theme.

If you want the Asciidoctor HTML style in PDF you will need to check the Asciidoctor default CSS and try to recreate it for Asciidoctor-pdf. If you are only interested in the font you will probably need the Open Sans font, I did not find a way to include a web font so you will have to download it and create your custom theme.

The default font in Asciidoctor-pdf is Noto Serif, a simple way to change it to Open Sans would be to create a custom-theme.yml file like this:

extends: default
font:
  catalog:
    merge: true
    Open Sans:
      normal: OpenSans-Regular.ttf
      bold: OpenSans-Bold.ttf
      italic: OpenSans-Italic.ttf
      bold_italic: OpenSans-BoldItalic.ttf
base:
  font_family: Open Sans

More information about theming in the Asciidoctor PDF Theming Guide Organize your files like this:

yourFile.adoc
resources/themes/custom-theme.yml
resources/fonts/OpenSans-Regular.ttf
resources/fonts/OpenSans-Bold.ttf
resources/fonts/OpenSans-Italic.ttf
resources/fonts/OpenSans-BoldItalic.ttf

and set your custom theme as an attribute when calling asciidoctor-pdf like this:

asciidoctor-pdf -a pdf-theme=resources/themes/custom-theme.yml -a pdf-fontsdir="resources/fonts;GEM_FONTS_DIR" yourFile.adoc