From 9d2ed0eee02dee62b93049a2032e8c7a8d893f7f Mon Sep 17 00:00:00 2001 From: Graham Burgsma Date: Mon, 11 May 2020 19:43:44 -0400 Subject: [PATCH 1/2] Start thread pool before using --- Sources/wkhtmltopdf/Document+Generate.swift | 1 + Tests/wkhtmltopdfTests/wkhtmltopdfTests.swift | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/wkhtmltopdf/Document+Generate.swift b/Sources/wkhtmltopdf/Document+Generate.swift index 25b60d7..cbbae26 100644 --- a/Sources/wkhtmltopdf/Document+Generate.swift +++ b/Sources/wkhtmltopdf/Document+Generate.swift @@ -4,6 +4,7 @@ import NIO extension Document { public func generatePDF(on threadPool: NIOThreadPool = NIOThreadPool(numberOfThreads: 1), eventLoop: EventLoop) throws -> EventLoopFuture { + threadPool.start() return threadPool.runIfActive(eventLoop: eventLoop) { let fileManager = FileManager.default diff --git a/Tests/wkhtmltopdfTests/wkhtmltopdfTests.swift b/Tests/wkhtmltopdfTests/wkhtmltopdfTests.swift index a3b5c07..261e9f6 100644 --- a/Tests/wkhtmltopdfTests/wkhtmltopdfTests.swift +++ b/Tests/wkhtmltopdfTests/wkhtmltopdfTests.swift @@ -24,7 +24,7 @@ class wkhtmltopdfTests: XCTestCase { let document = Document(margins: 15) let page1 = Page("

Page from direct HTML

") document.pages = [page1] - let data = try document.generatePDF(on: eventLoop).wait() + let data = try document.generatePDF(eventLoop: eventLoop).wait() // Cop-out test, just ensuring that the returned data is something XCTAssert(data.count > 50) // Visual test From 77d66d3bbcec9305a432721367e98294699c6b15 Mon Sep 17 00:00:00 2001 From: Graham Burgsma Date: Mon, 11 May 2020 19:43:54 -0400 Subject: [PATCH 2/2] Update README with 3.0.0 changes --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a209523..00511a0 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ # wkhtmltopdf -![Swift](http://img.shields.io/badge/swift-4.2-brightgreen.svg) -![Vapor](http://img.shields.io/badge/vapor-3.0-brightgreen.svg) +![Swift](http://img.shields.io/badge/swift-5.2-brightgreen.svg) +![Vapor](http://img.shields.io/badge/vapor-4.0-brightgreen.svg) ![Travis](https://travis-ci.org/vapor-community/wkhtmltopdf.svg?branch=master) -Vapor 3 library for converting HTML (Leaf or otherwise) into PDF files using +Vapor 4 library for converting HTML (Leaf or otherwise) into PDF files using [wkhtmltopdf](http://wkhtmltopdf.org/). ## Getting Started Add the following in your `Package.swift` file ```Swift -.package(url: "https://github.com/vapor-community/wkhtmltopdf.git", from: "2.0.0"), +.package(url: "https://github.com/vapor-community/wkhtmltopdf.git", from: "3.0.0"), ``` ## 📘 Overview First, install [wkhtmltopdf](http://wkhtmltopdf.org/downloads.html). This -library is tested on version 0.12.4. Specify the location of `wkhtmltopdf` +library is tested on version 0.12.5. 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. @@ -49,14 +49,14 @@ func pdf(_ req: Request) -> Future { // Add the pages to the document document.pages = [page1] + pages // Render to a PDF - let pdf = try document.generatePDF(on: req) + let pdf = try document.generatePDF(eventLoop: req.eventLoop) // Now you can return the PDF as a response, if you want return pdf.map { data -> Response in - let http = HTTPResponse(status: .ok, - headers: HTTPHeaders([("Content-Type", "application/pdf")]), - body: data) - return Response(http: http, - using: req) + return HTTPResponse( + status: .ok, + headers: HTTPHeaders([("Content-Type", "application/pdf")]), + body: .init(data: data) + ) } } }