io.github.cloudify.scala.spdf.WrappedPdf.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spdf_2.11 Show documentation
Show all versions of spdf_2.11 Show documentation
Create PDFs using plain old HTML+CSS. Uses wkhtmltopdf on the back-end which renders HTML using Webkit.
The newest version!
package io.github.cloudify.scala.spdf
import scala.sys.process.Process
class WrappedPdf(executable: Seq[String], config: PdfConfig) {
def run[A, B](sourceDocument: A, destinationDocument: B)(implicit sourceDocumentLike: SourceDocumentLike[A], destinationDocumentLike: DestinationDocumentLike[B]): Int = {
val commandLine = toCommandLine(sourceDocument, destinationDocument)
val process = Process(commandLine)
def source = sourceDocumentLike.sourceFrom(sourceDocument) _
def sink = destinationDocumentLike.sinkTo(destinationDocument) _
(sink compose source)(process).!
}
def toCommandLine[A: SourceDocumentLike, B: DestinationDocumentLike](source: A, destination: B): Seq[String] =
executable ++
PdfConfig.toParameters(config) ++
Seq(
"--quiet",
implicitly[SourceDocumentLike[A]].commandParameter(source),
implicitly[DestinationDocumentLike[B]].commandParameter(destination)
)
}
object WrappedPdf {
def apply(executable: Seq[String], config: PdfConfig): WrappedPdf = new WrappedPdf(executable, config)
}