import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.edit.PageSelection;
import com.ironsoftware.ironpdf.image.ToImageOptions;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;
PdfDocument pdf = PdfDocument.fromFile(Paths.get("assets/composite.pdf"));
// Extract all the pages from the PDF file.
List<BufferedImage> extractedImages = pdf.toBufferedImages();
// With the ToImageOptions object, specify maximum image dimensions for each
// extracted image, as well as their DPI
ToImageOptions rasterOptions = new ToImageOptions();
rasterOptions.setImageMaxHeight(100);
rasterOptions.setImageMaxWidth(100);
// Call the toBufferedImage method along with a PageSelection object to choose the pages from which to
// extract the images
//
// Available PageSelection methods include: allPages, lastPage, firstPage, singlePage(int pageIndex),
// and pageRange(int startingPage, int endingPage)
List<BufferedImage> sizedExtractedImages = pdf.toBufferedImages(rasterOptions, PageSelection.allPages());
// Save all the extracted images to a file location
int i = 1;
for (BufferedImage extractedImage : sizedExtractedImages) {
String fileName = "assets/images/" + i++ + ".png";
ImageIO.write(extractedImage, "PNG", new File(fileName));
}
import com.ironsoftware.ironpdf.PdfDocument
import com.ironsoftware.ironpdf.edit.PageSelection
import com.ironsoftware.ironpdf.image.ToImageOptions
import javax.imageio.ImageIO
import java.awt.image.BufferedImage
import java.io.File
import java.io.IOException
import java.nio.file.Paths
import java.util.List
Dim pdf As PdfDocument = PdfDocument.fromFile(Paths.get("assets/composite.pdf"))
' Extract all the pages from the PDF file.
Dim extractedImages As List(Of BufferedImage) = pdf.toBufferedImages()
' With the ToImageOptions object, specify maximum image dimensions for each
' extracted image, as well as their DPI
Dim rasterOptions As New ToImageOptions()
rasterOptions.setImageMaxHeight(100)
rasterOptions.setImageMaxWidth(100)
' Call the toBufferedImage method along with a PageSelection object to choose the pages from which to
' extract the images
'
' Available PageSelection methods include: allPages, lastPage, firstPage, singlePage(int pageIndex),
' and pageRange(int startingPage, int endingPage)
Dim sizedExtractedImages As List(Of BufferedImage) = pdf.toBufferedImages(rasterOptions, PageSelection.allPages())
' Save all the extracted images to a file location
Dim i As Integer = 1
Do
'INSTANT VB WARNING: An assignment within expression was extracted from the following statement:
'ORIGINAL LINE: String fileName = "assets/images/" + i++ + ".png";
Dim fileName As String = "assets/images/" & i & ".png"
i += 1
ImageIO.write(extractedImage, "PNG", New File(fileName))
Loop