Important alert: (current site time 7/15/2013 5:08:59 AM EDT)
 

article

Convert a Particular PDF Page or All PDF Pages to PNG Image Format

Email
Submitted on: 6/19/2013 10:04:32 PM
By: aspose_seo 
Level: Intermediate
User Rating: Unrated
Compatibility: Java (JDK 1.3), Java (JDK 1.4), Java (JDK 1.5)
Views: 1142
 
     This technical tip shows how to convert PDF pages to PNG Image using Aspose.Pdf for Java. Users can choose to convert a particular PDF page to PNG image or convert all PDF pages to PNG Images.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				This technical tip shows how to convert PDF pages to PNG Image using Aspose.Pdf for Java. Users can choose to convert a particular PDF page to PNG image or convert all PDF pages to PNG Images. In order to convert all page of PDF file to PNG format, you need to iterate through individual page and convert it to PNG format. The given code snippet shows you how to traverse through all the pages of PDF file and convert it to PNG image. The PngDevice class allows you to convert PDF pages to PNG images. This class provides a method named process(..) which allows you to convert a particular page of the PDF file to PNG image. You first need to create an object of Document class, so you could get the particular page which you want to convert to PNG. After that, you need to call the process(..) method to convert the page to PNG image.
Convert particular PDF page to PNG Image
[Java]
//open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("input.pdf");
// create stream object to save the output image
java.io.OutputStream imageStream = new java.io.FileOutputStream("Converted_Image.png");
//create Resolution object
com.aspose.pdf.Resolution resolution = new com.aspose.pdf.Resolution(300);
//create PngDevice object with particular resolution
com.aspose.pdf.PngDevice pngDevice = new com.aspose.pdf.PngDevice(resolution);
//convert a particular page and save the image to stream
pngDevice.process(pdfDocument.getPages().get_Item(1), imageStream);
//close the stream
imageStream.close();
Convert all PDF pages to PNG Images
[Java]
//open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("input.pdf");
// loop through all the pages of PDF file
for (int pageCount = 1; pageCount <= pdfDocument.getPages().size(); pageCount++)
{
// create stream object to save the output image
java.io.OutputStream imageStream = new java.io.FileOutputStream("Converted_Image" + pageCount + ".png");
 //create Resolution object
com.aspose.pdf.Resolution resolution = new com.aspose.pdf.Resolution(300);
//create PngDevice object with particular resolution
com.aspose.pdf.PngDevice pngDevice = new com.aspose.pdf.PngDevice(resolution);
//convert a particular page and save the image to stream
pngDevice.process(pdfDocument.getPages().get_Item(pageCount), imageStream);
//close the stream
imageStream.close();
}
 
Overview: Aspose.Pdf for Java
Aspose.Pdf is a Java PDF component to create PDF documents without using Adobe Acrobat. It supports Floating box, PDF form field, PDF attachments, security, Foot note & end note, Multiple columns document, Table of Contents, List of Tables, Nested tables, Rich text format, images, hyperlinks, JavaScript, annotation, bookmarks, headers, footers and many more. Now you can create PDF by API, XML and XSL-FO files. It also enables you to converting HTML, XSL-FO and Excel files into PDF.
More about Aspose.Pdf for Java
- Homepage of Aspose.Pdf is a Java: http://www.aspose.com/java/pdf-component.aspx 
- Read More Technical Tips by Aspose.Pdf is a Java at: http://www.aspose.com/docs/display/pdfjava/Working+with+com.aspose.pdf
- Download Aspose.Pdf is a Java: http://www.aspose.com/community/files/72/java-components/aspose.pdf-for-java/default.aspx 


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.