WordPress is a full-featured CMS system which is used countless times throughout the Internet. And there are many plugins available. Almost a plugin for every task you can imagine.
But there is one feature that I could not find. How to download all (or a list of) articles at once. And how to create a PDF of all your articles that could be further printed out?
Actually, this is not really difficult. First, create a file which contains a list of the hyperlinks (one per line) of your articles. You can compile this list manually if you want to retrieve just a small set of articles, or you can create a complete list from the database.
To retrieve all articles’ links login in to your WP database (not the blog) either directly on the command line with the mysql command or by using a web tool, such as PHPmyadmin and select your WP database. In most cases the name of the database is ‘wpm’. Within this database you’ll find a lot of tables. If you run a WP network (multisite) then there are even more tables 😉
The table we are looking for is called ‘…_posts‘. Typically the name is either ‘wp_posts‘ if you have a standard single WP installation or it is named ‘wp_mu_X_posts‘ in a WP multisite environment, where X is the number of the site.
Now issue the following command in your mysql tool (with the correct name of your _posts table):
select guid from wp_mu_X_posts where post_status='publish' and post_type='post';
You will get a list of a links. Copy them into a simple text file. It should finally look like the following example:
Having these links you can now use any tool to batch download the contents, e.g. wget, curl, or my favorite wkhtmltopdf. The latter retrieves all contents and creates a PDF which is ready for printout.
I wrote the following simple shell script which retrieves the list of links out of a file named ‘list‘ and downloads and converts the pages to PDF documents.
#!/bin/sh j=100 for i in $(cat list) do wkhtmltopdf -B 15mm -L 20mm -R 20mm -T 15mm "$i" $j.pdf j=$(($j + 1)) done
After it finished you’ll find a lot of PDFs in your directory — one for each link. If you want to create an all-in-one PDF there are several options. My favorite is the tool pdftk. Run the following command to concatenate all PDFs into one large document:
pdftk *.pdf cat output all_in_one.pdf
Of course, have a look at the appropriate man pages for more information.
Have phun creating your WP blog PDF books 🙂