Tech Blog

Generating PDFs and ePubs from an AsciiDoc ... on a Mac

Posted At : August 11, 2011 9:41 AM 2 Comments


I've been updaging our existing documentation which was written in AsciiDoc and also creating new documentation recently.

Our normal process is to update the source text file, commit to our SVN and the run the documentation build script from the deployment server to create the HTML and PDF versions of the document.

This works fine from our server but to speed things up while I was writing the documents and make sure I had the formatting correct I thought I'd install AsciiDoc on my laptop and 'build' the document locally before committing to SVN, building and checking.

Installing AsciiDoc is simple enough using MacPorts:

$ sudo port install asciidoc

Creating a html version of your AsciiDoc is simple at this point:

$ asciidoc /home/ajdyka/sample.txt

That will output a file called sample.html in the same directory as the source file. No worries ...

To create a PDF or an ePub, it's recommended that you use the a2x command instead of asciidoc though.

According to the AsciiDoc website "a2x is A toolchain manager for AsciiDoc (converts Asciidoc text files to other file formats)"

So I gave this a try:

$ a2x -fpdf -dbook -L sample.txt
$ a2x -fepub -dbook -L sample.txt

It generated the following error though!

a2x: ERROR: xmllint --nonet --noout --valid sample.xml returned non-zero exit status 4

It took a bit of Googling (sp?) but I found the core of my solution in this post:Fixing the ePub problem with Docbook-XSL/A2X/Asciidoc

The only 'tricky' part was finding my catalogue.xml, which ended up being in /opt/local/share/xsl/docbook-xsl ... and I modified the contents to be:

<?xml version="1.0" encoding="utf-8"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<!-- XML Catalog file for DocBook XSL Stylesheets v1.76.1 -->
<rewriteURI uriStartString="/usr/local/docbook-xsl-1.76.1/epub" rewritePrefix="./"/>
<rewriteSystem systemIdStartString="/usr/local/docbook-xsl-1.76.1/epub" rewritePrefix="./"/>
</catalog>
* the new path is where I extracted the docbook-xsl-1.76.1 archive

Once I had done that, everything generated fine :)

The next thing I need to work on is getting the default XSLT template cleaned up :)

HTH

A.J.

Tomcat: Out of memory - permgen

Posted At : August 4, 2011 6:56 AM

I ran into a permgen out of memory issue with one of our applications running on Tomcat/Railo and did a bit of digging around.

The main answer on the web is: Increase the size of you permgen by adding the following:

-XX:MaxPermSize=128m

However, to me this just delays the problem, particularly if you are using dynamic languages which load a lot of classes eg Railo.

So a bit of further digging found these options:

-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

These 3 options allow the permgen memory to be garbage collected. I tried to find a good reference link for them but couldn't.

The final thing that I discovered was the jmap tool - which is very helpful for understanding the memory usage.

You run it as follows and it gives a great summary of the memory usage of your running jvm.

$ sudo jmap -heap 18068

Attaching to process ID 18068, please wait...
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process
markl@davoip:/opt/tomcat/bin$ sudo jmap -heap 18068
[sudo] password for markl:
Attaching to process ID 18068, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 19.1-b02

using thread-local object allocation.
Parallel GC with 2 thread(s)

Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 530579456 (506.0MB)
NewSize = 1048576 (1.0MB)
MaxNewSize = 4294901760 (4095.9375MB)
OldSize = 4194304 (4.0MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 16777216 (16.0MB)
MaxPermSize = 67108864 (64.0MB)

Heap Usage:
PS Young Generation
Eden Space:
capacity = 114294784 (109.0MB)
used = 54227688 (51.715553283691406MB)
free = 60067096 (57.284446716308594MB)
47.445461728157255% used
From Space:
capacity = 31260672 (29.8125MB)
used = 0 (0.0MB)
free = 31260672 (29.8125MB)
0.0% used
To Space:
capacity = 31260672 (29.8125MB)
used = 0 (0.0MB)
free = 31260672 (29.8125MB)
0.0% used
PS Old Generation
capacity = 353763328 (337.375MB)
used = 317909912 (303.1825180053711MB)
free = 35853416 (34.192481994628906MB)
89.86514057217371% used
PS Perm Generation
capacity = 46399488 (44.25MB)
used = 44117200 (42.07344055175781MB)
free = 2282288 (2.1765594482421875MB)
95.08122158589336% used

Cheers, Mark