HTML Becomes PDF - Page 3
August 28, 2000
As you've probably guessed by now, we're going to create PDF output by
converting HTML into PDF. This is not a perfect solution, for several
reasons:
- Unless our Perl script has already been coded to produce HTML output, this
could be seen as a circuitous extra step.
- The HTMLDOC program does not always yield perfect reproductions of HTML
pages, especially very complex pages. It also does not yet support style
sheets.
- Integrating HTMLDOC into our Perl scripts will require making a system
call, which costs us some processing time.
We proceed nonetheless, because HTMLDOC also offers several palpable
advantages for generating PDF output from Perl back-end scripts:
- Most such Perl scripts are already coded to produce HTML output.
- Developers working with Perl as a back-end to web sites are likely more
familiar with HTML than PDF, and so simple formatting of results is much
quicker to implement with a known language (HTML) than an unknown (PDF).
- It gets the job done with the least development effort!
From the commandline, we can send a stream of HTML to HTMLDOC using a pipe,
while instructing HTMLDOC to return the results to standard output. We can
simply whip up a PDF file for a small web page as follows:
prompt> echo "<H2>Results</H2><TABLE><TR><TD>Score</TD><TD>95</TD></TR></TABLE>"
| htmldoc --webpage -t pdf - > resultTable.pdf
Note that in the example above we've line-wrapped the code at the pipe symbol
(|), but in reality the command is one long line. The logic: send the text
contained in the echo call to the htmldoc program, which accepts the
text as a web page and spits the PDF results out, which we redirect to the
file resultTable.pdf. Were we to open this masterpiece in Adobe Acrobat,
the results would gleam forth:

Skipping the Learning Curve - Page 2
The Perl You Need to Know
Enter the Perl - Page 4
|