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

  • SEARCH
  • Home
  • 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 8578203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:19:59+00:00 2026-06-11T20:19:59+00:00

I am using below code to convert PDF to PNG image. Document document =

  • 0

I am using below code to convert PDF to PNG image.

        Document document = new Document();
        try {
            document.setFile(myProjectPath);
            System.out.println("Parsed successfully...");
        } catch (PDFException ex) {
            System.out.println("Error parsing PDF document " + ex);
        } catch (PDFSecurityException ex) {
            System.out.println("Error encryption not supported " + ex);
        } catch (FileNotFoundException ex) {
            System.out.println("Error file not found " + ex);
        } catch (IOException ex) {
            System.out.println("Error handling PDF document " + ex);
        }

        // save page caputres to file.
        float scale = 1.0f;
        float rotation = 0f;

        // Paint each pages content to an image and write the image to file
        InputStream fis2 = null;
        File file = null;
        for (int i = 0; i < 1; i++) {
            BufferedImage image = (BufferedImage) document.getPageImage(i,
                    GraphicsRenderingHints.SCREEN,
                    Page.BOUNDARY_CROPBOX, rotation, scale);
            RenderedImage rendImage = image;
            // capture the page image to file
            try {
                System.out.println("\t capturing page " + i);
                file = new File(myProjectActualPath + "myImage.png");
                ImageIO.write(rendImage, "png", file);
                fis2 = new BufferedInputStream(new FileInputStream(myProjectActualPath + "myImage.png"));
            } catch (IOException ioe) {
                System.out.println("IOException :: " + ioe);
            } catch (Exception e) {
                System.out.println("Exception :: " + e);
            }
            image.flush();
        }

myProjectPath is the path of the pdf file.

The problem is that I have pdf image of size 305 KB. When I use above code to convert image, the image size is 5.5 MB which is unexpected. Any reason why this is happening? Is there way to compress this? If I get solution to compress the size (by making down the pixel size), it is also OK.

Note : For other pdf files, images are coming to 305 KB. This is happening with one PDF file and not sure why this is happening.

Edit 1

I am using jar files as

icepdf-core.jar
icepdf-viewer.jar

The import that I have are

import org.icepdf.core.exceptions.PDFException;
import org.icepdf.core.exceptions.PDFSecurityException;
import org.icepdf.core.pobjects.Document;
import org.icepdf.core.pobjects.Page;
import org.icepdf.core.util.GraphicsRenderingHints;
  • 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-06-11T20:20:00+00:00Added an answer on June 11, 2026 at 8:20 pm

    You could extract the images from the pdf (example using PDFBox):

        List<PDPage> pages = document.getDocumentCatalog().getAllPages();
        for(PDPage page : pages) {
            Map<String, PDXObjectImage> images = page.getResources().getImages();
    
            for(PDXObjectImage image : images.values()){
                //TODO: write image to disk
            }   
        }
    

    OR/AND you may want to save them as jpg to disk, as jpg overs compression as opposed to png.

    You could even identify the format of the orignal image and use that when writing to disk by calling:

    image.getSuffix();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using xpdf to convert pdf files to text. Below is the code
I am using below code DateTime dtt=new DateTime(); dtt = Convert.ToDateTime(FromDate); // DateTime dtt
I am using the below code for convert black and white image. Its working
I am using below code to get profile image of friends using Resfb. I
I am using the below code to convert a string to a date. I
I'm using the code below to convert meters to feet. It works like a
I am getting the value of input using javascript using below code. var name=document.getElementById(firstName).value;
I'm using the code below to convert the file size in bytes (test file
I am using wkhtmltopdf to convert HTML file into PDF document on a link
dr[po_amt].ToString() = 1,936.10; when i try to convert this to int32 using the below

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.