Permalink
Browse files

Initial import

  • Loading branch information...
aebruno committed Apr 9, 2011
0 parents commit 3da90f3ae94203c0bb4551e984b3c85ea2072c28
674 COPYING

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,55 @@
+#-------------------------------------------------------------------------------
+# Makefile for converting WordPress blog into PDF
+#-------------------------------------------------------------------------------
+
+#
+# Required software
+#
+XSLTPROC=/usr/bin/xsltproc
+FOP=/usr/bin/fop
+PHP=/usr/bin/php
+
+
+all: prepare export-docbook docbook-final fo pdf
+
+prepare:
+ mkdir -p scratch
+
+export-docbook: prepare
+ ${PHP} wp2docbook.php -b -o scratch/quasi-docbook.xml
+
+#------------------------------------------------------------------------------
+# XXX Need to configure the XSLT parameters:
+#
+# media.file.path - Full path to WordPress install (/var/www/blog)
+# blog.url - URL of your blog (http://localhost/blog)
+#------------------------------------------------------------------------------
+docbook-final: export-docbook
+ ${XSLTPROC} \
+ --stringparam media.file.path '/var/www/sample-blog' \
+ --stringparam blog.url 'http://localhost/sample-blog/' \
+ wp-html2docbook.xsl scratch/quasi-docbook.xml > scratch/docbook-final.xml
+
+#------------------------------------------------------------------------------
+# Edit the XSLT parameters to adjust resulting PDF file
+#------------------------------------------------------------------------------
+fo: docbook-final
+ ${XSLTPROC} \
+ --stringparam page.width 6in \
+ --stringparam page.height 9in \
+ --stringparam page.margin.inner 1.0in \
+ --stringparam page.margin.outer 0.8in \
+ --stringparam body.start.indent 0pt \
+ --stringparam body.font.family Times \
+ --stringparam title.font.family Times \
+ --stringparam dingbat.font.family Times \
+ --stringparam generate.toc 'book toc title' \
+ --stringparam hyphenate false \
+ /usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl \
+ scratch/docbook-final.xml > scratch/book.fo
+
+pdf: fo
+ ${FOP} -c conf/userconf.xconf scratch/book.fo book.pdf
+
+clean:
+ rm -Rf scratch/ book.pdf
59 README
@@ -0,0 +1,59 @@
+===============================================================================
+wp2print - Convert WordPress Blog to print ready PDF
+===============================================================================
+
+ABOUT
+
+This project contains code to export posts from WordPress and convert them into
+DocBook XML. The resulting DocBook is then converted to XSL-FO which can be
+used for conversion into PDF.
+
+
+Example usage (see Makefile for complete example):
+
+ $ php wp2docbook.php -b -o quasi-docbook.xml
+ $ xsltproc \
+ --stringparam media.file.path '/var/www/blog' \
+ --stringparam blog.url 'http://localhost/blog/' \
+ wp-html2docbook.xsl quasi-docbook.xml > docbook-final.xml
+ $ xsltproc /path/to/docbook-xsl/fo/docbook.xsl docbook-final.xml > book.fo
+ $ fop book.fo book.pdf
+
+SOURCE CODE
+
+- wp2docbook.php - Main driver to convert WordPress to quasi-DocBook
+- wp-html2docbook.xsl - XSLT to convert quasi-DocBook to valid DocBook
+- lib/config.php - Configuration file (defines file paths / settings)
+- lib/export-docbook.php - Code for exporting WordPress Posts as DocBook
+- conf/userconf.xconf - Apache FOP config file for embedding fonts
+- Makefile - Create print ready PDF
+
+
+REQUIRED SOFTWARE
+
+- DocBook XSL stylesheets: http://docbook.sourceforge.net/
+- XSLT processor: xsltproc (libXML), Saxon, Xalan, etc.
+- Apache FOP: http://xmlgraphics.apache.org/fop/
+- WordPress (access to the install directory)
+
+SIMPLE EXAMPLE BLOG
+
+For demonstration purposes only, I've included an export of a simple blog
+consisting of posts of Shakespeare's sonnets. To run the example:
+
+1. Install a fresh copy of WordPress
+2. Install the wordpress-importer plugin
+3. Import the contents from sample/shakespeare-blog-wordpress-export.xml
+4. Edit the lib/config.php file with the appropriate settings
+5. Edit the conf/userconf.xconf file to the full path of truetype fonts
+6. Edit the Makefile and set the URL and full path to the WordPress install
+7. $ make
+8. View book.pdf
+
+The steps outlined above are only guidelines and some extra finagling may be in
+order.
+
+AUTHOR
+
+wp2print was written by Andrew E. Bruno <aeb@qnot.org>
+
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<fop version="1.0">
+<source-resolution>300</source-resolution>
+<target-resolution>300</target-resolution>
+<renderers>
+ <renderer mime="application/pdf">
+ <!-- Full path to truetype fonts to be embedded in PDF file -->
+ <fonts>
+ <font embed-url="file:///usr/share/fonts/truetype/freefont/FreeSerif.ttf">
+ <font-triplet name="Times" style="normal" weight="normal"/>
+ </font>
+ <font embed-url="file:///usr/share/fonts/truetype/freefont/FreeSerifBold.ttf">
+ <font-triplet name="Times" style="normal" weight="bold"/>
+ </font>
+ <font embed-url="file:///usr/share/fonts/truetype/freefont/FreeSerifItalic.ttf">
+ <font-triplet name="Times" style="italic" weight="normal"/>
+ </font>
+ <font embed-url="file:///usr/share/fonts/truetype/freefont/FreeSerifBoldItalic.ttf">
+ <font-triplet name="Times" style="italic" weight="bold"/>
+ </font>
+ </fonts>
+ </renderer>
+</renderers>
+</fop>
@@ -0,0 +1,31 @@
+<?php
+class Config {
+ //----------------------------------------------------------
+ // Configuration for wp2docbook
+ //----------------------------------------------------------
+
+ // Full path to your WordPress install
+ public static $WP_PATH = '/var/www/sample-blog';
+
+ // Title of your book
+ public static $BOOK_TITLE = "Shakespeare's Sonnets";
+
+ // Optionally designate a page/post to be the preface of the book
+ public static $PREFACE_PAGE = 'About';
+
+ // Author First Name
+ public static $AUTHOR_FIRST = 'William';
+
+ // Author Last Name
+ public static $AUTHOR_LAST = 'Shakespeare';
+
+ // Include copyright in title page?
+ public static $INCLUDE_COPYRIGHT = true;
+
+ // Copyright year
+ public static $COPY_YEAR = 2011;
+
+ // Copyright holder
+ public static $COPY_HOLDER = 'William Shakespeare';
+}
+?>
Oops, something went wrong.

0 comments on commit 3da90f3

Please sign in to comment.