從 PDF 中提取文字

作為IronPDF廣泛的PDF創建和編輯功能的一部分,IronPDF還透過其內容提取方法促進對PDF文件內容的細粒度處理。

在所有PdfDocument對象上都提供extractAllText方法。 extractAllText 返回的 String 包含 PDF 中每一頁的所有文字。

此方法是一種方便的方式,可從包含多頁的PDF文檔中進行文檔級別的文字提取。 若要在頁面層級提取文本(即僅從特定的一組頁面),請改用extractTextFromPage方法。

下面的簡短代碼片段用於提取PDF文件第一頁的文本。

PdfDocument document = PdfDocument.fromFile(Paths.get("sample.pdf"));  
String firstPageText = document.extractTextFromPage(PageSelection.firstPage());
PdfDocument document = PdfDocument.fromFile(Paths.get("sample.pdf"));  
String firstPageText = document.extractTextFromPage(PageSelection.firstPage());
JAVA