Simple and highly customizable markdown to PDF conversion library
Note: Version 0.2.x has been released! Check out the changelog to see what's new!
The repository is hosted on Maven Central. You can add it to your project using the following code based on your build tool:
<dependency>
<groupId>com.github.woojiahao</groupId>
<artifactId>kMD2PDF</artifactId>
<version>0.2.2</version>
</dependency>
implementation 'com.github.woojiahao:kMD2PDF:0.2.2'
If you encounter errors with loading the library, visit the troubleshooting guide here.
All examples are taken from the examples repository.
val document
get() = MarkdownDocument("resources/markdown-all-in-one.md")
Example here.
fun main() {
val converter = markdownConverter {
document(document)
}
converter.convert()
}
Example here.
fun main() {
val converter = markdownConverter {
document(document)
targetLocation("${System.getProperty("user.home")}/Desktop/exported.pdf")
}
converter.convert()
}
Example here.
fun main() {
val converter = markdownConverter {
document(document)
}
val conversionResult = converter.convert()
conversionResult.success {
if (Desktop.isDesktopSupported()) Desktop.getDesktop().open(it)
}
}
Example here.
fun main() {
val converter = markdownConverter {
document(document)
}
val conversionStatus = converter.convert()
conversionStatus.failure {
if (it is FileNotFoundException) println("File is currently already open")
}
}
Example here.
More on this subject can be found on the documentation site here.
fun main() {
val converter = markdownConverter {
document(document)
settings {
fontSize = 16.0.px
font = FontFamily("Roboto", "Lato")
monospaceFont = FontFamily("Fira Code")
}
style {
p {
textColor = c("455A64")
}
ul {
listStyleType = SQUARE
}
selector("tr:nth-child(even)") {
"background-color" to "#f2f2f2"
}
}
}
converter.convert()
}
Example here.
More on the subject here.
fun main() {
val converter = markdownConverter {
document(document)
conversionTarget(MarkdownConverter.ConversionTarget.HTML)
}
converter.convert()
}