wkpdf is no longer maintained
My objective for wkpdf was providing the user with a simple installation experience on a stock OS X installation. I was excited when Apple started shipping RubyCocoa in OS X 10.5 because this meant that wkpdf could be installed easily using the rubygems package manager, without requiring the user to modify the system ruby installation with a RubyCocoa instalation. The official adoption of RubyCocoa by Apple, motivated me to port wkpdf from its initial incarnation in Objective-C to Ruby.
However, in OS X 10.9. Apple stopped shipping RubyCocoa with its default Ruby, which was upgraded at the same time from 1.8 to 2.x. While Apple still shipped RubyCocao for Ruby version 1.8, which was installed in parallel on OS X 10.9 for compatibility reasons, the writing was on the wall that RubyCocoa will be going away in the not too distant future. Thus it didn't come as a surprise when OS X 10.10 shipped without Ruby 1.8 and without RubyCocoa.
While wkpdf reportedly works in OS X 10.10 after RubyCocoa is installed with the binary installer, this is not the way I would like wkpdf to be installed. I like my system Ruby installation to be untouched, because messing with system Ruby will cause problems in the long run. Installing an additional Ruby in a different location may solve the problem for experienced users. But over the years, I received too many support requests from novice users with custom ruby installations, that messed up their installation causing lots of frustration and difficult to diagnose problems. This was my reason for only support a the canonical stock system ruby installation. Because this is no longer possible, I decided, as of December 2014, to no longer maintain the RubyCocoa version of wkpdf and to pull the corresponding gem from RubyGems.
So what's next? wkpdf was initially ported from a less advanced Objective-C implementation and it would be fairly easy to port the latest wkpdf version from RubyCocoa to Objective-C again, or to Swift. As my own use of wkpdf was very limited over the last couple of years, this is however not very high on my priority list.
How you can help: If you are interested to contribute to porting wkpdf from RubyCocoa to Objective-C or Swift, please let me know. If you are not a developer but would like to see a modernized version of wkpdf that runs on a current OS X system, you may consider offering a development bounty. Please get in touch with me, if this is an option for you.
What is wkpdf
wkpdf is a command line tool for rendering HTML to PDF using WebKit and RubyCocoa on Mac OS X.
Although there are plenty of browsers available for Mac OS X, I could not find a command-line tool that allows for downloading a website and storing the rendered website as PDF. This was my motivation for creating wkpdf. The application uses Apple WebKit for rendering the HTML pages, thus the result should look similar to what you get when printing the webpage with Safari.
Since wkpdf is based on the state-of-the-art WebKit HTML rendering framework, it provides high-quality web standard compliant HTML rendering with support for advanced CSS2/CSS3 styling.
There are plenty of use cases for wkpdf. For example, you may use wkpdf for:
- Automated generation of reports, invoices, etc.
- Creation of high-quality PDf versions of documentation in HTML format
- Archiving of PDF snapshot of websites
- etc.
Installation
wkpdf is an open-source software project. Its source code is hosted at github.com. For easy installation wkpdf is available as a Ruby gem package from rubygems.org, which means that wkpdf can be easily installed on Mac OS X 10.5.x and later with the RubyGems package manager that comes pre-installed with Mac OS X.
Installing wkpdf requires a recent version of RubyGems. If you don't have installed RubyGems version 1.3.3 or later, you need to update to the latest version with:
sudo gem update --system
Now you are ready to proceed with the installation of wkpdf with the the following command:
sudo gem install wkpdf
After wkpdf has been installed once, you can always update to the latest version with:
gem update wkpdf
Usage
The following command shows the basic usage of wkpdf. The content of the apple.com website is rendered to a file apple.pdf in the current directory.
wkpdf --source http://www.apple.com --output apple.pdf
wkpdf supports many options that affect how a HTML page is rendered and allow for example to set the page size and orientation, select specific style-sheet media, ignore HTTP errors etc. You can get a brief decription of wkpdfs options with:
wkpdf --help
The following example renders the apple.com website to a PDF document in A5 format in landscape orientation:
wkpdf --source http://www.webkit.org --paper A5 --orientation landscape \ --output webkit.pdf
Many websites provide specific CSS stylesheets for printing, which suppress superfluous graphical elements in order to generate tidy printouts. If you want to render a website with all the graphical icing to exactly match the view in a browser, you can explicitly force the use of the CSS screen stylesheet and enable the printing of background images as in the following example:
wkpdf --source http://www.slashdot.org --stylesheet-media screen \ --print-background yes --output sd.pdf
The following example suppresses pagination that is, the whole Slashdot front page is rendered as a single PDF page that extends as needed to fit the whole content.
wkpdf --source http://www.slashdot.org --stylesheet-media screen \ --print-background yes --paginate no --output sd.pdf
Developers
If you are a developer and you would like to extend wkpdf you can browse and clone wkpdf's git repository at: http://github.com/plessl/wkpdf.
Recipes and FAQ
A list of useful recipes and frequently asked questions can be found in the wkpdf Wiki.Questions and Support
For questions regarding wkpdf contact: wkpdf@plesslweb.ch
Please use the issue tracker at github for reporting bugs.
License
wkpdf is available under the terms of the MIT license:
Copyright (c) 2007-14 Christian Plessl
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.