import
org.apache.pdfbox.pdmodel.
PDDocument
;
import
org.apache.pdfbox.pdmodel.
PDPage
;
import
org.apache.pdfbox.rendering.
ImageType
;
import
org.apache.pdfbox.rendering.
PDFRenderer
;
import
org.apache.pdfbox.tools.imageio.
ImageIOUtil
;
public
class
ConvertToImage
{
public
static
void
main (
String
[] args)
throws
Exception
{
PDDocument
doc =
PDDocument
.load(
new
File
(args[
0
]));
PDFRenderer
pdfRenderer =
new
PDFRenderer
(doc);
int
pageCounter =
0
;
for
(
PDPage
page : doc.getPages())
BufferedImage
bi = pdfRenderer.renderImageWithDPI(pageCounter,
300
,
ImageType
.RGB);
ImageIOUtil
.writeImage(bi, args[
0
]+
"-"
+(pageCounter++)+
".png"
,
300
);
doc.close();
CodeSnippets