This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
- Read More Technical Tips by Aspose.Pdf
- Download Aspose.Pdf is a Java
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic