Skip to content

Commit

Permalink
Merge pull request #6 from maciejtrybilo/master
Browse files Browse the repository at this point in the history
Allow specifying the launch path.
  • Loading branch information
bygri authored Aug 19, 2019
2 parents 454a8a1 + 71073ea commit 1245e48
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +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. Your binary should be installed at
`/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:
Expand Down
2 changes: 1 addition & 1 deletion Sources/wkhtmltopdf/Document+Generate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Sources/wkhtmltopdf/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}

0 comments on commit 1245e48

Please sign in to comment.