Forum OpenACS Q&A: More control of output

Posted by Jade Rubick on
I'm trying to find a way to output web pages with a little more control of how the pages print out than at present.
  • In this thread, Hamilton talks about an Active X based solution that seems like it would work -- except I have a few Mac, and I do the development on Linux.
  • Perhaps I could generate PDF files on the fly? Has anybody done this before?
  • Perhaps Cascading Style Sheets are what I'm looking for? CSS2 seems to be able to change rendering according to what type of media it is for. See for more on CSS2 and media types.
I'm looking into CSS2, but if you have any experiences or suggestions, I'd appreciate knowing of them.
Posted by Jonathan Ellis on
what exactly are your goals?

I mean, html was DESIGNED to be formatted differently depending on the device it was viewed on so no surprise it's inexact. :)

Posted by Tilmann Singer on
Here are some options for creating pdf's:

fop from Converts xml to pdf using a xsl-fo stylesheet. Not suited for on-the-fly creation IMO because it's too slow. Also writing the stylesheets can be cumbersome, in particular because there is a lot of the spec that fop does not yet implement - finding those by experimentation is a tiring process.

If you want a lot of control then take a look at the reportlab toolkit. It's sort of a graphic library that outputs to pdf instead of the screen, open sourced and in python. Very useful I think - I am using it to generate business letters on the fly from my website. Drawback is that you have to do quite a bit of programming to customize the look of your output.

For a quick-and-not-so-dirty solution there is also htmldoc. It converts html files to pdf, with the bonus that you can insert special <!-- comments --> in the html that contain formatting instructions like page breaks etc.

Posted by Matthew Terenzio on
Coincidentally, I bumped into this XML/PHP pdf generator. Alas, it is not free, nor have I tried it. For what it is worth,
Posted by Jade Rubick on
Reportlab looks like a very good product. I'm curious how you would interface it with OpenACS or ACS, though. The scripts are Python, right?

If I have a Tcl based package in ACS, and I'd like to output it with ReportLab, would I...

1) exec a dynamically generated shell script? that's a little scary..

2) use python inside Aolserver? I don't know anything about this.

3) something else entirely?

Incidentally, if you are looking for full printing control, Reportlab looks like a good option. Tilmann, would you mind sharing a little more about what you're using it for, and how?

Posted by Cynthia Kiser on
You can use Python to program AOLserver - see But from looking at your question I am not sure if that is helpful or not.
Posted by Tilmann Singer on
Jade, I am calling ReportLab with exec to pregenerate pdf's in the background whenever the underlying data changes. If for some reason a pdf is requested that has not been pregenerated previously then the request triggers the exec call. Even when the pdf is generated during the request this way it works quite fast - a few seconds - which is acceptable IMHO.

The data is exchanged via a temporary xml file: previously to calling exec the tcl script writes the data in an xml file in /tmp/ and then calls the ReportLab script giving it the filename on the commandline. The ReportLab script then parses the xml and generates the pdf. This sounds a bit complicated - I tried first to pass the data via stdin, but could not make it work with non us-ascii characters (umlauts always showed up as weird two-char combinations).

No need for scary dynamically generated scripts here - actually I am not sure what you meant by that?

Running python and ReportLab from inside aolserver would  be much more efficient I guess, but for now the approach above works fine.

You can check out a demo of that setup here: - an online business card generator.

Posted by Jade Rubick on
Thank you, Tilmann. That's a nifty demo you've got there. I'll be
working on this in a couple of weeks, and report back what I find.

If you didn't mind sending me the source code for your demo, I
could write up a HOWTO for the documentation. My examples
would be based on ACS 3.4.x (because unfortunately that's what
I'm working with right now), but I think it could be of value for the
rest of the community.

Posted by Harry Neuwirth on
Great idea for controlling appearance. Do you think there is a way to wrap Acrobat forms into openacs generated pages?
Posted by Tilmann Singer on
Jade, it's in file storage:

And forget the part about xml parsing - I figured that since it only needs to deal with one lined values this one is implemented with a simple text file format. The xml stuff was used in another package where ReportLab generates business letters, for which there is no demo unfortunately.

Posted by Jade Rubick on
I've written up an outline of how to generate PDF files from
(Open)ACS. I think by looking at Tilmann's package and my
HOWTO, you can quickly get up to speed on generating PDF
files. I've generalized Tilmann's code a tiny bit, but most of the
hard work was done by Tilmann. Thanks for sharing, Tilmann!

The HOWTO is located at:

Posted by Fredrik Björck on
Dear All,

Has anybody managed to use the PDFlib with OpenACS and AOLserver (RH Linux 8.0)? I have been trying for two days, but can't really get it to work. PDFlib works really fine and creates very nice PDF output fast from tcl-scripts (example code for tcl is included in the pdflib files. For example, I write "tclsh hello.tcl" and abrakadabra - there it goes "hello.pdf" is created. But when trying to do the same thing from a web page on OpenACS/AOLserver, it returns error that it "can't find the package pdflib 4.0". This happens at it tries to execure the "package require pdflib 4.0" command within the hello.tcl script. I tried (and managed - at least no errors) to load pdflib as a module in AOLserver, but it still does not work.

I admit, I am a newbie.

Any ideas anyone? Maybe it is the hello.tcl script that is something wrong with to run it from a web page?

I have checked out the HOWTO thing for OpenACS and PDF in this thread, but it looks a bit complicated to have Python scripts when everything else is based on tcl.

Any help or ideas would be appreciated. My objective is, of course, to be able to generate PDF-files on the fly from database content and serve the over the web using tcl scripts.

All the best,

/Fredrik Björck

Here's the hello.tcl I am trying to run from the web (the only file - do I need also an ADO-file or html file or something?

# $Id: hello.tcl,v 2002/01/22 19:49:34 tm Exp $
# PDFlib client: hello example in Tcl

# Hide the exec to Tcl but not to the shell by appending a backslash\
exec tclsh "$0" ${1+"$@"}

# The lappend line is unnecessary if PDFlib has been installed
# in the Tcl package directory

# package require pdflib 4.0

set p [PDF_new]

if {[PDF_open_file $p "hello.pdf"] == -1} {
    puts stderr "Couldn't open PDF file!"

PDF_set_info $p "Creator" "hello.tcl"
PDF_set_info $p "Author" "Thomas Merz"
PDF_set_info $p "Title" "Hello world (Tcl)"

PDF_begin_page $p 595 842

# Change "host" encoding to "winansi" or whatever you need!
set font [PDF_findfont $p "Helvetica-Bold" "host" 0 ]

PDF_setfont $p $font 18.0

PDF_set_text_pos $p 50 700
PDF_show $p "Hello world!"
PDF_continue_text $p "(says Tcl)"
PDF_end_page $p
PDF_close $p

PDF_delete $p

Posted by Fredrik Björck on
In the printout of the hello.tcl file above, "require package" is commented out - I have tried both with and without the #, and it is the same result - can not find package. /F
Posted by Dev eloper on
If you do not want to have to program your application to handle conversion from html to pdf, then you can look at a web service offered by Gilgamesh Solutions at Using this service you will be able to send a URL to an html page you build on the fly on your server, and the service will actually crawl over your URL and convert your page to pdf!

You can control many options including footers, headers, page breaks, page orientation (landscape vs. portrait), include high quality images (png, jpg, gif). The beauty about this service is that you are able to control the format of your generated pdf using html tags!

If you have a coldfusion server, then you can actually buy the product for around $60 I believe. But you might want to go with the service option if you do not want to deal with installation, setting up your application, worrying about changing your application when you upgrade, if you use different languages and you want an application that is platform and web server independent.

Give it a try, I believe that they have test environments on their web site where you can try their products live for free.

Posted by Michel Henry de Generet on
openreport is another opensource tool to generate PDF on the fly.
Posted by Brian Fenton on

sorry to bump such an old thread, but I'm wondering what the current best practice for creating PDFs from OpenACS is? My requirements include must work on Windows and Linux, should be able to convert Microsoft Word, Excel and HTML. Also the ability to concatenate various documents into one PDF would be good.

Any suggestions?

many thanks