Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 592181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:42:45+00:00 2026-05-13T15:42:45+00:00

This is the situation. I need to add PDF generation to a program that

  • 0

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 :

  1. The PDF generation method is NEVER called.
  2. The exception is generated before entering the constructor of CaptureImage3D.
  3. 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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:42:46+00:00Added an answer on May 13, 2026 at 3:42 pm

    The fact that you have a catch for DocumentException means that the loader has to load the class, so that the system can catch it. 🙂

    If you want to avoid having to have the iText jar in your classpath, catch something higher up, or (like you said) don’t catch at all. 😛

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 342k
  • Answers 342k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here are a couple of ways to handle state in… May 14, 2026 at 5:17 am
  • Editorial Team
    Editorial Team added an answer Add the JRegistryKey.jar in the library. Then copy and paste… May 14, 2026 at 5:17 am
  • Editorial Team
    Editorial Team added an answer Which are you more comfortable with? Most people tend to… May 14, 2026 at 5:17 am

Related Questions

I have a situation where I need to increase the space between a table
The Situation (Ignore this it is boring): I have reports that I created using
Here is the situation: User looks something up. Alert sound is played because there
I have an app that shows store sales. It is a multi-dimensional array, so
I need to allow client users to extend the data contained by a JPA

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.