搜尋
首頁Javajava教程如何使用 PDFBox 將 PDF 檔案轉換為影像?

How to Convert PDF Files to Images with PDFBox?

使用PDFBox 將PDF 文件轉換為圖像

Apache PDFBox 提供了一套全面的工具用於操作PDF 文檔,包括將其轉換為圖像。透過使用 PDFBox,您可以有效地將 PDF 文件的各個頁面提取為單獨的圖像。

解決方案(版本1.8.*):

PDDocument document = PDDocument.loadNonSeq(new File(pdfFilename), null);
List<pdpage> pdPages = document.getDocumentCatalog().getAllPages();
int page = 0;
for (PDPage pdPage : pdPages)
{
    ++page;
    BufferedImage bim = pdPage.convertToImage(BufferedImage.TYPE_INT_RGB, 300);
    ImageIOUtil.writeImage(bim, pdfFilename + "-" + page + ".png", 300);
}
document.close();</pdpage>

解決方案(版本2.0):

PDDocument document = PDDocument.load(new File(pdfFilename));
PDFRenderer pdfRenderer = new PDFRenderer(document);
for (int page = 0; page 解決方案(版本2.0):<p><strong></strong></p><pre class="brush:php;toolbar:false">PDDocument document = Loader.loadPDF(new File(pdfFilename));
解決方案(3.0版):

記住設定日誌記錄並使用可用的最新JDK 版本。

以上是如何使用 PDFBox 將 PDF 檔案轉換為影像?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
爪哇可以到處跑嗎?爪哇可以到處跑嗎?May 07, 2025 pm 06:41 PM

Yes,Javacanruneverywhereduetoits"WriteOnce,RunAnywhere"philosophy.1)Javacodeiscompiledintoplatform-independentbytecode.2)TheJavaVirtualMachine(JVM)interpretsorcompilesthisbytecodeintomachine-specificinstructionsatruntime,allowingthesameJava

JDK和JVM有什麼區別?JDK和JVM有什麼區別?May 07, 2025 pm 05:21 PM

jdkincludestoolsfordEveloping and compilingjavacode,whilejvmrunsthecompiledbytecode.1)jdkcontainsjre,編譯器,andutilities.2)

Java功能:快速指南Java功能:快速指南May 07, 2025 pm 05:17 PM

Java的關鍵特性包括:1)面向對象設計,2)平台獨立性,3)垃圾回收機制,4)豐富的庫和框架,5)並發支持,6)異常處理,7)持續演進。 Java的這些特性使其成為開發高效、可維護軟件的強大工具。

Java平台獨立性解釋:綜合指南Java平台獨立性解釋:綜合指南May 07, 2025 pm 04:53 PM

JavaachievesPlatFormIndependencEthroughByTeCodeAndthejvm.1)sodiscompiledIntobyTecode,notmachinecode.2)thejvminterpretsbytbybytecodeonanyplatform,確保“ writeononce,runany where。”

平台獨立性如何使企業級的Java應用程序受益?平台獨立性如何使企業級的Java應用程序受益?May 03, 2025 am 12:23 AM

Java在企業級應用中被廣泛使用是因為其平台獨立性。 1)平台獨立性通過Java虛擬機(JVM)實現,使代碼可在任何支持Java的平台上運行。 2)它簡化了跨平台部署和開發流程,提供了更大的靈活性和擴展性。 3)然而,需注意性能差異和第三方庫兼容性,並採用最佳實踐如使用純Java代碼和跨平台測試。

考慮到平台獨立性,Java在物聯網(物聯網)設備的開發中扮演什麼角色?考慮到平台獨立性,Java在物聯網(物聯網)設備的開發中扮演什麼角色?May 03, 2025 am 12:22 AM

JavaplaysigantroleiniotduetoitsplatFormentence.1)itallowscodeTobewrittenOnCeandrunonVariousDevices.2)Java'secosystemprovidesuseusefidesusefidesulylibrariesforiot.3)

描述一個方案,您在Java中遇到了一個特定於平台的問題以及如何解決。描述一個方案,您在Java中遇到了一個特定於平台的問題以及如何解決。May 03, 2025 am 12:21 AM

ThesolutiontohandlefilepathsacrossWindowsandLinuxinJavaistousePaths.get()fromthejava.nio.filepackage.1)UsePaths.get()withSystem.getProperty("user.dir")andtherelativepathtoconstructthefilepath.2)ConverttheresultingPathobjecttoaFileobjectifne

Java平台獨立對開發人員有什麼好處?Java平台獨立對開發人員有什麼好處?May 03, 2025 am 12:15 AM

Java'splatFormIndenceistificantBecapeitAllowSitallowsDevelostWriTecoDeonCeandRunitonAnyPlatFormwithAjvm.this“ writeonce,runanywhere”(era)櫥櫃櫥櫃:1)交叉plat formcomplibility cross-platformcombiblesible,enablingDeploymentMentMentMentMentAcrAptAprospOspOspOssCrossDifferentoSswithOssuse; 2)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器