-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadPDF.java
More file actions
31 lines (21 loc) · 863 Bytes
/
ReadPDF.java
File metadata and controls
31 lines (21 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.pdf.ravishankarcode;
import java.io.IOException;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.canvas.parser.PdfTextExtractor;
public class ReadPDF {
public static final String READ_PDF = "C:\\temp\\hello.pdf";
public static void main(String[] args) throws IOException {
// PDFReader
PdfReader reader = new PdfReader(READ_PDF);
PdfDocument pdfDoc = new PdfDocument(reader);
// get the number of pages in PDF
int noOfPages = pdfDoc.getNumberOfPages();
for(int i = 1; i <= noOfPages; i++) {
// Extract content of each page
String contentOfPage = PdfTextExtractor.getTextFromPage(pdfDoc.getPage(i));
System.out.println(contentOfPage );
}
pdfDoc.close();
}
}