Hi,
This is the situation. I need to add PDF generation to a program that already has PNG generation. Initially the 2 classes involved are :
ActionUsuels
From where the constructor of CaptureImage3D
is called.
When I added the PDF generation I added a method at the CaptureImage3D
class.
Before adding the PDF generation, the PNG generation worked correctly. But now when I try to do the PNG generation, I get a : NoClassDefFoundError
: com/lowagie/text/DocumentException
.
I know it means that the class : DocumentException
(from the itext jar) can't be read from the classpath but :
- The PDF generation method is NEVER called.
- The exception is generated before entering the constructor of
CaptureImage3D
. - Consider the following PDF generation method:
Code:
public void captureImagePDF(File imageFile)
{
System.out.println("Pdf appelé");
// Dimension (en pixels) de l'image a sauvegarder dans le fichier
Dimension dim = new Dimension(512, 512);
// On recupere l'image (pixmap) rendue par le canvas 3D offscreen
BufferedImage myBufferedImage = offScreenCanvas.getOffScreenImage(dim);
// On recupere le contexte graphique de l'image finale de sortie
Graphics2D gc = myBufferedImage.createGraphics();
gc.drawImage(myBufferedImage, 0, 0, null);
Document myPDF = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter myWriter = null;
try
{
myWriter = PdfWriter.getInstance(myPDF, new FileOutputStream(imageFile));
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (DocumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
myPDF.open();
PdfContentByte cb = myWriter.getDirectContent();
cb.saveState();
Image image = null;
try {
image = Image.getInstance(myBufferedImage,null);
}
catch (BadElementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
cb.addImage(image);
}
catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
When I comment all the try/catch blocs, everything works fine !!!
I repeat again: captureImagePDF is never called. And even the constructor of CaptureImage3D
is never accessed. (it should be, but the exception is raised before). And yes, I have itext in the classpath.
I find it weird the fact that a piece of code, that is never called anywhere, causes the apparition of the exception!
Don't hesitate to ask for clarifications!
Any idea?
Thank you