Nate Pinchot

Building static wkhtmltopdf (and static QT)

31 January 2014

This post details how to build a static QT and wkhtmltopdf on Linux (in this case, Ubuntu 12.04.4 LTS) and Mac OS X from source.

A lot of this is taken from the wkhtmltopdf wiki and the comments found there.

Mac OS X

Use homebrew, and install the following formulas:

brew install https://raw.github.com/npinchot/homebrew/wkhtmltopdf_static_qt/Library/Formula/qt-wkhtmltopdf.rb
brew install --static https://raw.github.com/npinchot/homebrew/wkhtmltopdf_static_qt/Library/Formula/wkhtmltopdf.rb

Linux

Step 1.

Make sure you have all the dependencies installed.

sudo apt-get install openssl build-essential libssl-dev libxrender-dev git-core libx11-dev libxext-dev libfontconfig1-dev libfreetype6-dev fontconfig -y

The wkhtmltopdf wiki suggests you should install xorg (X Window System). I did not need this.

You probably also want to install the ttf-mscorefonts-installer which has the free Microsoft fonts. Make sure you enable the multiverse repository first.

sudo apt-get install ttf-mscorefonts-installer

Step 2

Clone the current wkhtmltopdf repository from GitHub.

git clone git://github.com/wkhtmltopdf/wkhtmltopdf.git wkhtmltopdf

Step 3

Clone the current patched QT from Gitorius.

git clone -b wk_4.8.5 git://github.com/wkhtmltopdf/qt.git qt-wkhtmltopdf
cd qt-wkhtmltopdf

At the time of writing, the latest stable patched QT branch was wk_4.8.5, please check out the wkhtmltopdf GitHub page for up to date info.

Step 4

Configure and build QT. Unless you've got a newer machine, this will take a long time (on an EC2 m1.large, it took about 4 hours).

./configure -nomake tools,examples,demos,docs,translations -opensource -prefix "`pwd`" `cat ../wkhtmltopdf/static_qt_conf_base ../wkhtmltopdf/static_qt_conf_linux | sed -re '/^#/ d' | tr '\n' ' '`

make -j2

You should increase/lower the build jobs (-j#) depending on your system. On an EC2 m1.large, I used -j2 (one for each CPU core).

Step 5

Compile wkhtmltopdf.

cd ../wkhtmltopdf
../qt-wkhtmltopdf/bin/qmake
make -j2

SQL server failover partners wthout an Active Directory domain

17 August 2013

Our current classic ASP application uses Microsoft SQL server 2005 and mirroring between two servers with a witness. We use the failover partner setting in the connection string. We recently had an issue where the SQL server connections were failing whenever the failover partner became the principal SQL server. If we manually swapped the principal/mirror roles between the servers, and pointed the connection string to the new principal, the application was able to connect to the SQL server (but the failover partner issue persisted), so we knew it was not a connectivity issue to a specific SQL server.

Surprisingly, the fix was to add the non-fully qualified domain names of the principal and failover partner to the hosts file.

The answer is soft of explained in this Microsoft TechNet article:

The failover partner in the connection string is used as an alternate server name if the connection to the initial principal server fails. If the connection to the initial principal server succeeds, then the failover partner name will not be used, but the driver will store the failover partner name that it retrieves from the principal server on the client-side cache.

There's a blog post by Michael Aspengren and a comment here this page by Madhu Varrier that give us more insight.

Death to the GridView

15 June 2012

In my experience, the User Experience and User Interface of in-house corporate software applications is just awful. Every day I wonder to myself how many people come to work at a job they love, and have to use software that makes them despise it.

These terrible in-house software applications tend to love using GridViews (or their desktop brothers, the DataGrid). One of the UI/UX quotes I heard a while ago that I'll never forget went something like this (I'm paraphrasing):

"When it comes to UX, using a standard DataGrid is like giving up."

(I think Scott Barnes may have said this on Twitter, but I don't recall the exact quote and couldn't find it. Drop me a line if you know who said it or have a link.)

Over the past few days, I redesigned a screen that was one of these default GridView screens. It was recklessly laid out, with obviously little thought put into content placement. Here it is:

Old RGA screen with GridView

Pretty bad, right? Here's the redesign:

RGA screen redesign

Hopefully I made someone's job a little more enjoyable :)

Creating a nice effect to populate input fields

11 June 2012

Recently, I worked on a new feature for a client facing web application; the basic idea is that we want users to be able to save favorite items to allow them to quickly place orders for high volume items.

TL;DR - Skip to the demo.

A quick overview of the UI

The load favorite button is shown on page load. When the load button is clicked, the user will be presented with a jQuery UI dialog that lists all of their favorite items. Once the user starts entering text, the load button disappears and the save button is shown. Clicking the save button saves the data via a simple AJAX call. Simple, intuitive and easy to use.

The effect

When the user clicks the load favorite button, we present a nicely laid out list of their favorite items. When a favorite item is selected, we will show a helpful animation of the appropriate text "jumping" from the dialog into the text inputs. I accomplished this by doing some simple math to find a point between the X coordinates of the dialog text and the destination input and subtracting 150 pixels from the ending position Y coordinate. I took those 3 points, and used crSpline to build the animation path. crSpline is an efficient (in my experience) JavaScript library to find the Catmull-Rom spline for a set of given points and was written by M. Ian Graham (he goes by MmmCurry on GitHub and has an awesome Gravatar).

Let's take a look at the code.

The HTML:
Note: The favorite items are statically listed here. In the real world they are loaded via AJAX and added to the page using a jQote2 template.

The jQuery UI effect JavaScript:

You may notice this looks very similar to jquery.effects.transfer.js from jQuery UI, which is what I used as a starting point.

We can use the jump effect like this:

You'll notice the jump effect sets a default class of ui-effects-jump. This can be overridden by passing a class as part of the JSON object in the 2nd parameter.

Here's an example overriding the default class of ui-effects-jump:

Overall, the code is pretty simple. Check out the demo.

Hello

07 June 2012

Hi there. I know this site is a little bare at the moment, so I apologize. I'll be posting things here as I have time. I am working on organizing some semblance of a portolio and have a few posts that I've started writing. Hopefully some of these will be useful to someone :)