File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

how to renders password procatacted pdf file into image

Arvind Gangwar
Ranch Hand

Joined: Mar 25, 2010
Posts: 37

Hi,

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="java.io.*, javax.imageio.ImageIO" %>
<html>
<head><title>Image Rendering</title></head>
<body>
<%

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 = channel.map(FileChannel.MapMode.READ_ONLY, 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" ));
/*response.setContentType("image/png");

OutputStream strm = response.getOutputStream();

ImageIO.write(bufferedImage,"png",strm);

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





</body>
</html>



Any suggestion is welcome.


Arvind Gangwar
OCPJP 6
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
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to renders password procatacted pdf file into image
 
Similar Threads
Placing text into a BufferedImage
Painting Not on the Screen
Question about drawimage
How can i have the coordinate on a buffered image ?
how do i capture screenshot via network in java swing