All, Looking for newbie help. I searhed the internet looking for examples to follow. What I want to do is write code to read a multipage pdf and convert to jpg (each page) and display on screen. I find way too much stuff that is either complicated or it is already a package. All I want is to be able to follow simple examples. Thanks.

Recommended Answers

All 9 Replies

you can use like this:

//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 + ".jpg");


//create Resolution object
com.aspose.pdf.Resolution resolution = new com.aspose.pdf.Resolution(300);
//create JpegDevice object where second argument indicates the quality of resultant image
com.aspose.pdf.JpegDevice jpegDevice = new com.aspose.pdf.JpegDevice(resolution, 100);
//convert a particular page and save the image to stream
jpegDevice.process(pdfDocument.getPages().get_Item(pageCount), imageStream);

//close the stream
imageStream.close();

ParPau: if you are a "newbie" in Java, then start at the beginning.

by copy-pasting code, you'll learn nothing except for just that: copy-pasting.

totally agree with you stultuske

Daemon - thanks for the first reply. I think I did find something like your example. My difficulty was the "com.aspose.pdf.Document" and not knowing how to import it. This is something with which I am not familiar. I'm trying to follow examples from my book and they don't show anything like this. As for Stultuske, thanks for the sarcasm. I took a programming class at the community college. What I am trying now is to finish the last few chapters on my own. During the course, I was able to cut and paste some snippets and modify them to fit the homework. I learned by example. Can you please take your comment and shove them in the same place as your 5-1/2" floppy and Apple 2e? Insulting people who are trying to learn doesn't get you points. Feel good ? You're a "posting expert" with comments like that ? Featured as well ? Says a lot about what Daniweb has to offer.

OK, cool it down folks.
stultuske is well known for saying what he thinks. If anyone doesn't like his posts then just ignore them.

Please don't get into a place where I have to infract anyone for violating the "Keep it Pleasant" rule.
Now, back to the original subject please.
JC

Aspose.Pdf may be a good solution, but the starting price of $799 may be a barrier to its use in this case! http://www.aspose.com/java/pdf-component/pricing.aspx

There are open source pdf libraries available - just Google. My guess is that you won't find a solution that is really simple code, so you'll probably have get into some code that's a bit beyond beginner level.

why go that way anyway... There's perfectly servicable libraries to show PDF documents in Swing (and I guess JavaFX) applications, as well as standard browser plugins to show them in web applications.

As Jwenting said there are free options such as iText, Apache PDFBox and others just search for them
Both of above mentioned libraries have very good documentation with plenty of examples and active communities to help out with issues one may face

The above post is an advertising. 1)pulled and old thread and 2)unrelating suggested solution.

commented: Thanks for the alert - action has been taken. +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.