views:

138

answers:

5

I've a daunting task of getting familiair and possibly re-architecting large pieces of old source code.

I was hoping there would be a nice tool to convert php (in my case), but let's make it more general: any language to PDF, for offline browsing on a Kindle or Ipad

Would be ideal if it would create indexes / hyperlinks automatically. So function calls can be easily browsed into

A: 

highlight_file() + FPDF

Col. Shrapnel
+1  A: 

Enscript is probably a good choice. I don't think it has PDF output, but it can output to PostScript and that is trivial to convert to PDF.

I usually use it to produce nicely formatted code print outs with line numbers and alternate line highlighting for code reviews.

   -E[lang], --highlight[=lang]
           Highlight source code by creating a special input  filter  with
           the  states  program.  The optional argument lang specifies the
           language to highlight.  As a default the states makes  an  edu-
           cated guess.

           You can print a short description of the supported highlighting
           languages and file formats with the command:

           enscript --help-highlight

           The    highlighting    rules     are     defined     in     the
           `/usr/share/enscript/st/*.st' files which can be edited to cre-
           ate highlighting definitions for new languages.
David Dorward
"There is a unix commandline tool for that!" ;^) Just reading the manpage (I 've found it on my mac) but except for syntax highlighting, it doesn't seem language aware right? So hyperlinks / table of contents are not done?
Toad
I've copied the bit about highlighting into my answer. It doesn't do a TOC or links I'm afraid.
David Dorward
+2  A: 

I would actually recommend you not do this and go through the code by documenting each function/spaghetti string/class/object and drawing a map of the program flow, that is, if you true goal is to understand the code rather than put it on a kindle and read through 300 lines/hour (12 000 lines in one work week).

I use notepad++ and run some regex searches to find refactorable code, then in the other window I have DIA open to map out functions and classes. I find it to be much faster and efficient use of my time.

I was recently given a plate of spaghetti to figure out, and found this worlds better than reading line-by-line would ever be. But it's still up to you. The other answers do the PDF conversion flawlessly.

I think I tend to agree with you. Good point. However, to just be able to browse through it on the couch to try and get a highlevel overview might be worth something
Toad
A: 

If you have cygwin or a unix system you can:

cat file.php | a2ps -1 -o - | ps2pdf - file.pdf

There are some page formatting options you can play with also to suit your needs. See the man pages for a2ps and ps2pdf for more information.

Amardeep
[UUOC](http://everything2.com/title/Useless+Use+of+Cat) : a2ps can read file.php itself.
Stephen P
Yes, thanks. That's out of habit because I usually process piped data through that pair of utilities.
Amardeep
according to the manual, it can not handle php files. (at least pretty print them).If it doesn't do any intelligent parsing, I could just as well print the raw ascii ;^)
Toad
A: 

For documentation purposes I usually prefer the lstlistings package for (pdf)LaTeX. Just setup your document in a style you like and then either paste the code into it, or reference it from another file.

Also, pygments (pygmentize) is useful. You could convert your files to LaTeX (again!) or rtf, html, etc. and print that to PDF with whatever tool you prefer.

zerm