[bash] Export wordpress posts as pdf without plugin

Install wkhtmltopdf:

apt-get install wkhtmltopdf

From phpmyadmin, export permalinks as CSV, use this SQL query:

SELECT `post_name` FROM `wp_posts` WHERE `post_type` = 'post' AND `post_status` = 'publish';

Copy the script, change filename, wp base url and output directory:

#!/bin/bash

# Input file
filename='wp_posts.csv'

# Wordpress base url
wp='http://blog.chemel.fr/'

# Ouput dir
directory='./dump/'

mkdir -p $directory

while IFS=$'\n\r' read -r permalink
do
    if [ ! -f $directory$permalink.pdf ]; then

        echo $wp$permalink

        wkhtmltopdf $wp$permalink $directory$permalink.pdf
    fi
done < "$filename"

Set permission and execute:

chmod +x wordpress2pdf.sh

./wordpress2pdf.sh

Done.

If you don’t have access to the mysql database you can crawl the sitemap.xml. See this script: https://github.com/chemel/blog2pdf