From a6b31d4d98ca8a9673c76d5dd7e11b606858f978 Mon Sep 17 00:00:00 2001 From: Maciej Trybilo Date: Thu, 15 Aug 2019 17:05:50 +0200 Subject: [PATCH 1/2] Allow specifying the launch path. --- README.md | 3 +-- Sources/wkhtmltopdf/Document+Generate.swift | 2 +- Sources/wkhtmltopdf/Document.swift | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2dc842f..53f3402 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,7 @@ Add the following in your `Package.swift` file ## 📘 Overview First, install [wkhtmltopdf](http://wkhtmltopdf.org/downloads.html). This -library is tested on version 0.12.4. Your binary should be installed at -`/usr/local/bin/wkhtmltopdf`; run it to ensure it and any dependencies are +library is tested on version 0.12.4. Specify the location of `wkhtmltopdf` in the `Document` initialiser. The default is `/usr/local/bin/wkhtmltopdf`. Run it to ensure it and any dependencies are installed correctly. To create a PDF, create and configure a `Document`, add one or more `Page`s, diff --git a/Sources/wkhtmltopdf/Document+Generate.swift b/Sources/wkhtmltopdf/Document+Generate.swift index bdea7d6..e878455 100644 --- a/Sources/wkhtmltopdf/Document+Generate.swift +++ b/Sources/wkhtmltopdf/Document+Generate.swift @@ -36,7 +36,7 @@ extension Document { // Call wkhtmltopdf and retrieve the result data let wk = Process() let stdout = Pipe() - wk.launchPath = "/usr/local/bin/wkhtmltopdf" + wk.launchPath = self.launchPath wk.arguments = wkArgs wk.arguments?.append("-") // output to stdout wk.standardOutput = stdout diff --git a/Sources/wkhtmltopdf/Document.swift b/Sources/wkhtmltopdf/Document.swift index af4c7b3..6862ece 100644 --- a/Sources/wkhtmltopdf/Document.swift +++ b/Sources/wkhtmltopdf/Document.swift @@ -5,18 +5,20 @@ public class Document { let rightMargin: Int let bottomMargin: Int let leftMargin: Int + let launchPath: String let paperSize: String public var pages: [Page] = [] - public init(size: String = "A4", zoom: String? = nil, margins all: Int? = nil, top: Int? = nil, right: Int? = nil, bottom: Int? = nil, left: Int? = nil) { + public init(size: String = "A4", zoom: String? = nil, margins all: Int? = nil, top: Int? = nil, right: Int? = nil, bottom: Int? = nil, left: Int? = nil, path: String = "/usr/local/bin/wkhtmltopdf") { self.zoom = zoom ?? "1.3" paperSize = size topMargin = all ?? top ?? 20 rightMargin = all ?? right ?? 20 bottomMargin = all ?? bottom ?? 20 leftMargin = all ?? left ?? 20 + launchPath = path } } From 71073ea264146a31994aee66e4ba8c880387a74a Mon Sep 17 00:00:00 2001 From: Maciej Trybilo Date: Fri, 16 Aug 2019 09:44:37 +0200 Subject: [PATCH 2/2] Stick to 80 column lines in README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 53f3402..a209523 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,10 @@ Add the following in your `Package.swift` file ## 📘 Overview -First, install [wkhtmltopdf](http://wkhtmltopdf.org/downloads.html). This -library is tested on version 0.12.4. Specify the location of `wkhtmltopdf` in the `Document` initialiser. The default is `/usr/local/bin/wkhtmltopdf`. Run it to ensure it and any dependencies are -installed correctly. +First, install [wkhtmltopdf](http://wkhtmltopdf.org/downloads.html). This +library is tested on version 0.12.4. Specify the location of `wkhtmltopdf` +in the `Document` initialiser. The default is `/usr/local/bin/wkhtmltopdf`. +Run it to ensure it and any dependencies are installed correctly. To create a PDF, create and configure a `Document`, add one or more `Page`s, and then call `generatePDF(on: Request)`. Here is a full example: