Meaningless Drivel is fun!
The moose likes Other Open Source Projects and the fly likes how to renders password procatacted pdf file into image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "how to renders password procatacted pdf file into image" Watch "how to renders password procatacted pdf file into image" New topic

how to renders password procatacted pdf file into image

Arvind Gangwar
Ranch Hand

Joined: Mar 25, 2010
Posts: 37


i have a task to renders password protected pdf file into thumbnails image, I did it with out password protected but unsuccessful when a pdf is password protected.
My old code is

<%@page import="com.sun.pdfview.PDFFile, com.sun.pdfview.PDFPage" %>
<%@page import="java.awt.Image, java.awt.Rectangle" %>
<%@page import="java.awt.Graphics2D, java.awt.image.BufferedImage"%>
<%@page import="java.nio.ByteBuffer, java.nio.channels.FileChannel" %>
<%@page import="*, javax.imageio.ImageIO" %>
<head><title>Image Rendering</title></head>

File file = new File("D:\\Tomcat 5.5\\webapps\\ROOT\\PDF_Test\\R-intro.pdf");
RandomAccessFile raf = new RandomAccessFile(file, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf =, 0, channel.size());
PDFFile pdffile = new PDFFile(buf);

// draw the first page to an image
PDFPage dpage = pdffile.getPage(0);

//get the width and height for the doc at the default zoom
Rectangle rect = new Rectangle(0,0, (int)dpage.getBBox().getWidth(), (int)dpage.getBBox().getHeight());
BufferedImage bufferedImage = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB);

//generate the image
Image img = dpage.getImage(
rect.width, rect.height, //width & height
rect, // clip rect
null, // null for the ImageObserver
true, // fill background with white
true // block until drawing is done



Graphics2D bufImageGraphics = bufferedImage.createGraphics();
bufImageGraphics.drawImage(img, 0, 0, null);
ImageIO.write(bufferedImage, "jpg", new File("D:\\Tomcat 5.5\\webapps\\ROOT\\PDF_Test\\Image.jpg" ));

OutputStream strm = response.getOutputStream();


strm.close(); */
<%="Pdf is renders into jpg image which save to location at D:\\Tomcat5.5\\webapps\\ROOT\\PDF_Test\\R-intro.jpg" %>


Any suggestion is welcome.

Arvind Gangwar
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Please use code tags for your code

Learning and Learning!-- Java all the way!
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Some (presumably newer) versions of the PDFFile class have methods that allow you to pass in passwords. You can find a recent version linked on the AccessingFileFormats page.
I agree. Here's the link:
subject: how to renders password procatacted pdf file into image
It's not a secret anymore!