wkhtmltopdf setup guide with KnpLabs Snappy support on Debian

This document will show you how to get wkhtmltopdf working on Debian using KnpLabs Snappy. If you try and install from distribution you won’t get some of the latest features of wkhtmltopdf like {shell}–javascript-delay{/shell}. This guide will help you install the latest version {shell}0.11.0 rc1{/shell}. This guide assumes you have LAMP already installed and that you can run {shell}sudo{/shell}.

1. Installing dependencies

Before you install you will need to have X11, gcc and openssl installed.

2. Getting the source

The bleeding edge build from git didn’t work for me so let’s download the latest stable release build.

Let’s make a temp directory

Download and extract the code by running

Be sure to change the version number to the latest source release.

3. Installing QT

Before you can compile wkhtmltopdf you need to have QT installed, again you have two options: You can install the QT from your distribution, this will be fast but your wkhtmltopdf build will not have all the features of the static build, or you can compile QT your self, this takes a long time but you will get all the features.

NOTE: I would suggest installing from distribution (3.b). I tried installing from source and it didn’t work.

3.a Installing QT from your distribution

You must now run qmake in the wkhtmltopdf folder.

3.b Installing QT yourself

First check out the source

Qt must be configured, a good set of configuration options for qt can found by looking at the output of

And Qt compiled and installed (this will take a while)

You must now run qmake in the wkhtmltopdf folder.

4. Compiling and installing wkhtmltopdf

Now all you need to do is compile and install wkhtmltopdf

For some reason Debian wants execute from

. So do the following to fix the issue.

6. Check to see if it works

Run the following. If you get the error {shell}”Cannot connect to X server”{/shell} then continue to number 7.

7. Fixing “Cannot connect to X server”

We need to run it headless on a ‘virtual’ x server. We will do this with a package called xvfb.

8. Create a shell script wrapper for wkhtmltopdf

We need to write a little shell script to wrap wkhtmltopdf in xvfb. Make a file called wkhtmltopdf.sh using the following:

Now let’s make it executable.

Give step 6 a try again.

Using KnpLabs Snappy

Here I will show you how to use KnpLabs Snappy. Snappy is a PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. It uses the excellent webkit-based wkhtmltopdf and wkhtmltoimage available on OSX, linux, windows.

1. Download snappy from github

2. Copy the {shell}snappy-master/src{/shell} folder to your webroot.

3. Create a html file for your template

Save this file as {shell}hello.html{/shell} in your webroot. This will be used as your template. It contains a chart from hicharts.js.

Notes

In order for wkhtmltopdf to correctly print the chart, it is advised to remove any animations on hicharts.js objects. You will need to set the {javascript}animation{/javascript} property to false for both the {javascript}Chart{/javascript} object and the {javascript}plotOptions.series{/javascript} object.

4. Create the following php file in your webroot.

Save this file as {shell}generate-pdf.php{/shell} in your webroot.

Notes

Note the use of {php}javascript-delay{/php}:

This will allow you to delay the printing of the pdf for a specified amout of time defined by ms. In this case the delay is set to {php}500ms{/php}. Also the {php}Content-Disposition{/php} is set to {php}inline{/php}. This will allow the pdf to show withing the browser window if the user has a pdf plugin installed. Supported browsers are Chrome and Safari. If the user does not have a supported browser they will be presented with a file download diaglog.

Resources

Date
December 3, 2012
Time
1:26 am
Category
Uncategorized
Tags


Fix XAMPP HostnameError001 on Mac OS X

Today when starting up XAMPP in Snow Leopard I ran across this problem where I was getting a HostnameError001 popup. So the first thing that I thought of was to cross check my hostname with my computer name. Turns out that for me this was the problem.
(more…)

Date
April 29, 2011
Time
3:39 pm
Category
Uncategorized
Tags
Tags: , , ,


Too many carousel items in jCarousel Lite v1.0.1

I’ve been working on a project and found the need for a carousel. After some searching I found a great script called jCarousel Lite. I found a bug with the implementation of jCarousel Lite v1.0.1 and how it uses selectors to get the number of li’s in a carousel. In my implementation I’m using list items within each carousel item. After looking at your code the following would result in jCarousel thinking that it has 3 items in the carousel when really there is only 1.

The current implementation of jCarousels use of $(‘li’, ul) in the constructor will return all nested li’s regardless of how deeply nested they are in the dom structure. To handle this issue I’ve modified a few lines of code in the constructor to fix this issue. Feel free to apply these changes if you see fit.

Here’s the original snippet:

Here is my modified version:

Date
March 30, 2011
Time
8:11 pm
Category
Uncategorized
Tags
Tags: , ,


Fixing WordPress update issue for Mac localhost

Today I was trying to put in some work on my custom theme when I noticed that a few of my plugins were out-of-date. I proceeded to use the auto update feature and kept getting a write permission error during the update process. After some searching I found this great little tidbit that helped fix my issue. Go to the root of your WordPress site and run the following in Terminal:
chmod -R go+w *

You may have issues with permissions when trying to upload, import, etc. You can correct this by doing a chmod on your sites folder and subfolders.

From the terminal navigate to your sites folder and run something like the following…

chmod -R go+w *

This will grant group and others write permissions. If you need higher local security, then feel free to grant permissions by a more restrictive method.

This information was gathered from several sources. If you have problems or need additional information, I would reference my sources for this article. Please post additional recommendations and issues in the forum comments associated with this article.

http://www.angry-fly.com/index.cfm/2007/10/26/Fix-for-MySQL-on-Leopard
http://warker.com/2006/09/16/wordpress-os-x-install-tips/
http://remysharp.com/2007/10/27/lamp-in-leopard-osx-105-php5-and-apache-22/

[via tech-recipes]

Date
January 20, 2011
Time
3:25 pm
Category
Uncategorized
Tags
Tags: ,


InteractivePNG – AS3 Class to handle hit areas for transparent PNG's

Moses Gunesch, creator of Fuse Kit and ZigoEngine , has developed an AS3 Class which handles mouse interactions when dealing with transparent PNG’s.

Here is the theory:
If you have a PNG (one that contains transparent areas) embedded inside of a MovieClip button, the rectangle of the image acts as the hitArea of the MovieClip. In order for the hitArea to only be defined by visible areas of the image, you would normally have to create a custom mask in order to hide the transparent areas of the PNG. This AS3 Class allows you to specify an alpha tolerance (0=transparent, 255=completely opaque), that will allow you to selective exclude the transparent areas from your hitArea based on the value that you give it. This is a very simple concept, but an intricate implementation.

The project is open-sourced under the MIT  Open Source License. Go and check it out:

Date
February 2, 2009
Time
5:27 pm
Category
Uncategorized
Tags
Tags: , , ,


Setting up Eclipse + FDT for CS4 Authoring

Here are the swc paths that you’ll need to setup FDT for writing Flash 10 code.

Base Flash CS4 Class Path
$(AppConfig)/Common/Configuration/ActionScript 3.0/FP10

Class Path for ik.swc
$(AppConfig)/Common/Configuration/ActionScript 3.0/libs/ik.swc

Class Path for player.swc
$(AppConfig)/Common/Configuration/ActionScript 3.0/libs/flash.swc

Where $(AppConfig) = /Applications/Adobe CS4/Adobe Flash CS4

Date
October 10, 2008
Time
11:27 pm
Category
Uncategorized
Tags
Tags: , , , , ,


Flashcamp 10 San Francisco – Day 1

We got our copies of Flash CS4. The UI is pretty sweet. They now have some pretty decent presets for workspaces. Here are screenshots of the six workspaces that come out of the box.

Animator
Flash CS4 Workspace: Animator
(more…)

Date
Time
11:12 pm
Category
Uncategorized
Tags
Tags: , , ,


LivePlace and OTOY Server-Side 3D Rendering

Check out this video on LivePlace. It demo’s a virtual world that is rendered server-side, much like Second Life. This demo video that was leaked is shown on a Treo 700 at 240kbps. This is some really awesome tech. The environments are super real and looks to break some barriers by allowing anyone with an internet connected device to interact with the world. This means that mobile users can dream of being in another world while on their commute in their mundane lives.

Original article on Gizmodo

OTOY is the technology behind the server-side 3d rendering technology. Here are a few video’s:
(more…)

Date
August 15, 2008
Time
3:57 pm
Category
Uncategorized
Tags
Tags: , , ,


New VisionAire technology from Obscura Digital

In this video you’ll see Steve Mason demonstrating Obscura Digital’s VisionAire technology. He’s not using any controller in his hands. He’s not moving in sync with a pre-recorded video. They are using some proprietary motion capture technology to capture his movements and translate them to on-screen actions. The image is being projected from the ceiling reversed to a mirror on the floor. The image is then reflected to a screen net that is at a 45 degree angle to the presenter. Steve is able to move his arms around freely without having to touch anything. The audience that is front and center get’s the best view, but if your off to one side you can see the screen net. These guys are a group of talented engineers here in the bay.

Check them out: Obscura Digital

Date
August 6, 2008
Time
12:29 pm
Category
Uncategorized
Tags
Tags: , ,


HAMSoft Engineering: What's Keeping Me?


What’s Keeping Me? is an application that will locate, quit, relaunch, or kill the problem application that is preventing you from accomplishing a task (empty the Trash, eject a disk, etc…).
HAMSoft Engineering: What’s Keeping Me?

Date
July 16, 2008
Time
2:34 pm
Category
Uncategorized
Tags
Tags: , ,