ConvertPagesToImages convert = new ConvertPagesToImages ( "/path/to/file.pdf" );
try {
if ( convert . openPDFFile ()) {
for ( int page = 1 ; page <= convert . getPageCount (); page ++) {
final BufferedImage bi = convert . getPageAsImage ( page );
final File out = new File ( "/path/to/output/" + page + ".bmp" );
// Setters to control output
final BmpEncoderOptions options = new BmpEncoderOptions ();
JDeli . write ( bi , options , out );
}
}
} catch ( PdfException | IOException e ) {
e . printStackTrace ();
} catch ( Exception e ) {
e . printStackTrace ();
}
convert . closePDFfile ();
ConvertPagesToImages convert = new ConvertPagesToImages ( "/path/to/file.pdf" );
try {
if ( convert . openPDFFile ()) {
for ( int page = 1 ; page <= convert . getPageCount (); page ++) {
final BufferedImage bi = convert . getPageAsImage ( page );
final File out = new File ( "/path/to/output/" + page + ".gif" );
// Setters to control output
final GifEncoderOptions options = new GifEncoderOptions ();
JDeli . write ( bi , options , out );
}
}
} catch ( PdfException | IOException e ) {
e . printStackTrace ();
} catch ( Exception e ) {
e . printStackTrace ();
}
convert . closePDFfile ();
ConvertPagesToImages convert = new ConvertPagesToImages ( "/path/to/file.pdf" );
try {
if ( convert . openPDFFile ()) {
for ( int page = 1 ; page <= convert . getPageCount (); page ++) {
final BufferedImage bi = convert . getPageAsImage ( page );
final File out = new File ( "/path/to/output/" + page + ".heic" );
// Setters to control output
final HeicEncoderOptions options = new HeicEncoderOptions ();
JDeli . write ( bi , options , out );
}
}
} catch ( PdfException | IOException e ) {
e . printStackTrace ();
} catch ( Exception e ) {
e . printStackTrace ();
}
convert . closePDFfile ();
ConvertPagesToImages convert = new ConvertPagesToImages ( "/path/to/file.pdf" );
try {
if ( convert . openPDFFile ()) {
for ( int page = 1 ; page <= convert . getPageCount (); page ++) {
final BufferedImage bi = convert . getPageAsImage ( page );
final File out = new File ( "/path/to/output/" + page + ".jpg" );
// Setters to control output
final JpegEncoderOptions options = new JpegEncoderOptions ();
options . setQuality ( 90 ); // Default is 75. No compression is 100
JDeli . write ( bi , options , out );
}
}
} catch ( PdfException | IOException e ) {
e . printStackTrace ();
} catch ( Exception e ) {
e . printStackTrace ();
}
convert . closePDFfile ();
ConvertPagesToImages convert = new ConvertPagesToImages ( "/path/to/file.pdf" );
try {
if ( convert . openPDFFile ()) {
for ( int page = 1 ; page <= convert . getPageCount (); page ++) {
final BufferedImage bi = convert . getPageAsImage ( page );
final File out = new File ( "/path/to/output/" + page + ".jpx" );
// Setters to control output
final Jpeg2000EncoderOptions options = new Jpeg2000EncoderOptions ();
options . setOutputSubtype ( Jpeg2000OutputSubtype . JPX ); // Default is JPX. JP2 also
JDeli . write ( bi , options , out );
}
}
} catch ( PdfException | IOException e ) {
e . printStackTrace ();
} catch ( Exception e ) {
e . printStackTrace ();
}
convert . closePDFfile ();
ConvertPagesToImages convert = new ConvertPagesToImages ( "/path/to/file.pdf" );
try {
if ( convert . openPDFFile ()) {
for ( int page = 1 ; page <= convert . getPageCount (); page ++) {
final BufferedImage bi = convert . getPageAsImage ( page );
final File out = new File ( "/path/to/output/" + page + ".png" );
// Setters to control output
final PngEncoderOptions options = new PngEncoderOptions ();
options . setCompressionFormat ( PngCompressionFormat . NONE );
JDeli . write ( bi , options , out );
}
}
} catch ( PdfException | IOException e ) {
e . printStackTrace ();
} catch ( Exception e ) {
e . printStackTrace ();
}
convert . closePDFfile ();
ConvertPagesToImages convert = new ConvertPagesToImages ( "/path/to/file.pdf" );
try {
if ( convert . openPDFFile ()) {
for ( int page = 1 ; page <= convert . getPageCount (); page ++) {
final BufferedImage bi = convert . getPageAsImage ( page );
final File out = new File ( "/path/to/output/" + page + ".tiff" );
// Setters to control output
final TiffEncoderOptions options = new TiffEncoderOptions ();
options . setCompressionFormat ( TiffCompressionFormat . DEFLATE );
options . setResolutionUnit ( TiffResolutionUnit . INCH );
options . setXResolution ( 300 );
options . setYResolution ( 300 );
JDeli . write ( bi , options , out );
}
}
} catch ( PdfException | IOException e ) {
e . printStackTrace ();
} catch ( Exception e ) {
e . printStackTrace ();
}
convert . closePDFfile ();
ConvertPagesToImages convert = new ConvertPagesToImages ( "/path/to/file.pdf" );
try {
if ( convert . openPDFFile ()) {
for ( int page = 1 ; page <= convert . getPageCount (); page ++) {
final BufferedImage bi = convert . getPageAsImage ( page );
final File out = new File ( "/path/to/output/" + page + ".webp" );
// Setters to control output
final options = new ();
options . setQuality ( 90 ); // Default is 75. No compression is 100
options . setCompressionFormat ( WebpCompressionFormat . LOSSLESS ); // Also supports LOSSY
JDeli . write ( bi , options , out );
}
}
} catch ( PdfException | IOException e ) {
e . printStackTrace ();
} catch ( Exception e ) {
e . printStackTrace ();
}
convert . closePDFfile ();
// Disable all caching to file to reduce memory usage
PdfFileReader . alwaysCacheInMemory = - 1 ;
// bytes is a byte[] with the PDF file data
ConvertPagesToImages convert = new ConvertPagesToImages ( bytes );
// convert.setPassword("password"); // If password needed
try {
if ( convert . openPDFFile ()) {
int pageCount = convert . getPageCount ();
for ( int page = 1 ; page <= pageCount ; page ++) {
BufferedImage image = convert . getPageAsImage ( page );
}
}
} catch ( PdfException e ) {
e . printStackTrace ();
}
convert . closePDFfile ();