import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.rendering.ImageType; import org.apache.pdfbox.rendering.PDFRenderer; import org.apache.pdfbox.tools.imageio.ImageIOUtil; public class PDFToImage { public PDFToImage() { } public static void main(String[] args) { try { PDDocument pdDocument = new PDDocument(); PDDocument oDocument = PDDocument.load(new File("docs/my_form.pdf")); PDFRenderer pdfRenderer = new PDFRenderer(oDocument); int numberOfPages = oDocument.getNumberOfPages(); for (int i = 0; i < numberOfPages; i++) { BufferedImage bim = pdfRenderer.renderImageWithDPI(i, 300, ImageType.RGB); String filename = "docs/my_form_image" + "_" + i + ".png"; ImageIOUtil.writeImage(bim, filename, 300); } pdDocument.close(); } catch (IOException e) { e.printStackTrace(); } } }
All one can think and do in a short time is to think what one already knows and to do as one has always done!
No comments:
Post a Comment
NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.