Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto detect xvfb-run and will use it together with wkhtmltopdf if exists #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.13
sbt.version=1.1.6
21 changes: 13 additions & 8 deletions src/main/scala/io/github/cloudify/scala.spdf/Pdf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ class Pdf(executablePath: String, config: PdfConfig) {
/**
* Generates the command line needed to execute `wkhtmltopdf`
*/
private def toCommandLine[A: SourceDocumentLike, B: DestinationDocumentLike](source: A, destination: B): Seq[String] =
Seq(executablePath) ++
PdfConfig.toParameters(config) ++
Seq(
"--quiet",
implicitly[SourceDocumentLike[A]].commandParameter(source),
implicitly[DestinationDocumentLike[B]].commandParameter(destination)
)
private def toCommandLine[A: SourceDocumentLike, B: DestinationDocumentLike](source: A, destination: B): Seq[String] = {
val XVFB = "xvfb-run"
val execPath = PdfConfig.findExecutablePath(XVFB) match {
case Some(xvfbPath) if xvfbPath.contains(XVFB) => Seq(xvfbPath, "--", executablePath)
case _ => Seq(executablePath)
}

execPath ++ PdfConfig.toParameters(config) ++ Seq(
"--quiet",
implicitly[SourceDocumentLike[A]].commandParameter(source),
implicitly[DestinationDocumentLike[B]].commandParameter(destination)
)
}

/**
* Check whether the executable is actually executable, if it isn't
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/io/github/cloudify/scala.spdf/PdfConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,11 @@ object PdfConfig {
* Attempts to find the `wkhtmltopdf` executable in the system path.
* @return
*/
def findExecutable: Option[String] = try {
def findExecutable: Option[String] = findExecutablePath("wkhtmltopdf")

def findExecutablePath(exec: String): Option[String] = try {
val os = System.getProperty("os.name").toLowerCase
val cmd = if(os.contains("windows")) "where wkhtmltopdf" else "which wkhtmltopdf"
val cmd = if(os.contains("windows")) s"where $exec" else s"which $exec"

Option(cmd.!!.trim).filter(_.nonEmpty)
} catch {
Expand Down