XML.com: XML From the Inside Out
oreilly.comSafari Bookshelf.Conferences.

advertisement

PDF Presentations Using AxPoint
by Kip Hampton | Pages: 1, 2

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