Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

how to renders password procatacted pdf file into image

Ranch Hand
Posts: 37
MyEclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tags for your code
Posts: 43028
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
It's exactly the same and completely different as this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic