We can parse PDF files using Apache PDFBox
Just Add the dependency of Apache PDFBox in pom.xml
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.9</version>
</dependency>
Sometimes if you are getting error download following dependencies as well
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.9</version>
</dependency>
Run the Sample below program to read the PDF (Unprotected)
E-Ticket
Paytm Booking ID : 4134491696
Booked on: 14 Nov 2017 09:35 PM
Customer Care
7053111905
Paytm Flight Support
7053111905
24X7 Care
paytm.com/care
*Always carry ticket and your ID proof while travelling
One97 Communications Limited, B 121, Sector 5, Noida - 201301
How to Read Password Encrypted PDF (Protected PDF)
Just Add the dependency of Apache PDFBox in pom.xml
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.9</version>
</dependency>
Sometimes if you are getting error download following dependencies as well
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk15on</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.9</version>
</dependency>
Run the Sample below program to read the PDF (Unprotected)
package com.neeraj.test.neeraj;
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.pdfbox.text.PDFTextStripperByArea;
public class PDFParser {
public static void main(String[] args) throws InvalidPasswordException, IOException {
try (PDDocument document = PDDocument.load(new File("C:\\Users\\bakhtani\\Downloads\\ticket_3057779845.pdf"))) {
document.getClass();
if (!document.isEncrypted()) {
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
stripper.setSortByPosition(true);
PDFTextStripper tStripper = new PDFTextStripper();
String pdfFileInText = tStripper.getText(document);
//System.out.println("Text:" + st);
// split by whitespace
String lines[] = pdfFileInText.split("\\r?\\n");
for (String line : lines) {
System.out.println(line);
if(line.contains("Neeraj")){
System.out.println("Neeraj is there");
System.out.println(line);
}
}
}
}
}
}
OutputE-Ticket
Paytm Booking ID : 4134491696
Booked on: 14 Nov 2017 09:35 PM
Customer Care
7053111905
Paytm Flight Support
7053111905
24X7 Care
paytm.com/care
*Always carry ticket and your ID proof while travelling
One97 Communications Limited, B 121, Sector 5, Noida - 201301
How to Read Password Encrypted PDF (Protected PDF)
package com.neeraj.test.neeraj;
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
import org.apache.pdfbox.text.PDFTextStripper;
public class PDFParser {
public static void main(String[] args) throws InvalidPasswordException, IOException {
try (PDDocument document = PDDocument.load(new File("C:\\Users\\bakhtani\\Downloads\\EAadhaar_285091794512_07122017141237_873152.pdf"), "password")) {
document.setAllSecurityToBeRemoved(true);
PDFTextStripper reader = new PDFTextStripper();
String pageText = reader.getText(document);
System.out.println(pageText);
} catch (IOException e){
System.err.println("Exception while trying to read pdf document - " + e);
}
}
}
it doesn't work, asshole!!!
ReplyDeletehttps://bayanlarsitesi.com/
ReplyDeleteCihangir
Heybeliada
Yalova
Adana
SLH
Eskişehir
ReplyDeleteAdana
Sivas
Kayseri
Samsun
2LXİOE
451B9
ReplyDeleteNiğde Parça Eşya Taşıma
Bilecik Evden Eve Nakliyat
Konya Evden Eve Nakliyat
Afyon Evden Eve Nakliyat
Artvin Lojistik
08CE2
ReplyDeleteKaraman Şehirler Arası Nakliyat
Iğdır Parça Eşya Taşıma
Giresun Lojistik
Maraş Evden Eve Nakliyat
Bingöl Şehir İçi Nakliyat
Ünye Fayans Ustası
Kırşehir Şehirler Arası Nakliyat
Etimesgut Fayans Ustası
Bitmex Güvenilir mi
8333F
ReplyDeleteorder anapolon oxymetholone
Isparta Evden Eve Nakliyat
Çorum Evden Eve Nakliyat
Niğde Evden Eve Nakliyat
buy masteron
steroid cycles
order steroid cycles
Şırnak Evden Eve Nakliyat
Hatay Evden Eve Nakliyat
DE2B2
ReplyDeleteBitlis Lojistik
Kaspa Coin Hangi Borsada
Iğdır Parça Eşya Taşıma
Uşak Şehir İçi Nakliyat
İstanbul Şehir İçi Nakliyat
Sakarya Şehirler Arası Nakliyat
Adıyaman Şehirler Arası Nakliyat
Ünye Boya Ustası
Siirt Parça Eşya Taşıma
شركة مكافحة النمل الابيض بالدمام Rt8hfoL7NJ
ReplyDelete