
Facilitates PDF generation from HTML & CSS using Chromium or Google Chrome, supporting various input methods and customizable settings for encryption, metadata, page orientation, and size.
Easy PDF generation with HTML & CSS using Chromium or Google Chrome
build.gradle.kts:
dependencies {
implementation("io.fluidsonic.pdf:fluid-pdf:0.30.0")
}import io.fluidsonic.pdf.*
import java.nio.file.*
suspend fun main() {
// TODO Change the binary file path to your local Chromium or Google Chrome installation.
val sourceFile = Path.of("input.html").toAbsolutePath()
val destinationFile = Path.of("output.pdf").toAbsolutePath()
coroutineScope {
val service = PdfGeneratorService.chromiumLauncher(
path = Path.of("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
)
service.startIn(this)
try {
service.generate(PdfGenerationSource.HtmlFile(sourceFile))
.writeTo(destinationFile)
}
finally {
service.stop()
}
}
println("PDF has been generated at $destinationFile")
}PdfGeneratorService.chromiumLauncher() to launch a browser instance.PdfGeneratorService.devTools() to connect to an existing or a remote browser instance.service.startIn(CoroutineScope) and service.stop() to manage the service lifecycle.PdfGeneratorService.generate() to create any number of PDFs.PdfGenerator interface to hide service details, e.g. in dependency injection.service.generate(PdfGenerationSource.Html("<strong>Hello world!</strong>"))
.writeTo(PdfGenerationDestination.File(destinationFile))π‘ Relative paths in HTML & CSS won't resolve. Using <base href="https://github.com/fluidsonic/fluid-pdf/blob/master/β¦"> to specify the base path should help.
Paths in HTML & CSS only work with a Chromium instance on the same machine.
val sourceStream: InputStream = β¦
generator.generate(PdfGenerationSource.HtmlStream(sourceStream))
.writeTo(PdfGenerationDestination.File(destinationFile))π‘ Relative paths in HTML & CSS won't resolve. Using <base href="https://github.com/fluidsonic/fluid-pdf/blob/master/β¦"> to specify the base path should help.
Paths in HTML & CSS only work with a Chromium instance on the same machine.
service.generate(
source = PdfGenerationSource.Html("<strong>Hello world!</strong>"),
settings = PdfGenerationSettings.default.copy(
encryption = PdfEncryption(
ownerPassword = "secret",
permissions = PdfPermissions.none.copy(
contentExtractionAllowed = true,
contentExtractionForAccessibilityAllowed = true,
printQuality = PdfPermissions.PrintQuality.high,
),
),
includeBackgrounds = false,
metadata = PdfMetadata(
title = "My PDF"
),
pageMargins = PdfMargins.cm(top = 2.0, right = 2.0, bottom = 1.0, left = 2.0),
pageOrientation = PdfOrientation.landscape,
pageSize = PdfSize.A5,
preferCssPageSize = false
)
)
.writeTo(destinationFile)service.generate(PdfGenerationSource.Html("<strong>Hello world!</strong>"))
.writeTo(outputStream)π‘ Closing the output stream is the responsibility of the caller. It will not be closed automatically.
Contributions welcome π
com.github.kklisura.cdt..generate() works well with significant parallelism.Apache 2.0
Easy PDF generation with HTML & CSS using Chromium or Google Chrome
build.gradle.kts:
dependencies {
implementation("io.fluidsonic.pdf:fluid-pdf:0.30.0")
}import io.fluidsonic.pdf.*
import java.nio.file.*
suspend fun main() {
// TODO Change the binary file path to your local Chromium or Google Chrome installation.
val sourceFile = Path.of("input.html").toAbsolutePath()
val destinationFile = Path.of("output.pdf").toAbsolutePath()
coroutineScope {
val service = PdfGeneratorService.chromiumLauncher(
path = Path.of("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
)
service.startIn(this)
try {
service.generate(PdfGenerationSource.HtmlFile(sourceFile))
.writeTo(destinationFile)
}
finally {
service.stop()
}
}
println("PDF has been generated at $destinationFile")
}PdfGeneratorService.chromiumLauncher() to launch a browser instance.PdfGeneratorService.devTools() to connect to an existing or a remote browser instance.service.startIn(CoroutineScope) and service.stop() to manage the service lifecycle.PdfGeneratorService.generate() to create any number of PDFs.PdfGenerator interface to hide service details, e.g. in dependency injection.service.generate(PdfGenerationSource.Html("<strong>Hello world!</strong>"))
.writeTo(PdfGenerationDestination.File(destinationFile))π‘ Relative paths in HTML & CSS won't resolve. Using <base href="https://github.com/fluidsonic/fluid-pdf/blob/master/β¦"> to specify the base path should help.
Paths in HTML & CSS only work with a Chromium instance on the same machine.
val sourceStream: InputStream = β¦
generator.generate(PdfGenerationSource.HtmlStream(sourceStream))
.writeTo(PdfGenerationDestination.File(destinationFile))π‘ Relative paths in HTML & CSS won't resolve. Using <base href="https://github.com/fluidsonic/fluid-pdf/blob/master/β¦"> to specify the base path should help.
Paths in HTML & CSS only work with a Chromium instance on the same machine.
service.generate(
source = PdfGenerationSource.Html("<strong>Hello world!</strong>"),
settings = PdfGenerationSettings.default.copy(
encryption = PdfEncryption(
ownerPassword = "secret",
permissions = PdfPermissions.none.copy(
contentExtractionAllowed = true,
contentExtractionForAccessibilityAllowed = true,
printQuality = PdfPermissions.PrintQuality.high,
),
),
includeBackgrounds = false,
metadata = PdfMetadata(
title = "My PDF"
),
pageMargins = PdfMargins.cm(top = 2.0, right = 2.0, bottom = 1.0, left = 2.0),
pageOrientation = PdfOrientation.landscape,
pageSize = PdfSize.A5,
preferCssPageSize = false
)
)
.writeTo(destinationFile)service.generate(PdfGenerationSource.Html("<strong>Hello world!</strong>"))
.writeTo(outputStream)π‘ Closing the output stream is the responsibility of the caller. It will not be closed automatically.
Contributions welcome π
com.github.kklisura.cdt..generate() works well with significant parallelism.Apache 2.0