Skip to content

Commit 48b4819

Browse files
authored
Merge pull request #10 from grahamburgsma/fix-threadpool
Fix threadpool usage and update README
2 parents bc8fc2a + 77d66d3 commit 48b4819

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# wkhtmltopdf
22

3-
![Swift](http://img.shields.io/badge/swift-4.2-brightgreen.svg)
4-
![Vapor](http://img.shields.io/badge/vapor-3.0-brightgreen.svg)
3+
![Swift](http://img.shields.io/badge/swift-5.2-brightgreen.svg)
4+
![Vapor](http://img.shields.io/badge/vapor-4.0-brightgreen.svg)
55
![Travis](https://travis-ci.org/vapor-community/wkhtmltopdf.svg?branch=master)
66

7-
Vapor 3 library for converting HTML (Leaf or otherwise) into PDF files using
7+
Vapor 4 library for converting HTML (Leaf or otherwise) into PDF files using
88
[wkhtmltopdf](http://wkhtmltopdf.org/).
99

1010
## Getting Started
1111

1212
Add the following in your `Package.swift` file
1313
```Swift
14-
.package(url: "https://github.com/vapor-community/wkhtmltopdf.git", from: "2.0.0"),
14+
.package(url: "https://github.com/vapor-community/wkhtmltopdf.git", from: "3.0.0"),
1515
```
1616

1717
## 📘 Overview
1818

1919
First, install [wkhtmltopdf](http://wkhtmltopdf.org/downloads.html). This
20-
library is tested on version 0.12.4. Specify the location of `wkhtmltopdf`
20+
library is tested on version 0.12.5. Specify the location of `wkhtmltopdf`
2121
in the `Document` initialiser. The default is `/usr/local/bin/wkhtmltopdf`.
2222
Run it to ensure it and any dependencies are installed correctly.
2323

@@ -49,14 +49,14 @@ func pdf(_ req: Request) -> Future<Response> {
4949
// Add the pages to the document
5050
document.pages = [page1] + pages
5151
// Render to a PDF
52-
let pdf = try document.generatePDF(on: req)
52+
let pdf = try document.generatePDF(eventLoop: req.eventLoop)
5353
// Now you can return the PDF as a response, if you want
5454
return pdf.map { data -> Response in
55-
let http = HTTPResponse(status: .ok,
56-
headers: HTTPHeaders([("Content-Type", "application/pdf")]),
57-
body: data)
58-
return Response(http: http,
59-
using: req)
55+
return HTTPResponse(
56+
status: .ok,
57+
headers: HTTPHeaders([("Content-Type", "application/pdf")]),
58+
body: .init(data: data)
59+
)
6060
}
6161
}
6262
}

Sources/wkhtmltopdf/Document+Generate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import NIO
44
extension Document {
55

66
public func generatePDF(on threadPool: NIOThreadPool = NIOThreadPool(numberOfThreads: 1), eventLoop: EventLoop) throws -> EventLoopFuture<Data> {
7+
threadPool.start()
78
return threadPool.runIfActive(eventLoop: eventLoop) {
89
let fileManager = FileManager.default
910

Tests/wkhtmltopdfTests/wkhtmltopdfTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class wkhtmltopdfTests: XCTestCase {
2424
let document = Document(margins: 15)
2525
let page1 = Page("<p>Page from direct HTML</p>")
2626
document.pages = [page1]
27-
let data = try document.generatePDF(on: eventLoop).wait()
27+
let data = try document.generatePDF(eventLoop: eventLoop).wait()
2828
// Cop-out test, just ensuring that the returned data is something
2929
XCTAssert(data.count > 50)
3030
// Visual test

0 commit comments

Comments
 (0)