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 8350735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:24:50+00:00 2026-06-09T08:24:50+00:00

how we can convert a pdf file to single jpeg? now i have using

  • 0

how we can convert a pdf file to single jpeg? now i have using following code to convert to different images..but how i can acheive as a single jpeg image
package packagename;

import antlr.ByteBuffer;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Praveen
*/
public class Pdf2ImageCon extends HttpServlet {

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String pdfname="C:/san.pdf";
    try {
        BufferedImage img=null;

        File file = new File(pdfname);
    RandomAccessFile raf;
    try {
        raf = new RandomAccessFile(file, "r");
        FileChannel channel = raf.getChannel();
        MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
        PDFFile pdffile = new PDFFile(buf);
        // draw the first page to an image
        int num = pdffile.getNumPages();

int length;
length=num;
        for (int i = 0; i <= num; i++) {
            PDFPage page = pdffile.getPage(i);
            //get the width and height for the doc at the default zoom
            int width = (int) page.getBBox().getWidth();
            int height = (int) page.getBBox().getHeight();
            Rectangle rect = new Rectangle(0, 0, width, height);
            int rotation = page.getRotation();
            Rectangle rect1 = rect;
            if (rotation == 180) {
                rect1 =
new Rectangle(0, 0, rect.height, rect.width);
            }
            //generate the image


                    img = (BufferedImage) page.getImage(
                    rect.width, rect.height, //width & height
                    rect1, // clip rect
                    null, // null for the ImageObserver
                    true, // fill background with white
                    true // block until drawing is done
                    );

        }
        ImageIO.write(img, "png", new File("C:\\newone.png"));
    } catch (FileNotFoundException e1) {
        System.err.println(e1.getLocalizedMessage());
    } catch (IOException e) {
        System.err.println(e.getLocalizedMessage());
    }



    } finally {
        out.close();
    }
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
 * Handles the HTTP <code>GET</code> method.
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
    processRequest(request, response);
}

/**
 * Handles the HTTP <code>POST</code> method.
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
    processRequest(request, response);
}

/**
 * Returns a short description of the servlet.
 * @return a String containing servlet description
 */

public String getServletInfo() {
    return "Short description";
}// </editor-fold>

}

with this each of a pdf file page generates a new jpeg image. how i can get a single jpeg / png out of a pdf file

  • 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-09T08:24:53+00:00Added an answer on June 9, 2026 at 8:24 am

    JPEG is not a multi-page image format (whereas for example TIFF is, or animated GIF).

    • So what exactly do you want?
    • “Tile” all the PDF pages into one huge JPEG?

    If you want, for example, to tile the first 12 pages of the official ISO 3200_2008 PDF-1.7 specification in 4 columns and 3 rows (‘4×3’) with 2 pixels extra spacing between each of the pages), run this ImageMagick command:

    montage \
       http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf[1-12] \
      -tile 4x3 -geometry +2+2 \
      -background white \
       tiled.png
    

    It shouldn’t be a problem for you to translate that into your code.

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

Sidebar

Related Questions

I have a PDF file that I want to convert to PowerPoint using .NET.
i am using Imagemagick for converting my .pdf file to .png images but when
Can I convert a pdf to pcl file with ghostscript? I'm using Ghostscript 9.01
I need to convert a pdf file into a jpeg using C#. And the
How can I convert each pages of a PDF's file in C#, using free
i want to convert my webpage(displayed in UIWebView) contents in pdf file. which can
We have a project where we need to convert the following file types to
I want to convert .pdf file to .png file using Imagemagick php API. we
I receive a binary pdf file, which is base64Binary encoded. How can I convert
i am trying to read a html file and convert it to pdf using

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.