IRONSOFTWAREHOME
Rasterize a PDF to Images

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));
}
mvn install
Rasterize a PDF to Images

Rasterize a PDF to Images

文件載入完成後,無論是從檔案中載入,還是從其他資源內容(網頁、URL、HTML 等)進行轉換,IronPDF 都能將 PDF 文件的頁面匯出為圖像,這些圖像可以儲存到檔案系統中,存放於資料庫內,或是通過網路傳送(以及其他用途)。

方法BufferedImage物件的集合。 每個PdfDocument單頁的圖像位元組內容。 此外,BufferedImage List是按頁碼遞增的順序排列。 開發人員可以在方法呼叫中包含一個List,用於包含 PDF 的頁面集。

特色程式碼範例建立了一個ToImageOptions物件,以設定圖像轉換後的預期寬度和高度。 這個類別還包括一個用於更改圖像輸出DPI的方法(setDpi)。 開發人員可以將此類的實例與PageSelection的實例一起使用,以同時控制 PDF 到圖像轉換的範圍、大小和質量。

如需了解有關 IronPDF 及其功能的更多資訊,您可以造訪IronPDF 文件和資源。

Learn more about the toBufferedImages method here.
在 GitHub 查看

準備好開始了嗎?

版本:2026.6剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰。

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

OR
bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
預訂您的免費 即時演示
Booking Badge

全球數百萬工程師的信任

Iron Software的客戶商標
獲取您的無義務諮詢
填寫以下表格或發送電子郵件至sales@ironsoftware.com
您的詳細資訊始終保持機密。
全球數百萬工程師的信任
Iron Software的客戶商標
立即獲取您的30天試用金鑰。
無需信用卡或帳戶建立
PDF的Java Maven程式庫
using Maven 安裝

版本: 2026.6

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.6.1</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.6.1
or
Java PDF JAR
下載 JAR

版本: 2026.6

手動安裝到您的專案中