Reputation: 2523
I have to print the whole sourcecode of a java-project. The final version should look like: Eclipse: File -> Print. But with this function you can only print one file at once.
Is there a way to print (or create a pdf/rtf of) the whole project (all *.java, *.xml, ... files) with one command?
Im using eclipse galileo on windows xp sp3
EDIT: For each class/file the page should (more or less) look like this:
1 package utils.libraries;
2
3 import java.io.File;
9
10 /**
11 * @
12 * @
13 * @
14 */
15 public class LibraryExtractor {
16
17 /**
18 *
19 *
20 *
21 *
22 *
23 *
24 *
25 */
26 public static void extranctLibrary(String library, File targetFile) throws
IOException, URISyntaxException {
27 targetFile.getParentFile().mkdirs();
28 if (!targetFile.exists())
29 targetFile.createNewFile();
30
31 ClassLoader classLoader = LibraryExtractor.class.getClassLoader();
32 InputStream in = classLoader.getResourceAsStream(library);
33 OutputStream out = new FileOutputStream(targetFile);
34
35 byte[] buf = new byte[1024];
36 int len;
37
38 while ((len = in.read(buf)) > 0)
39 out.write(buf, 0, len);
40
41 in.close();
42 out.close();
43 }
44 }
45
SOLUTION:
Upvotes: 30
Views: 41762
Reputation: 630
http://sourceforge.net/projects/javasrc2pdf/?source=typ_redirect
This creates all the PDFs and with reasonably good syntax highlighting however they are all in separate files. But there are plenty of ways to combine pdfs out there
Upvotes: 1
Reputation: 70204
I've used Java2Html from Eclipse in the past. See whether it suits your needs.
Upvotes: 6
Reputation: 61705
If you want the formatting exactly as it is in Eclipse, then you will probably have to print from Eclipse. You'll spend more time trying to duplicate the print formatting that you have in Eclipse with another method.
Another important point: If you are using folding in the text editors in Eclipse, then the folded lines will not be displayed in the printed version.
If you really really have to furnish the source code as trees, then I would suggest that you try and persuade your clients that colour and syntax highlighting are not important, and then format everything in Eclipse, and print from elsewhere. There are suggestions for the line numbers etc in other answers.
Upvotes: 1
Reputation: 76067
An option that looks fancy is to use vim in batch mode to generate a bunch of colorized HTML files and then print by dragging all of them to the printer (I know that can be done, some time ago a colleague printed the whole J2SE API, and I hope she didn't it page by page xD).
find -name "*.java" -exec vim '+set nu' +TOhtml +wq +q '{}' \;
Upvotes: 1
Reputation: 11205
I would use pygments with linenos enabled as explained in http://pygments.org/docs/formatters/
Upvotes: 0
Reputation: 8157
If you can afford spending $50 buy Ultraedit, open all files and print it...
Ultraedit features about printing includes:
Upvotes: 7
Reputation: 39606
If you don't mind installing Cygwin, or running on Linux, the following command will do what you want:
enscript -r -2 --file-align=2 --highlight --line-numbers -o - `find . -name '*.java'` | ps2pdf - files.pdf
enscript is a program for converting text files to a variety of output formats; PostScript is the default, but you can also produce HTML, RTF, and a few others. The -r
option says to print in landscape, -2
is two columns per page (save trees), --file-align=2
says that each new file should start on its own physical page, --highlight
turns on language-specific syntax highlighting (it will try to figure out the language, or you can specify "java"), --line-numbers
should be obvious, and -o -
sends the output to standard-out (where it's piped to ps2pdf).
find generates the list of files; here I'm telling it to find all Java files under in the current directory. The output is passed as arguments to enscript; for "50-100 files" you should be OK, but you might need to read about xargs. You could get rid of the -name
argument to generate a list of all files, or add multiple -name
arguments to add more file types to the list; I wouldn't go with the "all files" approach, because then you'll get source-control files.
ps2pdf takes the PostScript output from enscript and converts it to PDF, which you can print.
Upvotes: 63
Reputation: 54605
I don't think you can do this within Eclipse (of course you could write a plugin which does this).
If you use Ant as your build tool you could use the concat
task and then print the resulting file
<concat destfile="${concat.src.dir}/concat.txt" force="no">
<filelist dir="${src.dir}" includes="**/*.java **/*.xml" />
</concat>
Upvotes: 3