Menu

PDF Presentations Using AxPoint

June 19, 2002

Kip Hampton

Editor's Note: Kip Hampton will be presenting a tutorial on Perl and XML at the upcoming O'Reilly Open Source Convention.

Introduction

Conference season is upon us and it's time once again for Perl lovers throughout the world to come together in a spirit of sobriety and good citizenship to share information about the ins and outs of using their favorite language. (Okay, at least the information-sharing and favorite language parts are true...)

All kidding aside, if you've ever attended The Perl Conference or one of the YAPC gatherings, you've probably experienced the vague sense of disappointment that comes from watching someone who's otherwise staunchly committed to Open Source software boot up proprietary OS to use a presentation application to deliver the slides for their talk. It doesn't have to be that way; there are alternatives.

This month, we will be examining AxPoint, Matt Sergeant's Perl/XML-based tool for creating visually rich presentations and slideshows in PDF.

Originally designed for use exclusively within the AxKit XML publishing environment, AxPoint has recently undergone a major facelift and is now also available outside of AxKit as a simple SAX Handler, XML::Handler::AxPoint.

First, let's have a look at AxPoint's XML syntax.

Basic AxPoint Syntax

AxPoint's XML application grammar was designed to be very simple. And it is. Most of the low-level details of how the data will be rendered as PDF (placement of text and images on the slides, etc) are taken care of invisibly, freeing the author to focus on the content of the presentation.

Here is a list of the most common elements in the AxPoint language:

<slideshow>
The required root-level element for all AxPoint presentations

Parents: None

Children: slideset, slide, title, metadata.

<slide>
This element defines the boundaries for a single slide in the presentation.

Parents: slideshow, slideset.

Children: image, point, source-code, title. .

<slideset>
A logical grouping of one or more <slide> elements.

Parents: slideshow, slideset, slide.

Children: None.

<point>
A single bullet-point contained in a <slide>.

Parents: slideshow, slideset, slide.

Children: None.

<source-code> (or <source_code>)
A block of text rendered in a fixed-sized font, equivalent to the <pre> element in HTML.

Parents: slideshow, slideset, slide.

Children: None.

<title>
Defines the title for the immediate parent element.

Parents: slideshow, slideset, slide.

Children: None.

<image>
Inserts an image into current slide.

Parents: slideshow, slideset, slide.

Children: None.

<b> and <i>
Renders the enclosed text in either a bold or italic typeface (same as HTML).

Parents: point, source-code.

Children: None.

<color> (or <colour>)
Renders the enclosed text in a specific color. To choose the color, you can pass one of the 16 HTML named colors to the name attribute, or you can use the rgb attribute and pass in a hex triplet.

Parents: point, source-code.

Children: None.

<metadata>
A child of the <slideshow> element, this element may contain a number of child elements that describe the metadata for the slideshow.

Parents: slideshow.

Children:

  • speaker -- The speaker's name; appears on the title slide.
  • email -- The speaker's email address. If present, it makes the speaker's name appears as a mailto: link on the title slide.
  • organisation -- The speaker's company or affiliation.
  • link -- A URL. If present, it makes the organisation name appear as a hyperlink to that URL on the title slide.
  • background -- The path to an image to be used as the background for all slides in the presentation. The image size is fixed at 612 x 450.
  • logo -- The path to a logo or other image that will appear in the lower right corner of each slide.
.

Example -- A Simple AxPoint Presentation

For our sole example, we will create a simple AxPoint presentation for a talk about Damian Conway's confounding, but cool Acme::Bleach module. We'll start by creating a new empty document named bleach.axp.

With our new document open, let's create the required top-level <slideshow> element and add the metadata for the talk. This information will appear on the presentation's title slide.


<?xml version="1.0"?>

<slideshow>

  <title>The Secrets of Using Acme::Bleach</title>

  <metadata>

    <speaker>Dr. Ima Guru</speaker>

    <email>guru@geek-temple.tld</email>

    <organisation>High Order of Geeks</organisation>

    <background>bg2.png</background>

  </metadata>

Next, we will add the markup that will be used to create our first slide. This slide consists of a single bullet point (<point> element ) and a <source-code> block.


  <slide>

    <title>Before</title>

    <point level="1">Begin with a typical Perl script.</point>

    <source-code>

use XML::LibXML;



my $file = 'files/camelids.xml';

my $p = XML::LibXML->new();



my $dom = $p->parse_file( $file );



my $root = $dom->getDocumentElement();



foreach my $species ($root->find('//species')->get_nodelist){

    print $species->find('common-name')->string_value;

    print ' (' . $species->find('@name') . ') ';

    print "\n";

}



# prints

Bactrian Camel (Camelus bactrianus)

Dromedary, or Arabian Camel (Camelus dromedarius)

...

    </source-code>

  </slide>

Our second slide is very much like the first, but certain parts of the source code will be rendered in red in order to highlight changes.


  <slide>

    <title>During</title>

    <point level="1">Import Acme::Bleach.</point>

    <source-code>

use XML::LibXML;

<color name="red">use Acme::Bleach;</color>



my $file = 'files/camelids.xml';

my $p = XML::LibXML->new();



my $dom = $p->parse_file( $file );



my $root = $dom->getDocumentElement();



foreach my $species ($root->find('//species')->get_nodelist){

    print $species->find('common-name')->string_value;

    print ' (' . $species->find('@name') . ') ';

    print "\n";

}



# prints

Bactrian Camel (Camelus bactrianus)

Dromedary, or Arabian Camel (Camelus dromedarius)

...

    </source-code>

  </slide>

The third slide is also similar, but features a second-level <point> element.


<slide>

<title>After</title>

<point level="1">When running a script that uses 

Acme::Bleach for the first time, all the distracting 

printable characters are removed from your source file 

and only the 'use Acme::Bleach' line appears.</point>

<point level="2">The scary part is, the script 

still works as before.</point>

    <source-code>

use Acme::Bleach;



# prints

Bactrian Camel (Camelus bactrianus)

Dromedary, or Arabian Camel (Camelus dromedarius)

...

    </source-code>

  </slide>

All that's left to make the document well-formed XML is to close the top-level element.


</slideshow>

Creating the PDF Document

There are two ways to deliver our presentation in PDF format. If we have AxKit installed on our Web server, we can have it do the transformation on the fly using the Apache::AxKit::Language::AxPoint module. Here's an example of what we might add to our .htaccess or httpd.conf files to set that up:


<Files *.axp>

  AxAddStyleMap application/x-axpoint Apache::AxKit::Language::AxPoint

  AxAddProcessor application/x-axpoint NULL

</Files>

Now all requests for XML documents with a .axp file extension will be processed by the AxPoint language module and delivered as PDF to the client.

If you do not have AxKit installed, you can use the command-line tool axpoint, which installs with XML::Handler::AxPoint, to handle the transformation

To create the file bleach.pdf from our document, we simply invoke the axpoint utility, passing the path to our XML document, and the name of the file we wish to create:


$ axpoint bleach.axp bleach.pdf

If no parsing errors occur, this writes the PDF version of our presentation to the file system.

The complete PDF slideshow is available in this month's samples, but let's look at a couple of excerpts.

screenshot

screenshot

Conclusions

Also in Perl and XML

OSCON 2002 Perl and XML Review

XSH, An XML Editing Shell

Multi-Interface Web Services Made Easy

Perl and XML on the Command Line

Introducing XML::SAX::Machines, Part Two

AxPoint is one of those rare applications that strikes a good balance between simplicity and functionality. If you want to get fancy, you can -- for example, the latest version even supports certain SVG primitives, natively -- but if you need something fast, the language itself gets out of the way and lets you focus on the important parts without sacrificing a professional look. If you have presentation deadlines coming up (and I know I do) I strongly encourage you to give AxPoint a close look.

Resources