Bonjour,

J'ai un projet. Ce projet consiste à réaliser une appli, capable de générer des fichiers CHM, PDF, et XHTML de documentations techniques d'un projet (Java, PHP ...)
Le concept est que j'aurais une classe de lecture de fichiers, une autre de lecture de projet (qui ne fait qu'appeler la première autant de fois qu'il y a de codes sources dans le projet), et trois autres qui se chargent d'écrire aux différents format (ces trois classe iméplementent une interface qui permet d'avoir les même nom de méthode partout).
J'attaque aujourd'hui à la partie PDF (à mon avis la plus facile).
Voici la classe de lecture de fichier
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.datalion.documentor.file;
 
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.Vector;
import java.util.regex.Pattern;
 
import com.datalion.documentor.writer.PDFWriter;
import com.lowagie.text.DocumentException;
 
public class FileReader 
{
	private static FileReader instance = null;
	private StringBuilder content;
	private String line;
	private Hashtable<String,String> comments;
	private Vector<Pattern> patterns;
	private BufferedReader br;
	/** Construct the FileReader
         * Set up the variables
         * You must called read(String URL) to fill in the objects
         */
	private FileReader()
	{
		this.content = new StringBuilder();
		this.line = null ;
		this.patterns = new Vector <Pattern>();
		this.patterns.add(Pattern.compile(Pattern.quote("/**"))); // begin comment
		this.patterns.add(Pattern.compile(Pattern.quote(".*?"))); // continue comment
		this.patterns.add(Pattern.compile(Pattern.quote("^.*@"))); // special comment
		this.patterns.add(Pattern.compile(Pattern.quote("*/$"))); // end comment
		this.comments = new Hashtable<String,String>();
		this.br = null;
	}
	private static FileReader getInstance()
	{
		if(FileReader.instance == null)
		{
			FileReader.instance = new FileReader();
		}
		return FileReader.instance;
	}
	/** Read a file and put all class comments in a vector
         * @param Path of the file
         */
	public void read(String URL)
	{
		try
		{
			br = new BufferedReader(new InputStreamReader(new FileInputStream(URL)));
			while ((line = br.readLine()) != null) 
			{
				content.append("\n").append(line);
				if(this.patterns.get(0).matcher(line).find())
				{
					this.comments.put("Method",line);
				}
				if(this.patterns.get(1).matcher(line).find())
				{
					this.comments.put("Other",line);
				}	
				if(this.patterns.get(2).matcher(line).find())
				{
					this.comments.put("Flag",line);
				}
				if(this.patterns.get(3).matcher(line).find())
				{
					this.comments.put("End",line);
				}
				System.out.println(line);
			}
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			return;
		} 
		finally 
		{
			try 
			{
				br.close();
			} 
			catch (IOException e) {
				e.printStackTrace();
				br = null;
			}
		}
	}
	public Hashtable<String,String> getComments()
	{
		return this.comments;
	}
}
et la classe d'écriture de fichier PDF
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.datalion.documentor.writer;
 
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
 
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
 
public class PDFWriter implements isWriter
{
	private static PDFWriter instance = null;
	private Document doc;
	private PDFWriter()
	{
		this.doc = new Document();
	}
	public static PDFWriter getInstance()
	{
		if(PDFWriter.instance == null)
		{
			PDFWriter.instance = new PDFWriter();
		}
		return PDFWriter.instance;
	}
	public void createFile(String URL) throws FileNotFoundException, DocumentException
	{
		PdfWriter.getInstance(this.doc, new FileOutputStream(URL));
	}
	public void openFile()
	{
		PDFWriter.instance.doc.open();
	}
	public void declareMethod(String name) throws DocumentException 
	{
		PDFWriter.instance.doc.add(new Paragraph(name));	
	}
	public void closeFile()
	{
		PDFWriter.instance.doc.close();
	}
}
mais quand je l'execute, j'ai une erreur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
Exception in thread "main" ExceptionConverter: java.io.IOException: The document has no pages.
	at com.lowagie.text.pdf.PdfPages.writePageTree(Unknown Source)
	at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
	at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
	at com.lowagie.text.Document.close(Unknown Source)
	at com.datalion.documentor.writer.PDFWriter.closeFile(PDFWriter.java:41)
	at com.datalion.documentor.file.FileReader.main(FileReader.java:36)
pourtant la méthode closeFile() ne fait que fermer le fichier PDF. il paraitrait que je n'ai pas de numéro de page sur mon PDF et que c'est donc normal ?