I want to convert Asciidoctor files into PDF files using Gradle and the AsciidoctorPdf plugin. To be able to customize the resulting PDF, I define a custom theme. As base font I use the EB-Garamond font from Google.
My theme references the default theme, which references the bundled Noto Serif font: https://github.com/asciidoctor/asciidoctor-pdf/blob/main/data/themes/default-theme.yml
The search path for the bundled fonts is provided by GEM_FONTS_DIR keyword:
Font paths can be absolute or relative. Absolute paths are used as is. Relative font paths are resolved from the font search path. You can also use the GEM_FONTS_DIR keyword to refer to the location of the bundled fonts.
https://docs.asciidoctor.org/pdf-converter/latest/theme/custom-font/#declare
I set the relative path to the directory containing the EB-Garamond font in the extension of AsciidoctorPdf :
tasks.asciidoctorPdf {
setFontsDirs(listOf("fonts"))
}
Now when I run the build, I get an error message:
No such file or directory - notoserif-regular-subset.ttf not found in <absolute-path>/play-books/fonts
Exception in thread "main" org.asciidoctor.gradle.remote.AsciidoctorRemoteExecutionException: Error running Asciidoctor whilst attempting to process <absolute-path>/cocinero.adoc using backend pdf
I suspect that by calling setFontsDirs, the search path for fonts is completely reset and thus the path to the bundled fonts is also lost.
How can I pass the path to my own font directory to AsciidoctorPdf without losing the path to the bundled fonts?
build.gradle.kts:
plugins {
id("org.asciidoctor.jvm.convert")
id("org.asciidoctor.jvm.pdf")
}
tasks.asciidoctorPdf {
dependsOn("asciidoctor")
setFontsDirs(listOf("fonts"))
setTheme("play-book")
}
pdfThemes {
local("play-book") {
themeDir = projectDir
}
}
tasks.build {
dependsOn("asciidoctor")
dependsOn("asciidoctorPdf")
}
settings.gradle.kts:
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
plugins {
val versions = object {
val asciidoctor = "3.3.2"
}
id("org.asciidoctor.jvm.convert") version versions.asciidoctor
id("org.asciidoctor.jvm.pdf") version versions.asciidoctor
}
}
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}
rootProject.name = "cartel-deutsch"
include("play-books")
play-book-theme.yml:
extends: default
font:
catalog:
merge: true
EBGaramond:
normal: EB_Garamond/static/EBGaramond-Regular.ttf
italic: EB_Garamond/static/EBGaramond-Italic.ttf
bold: EB_Garamond/static/EBGaramond-Bold.ttf
bold_italic: EB_Garamond/static/EBGaramond-BoldItalic.ttf
page:
size: A5
margin: [ 8mm, 8mm, 12mm, 8mm ]
base:
font-family: EBGaramond
heading:
font-family: Helvetica