-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a method to get s3 object as file, add utils to parse pdf file to…
… text.
- Loading branch information
Joel Balcaen
committed
Apr 3, 2024
1 parent
dfc6d45
commit 9226a22
Showing
4 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...uestProcessorFunction/src/main/java/com/levio/awsdemo/formrequestprocessor/utils/PDF.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.levio.awsdemo.formrequestprocessor.utils; | ||
|
||
import org.apache.pdfbox.cos.COSDocument; | ||
import org.apache.pdfbox.io.RandomAccessRead; | ||
import org.apache.pdfbox.pdfparser.PDFParser; | ||
import org.apache.pdfbox.pdmodel.PDDocument; | ||
import org.apache.pdfbox.text.PDFTextStripper; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
|
||
public class PDF { | ||
|
||
public static String generateTextFromPDF(File file) throws IOException { | ||
String parsedText; | ||
PDFParser parser = new PDFParser((RandomAccessRead) new RandomAccessFile(file, "r")); | ||
parser.parse(); | ||
|
||
COSDocument cosDoc = parser.parse().getDocument(); | ||
PDFTextStripper pdfStripper = new PDFTextStripper(); | ||
PDDocument pdDoc = new PDDocument(cosDoc); | ||
parsedText = pdfStripper.getText(pdDoc); | ||
|
||
return parsedText; | ||
} | ||
} |