Good afternoon,
I'm trying to create a PDF file with pdBox, recording what it finds in the matcher of my application, but the created pdf goes blank Could anyone help me with this question?
PDFParser parser = new PDFParser(new RandomAccessBufferedFileInputStream(f.getAbsolutePath()));
parser.parse();
COSDocument cosDoc = parser.getDocument();
PDFTextStripper pdfStripper = new PDFTextStripper();
PDDocument pdDoc = new PDDocument(cosDoc);
PrintWriter arq = new PrintWriter(new File("C:\Tratados\" + f.getName())); //Diretório de saida
//PrintWriter gravarArq = new PrintWriter(arq);
List<String> linhasGravadas = new ArrayList<>();
for (int i = 1; i <= pdDoc.getNumberOfPages(); i++) {
pdfStripper.setStartPage(i);
pdfStripper.setEndPage(i);
String parsedText = pdfStripper.getText(pdDoc);
String aut = "";
String hora = "";
String data = "";
int Aut = 0, Data = 0, Hora = 0;
System.out.println("Pagina: " + i);
arq.println("Pagina: " + i);
Matcher matcherData = Pattern.compile("([0-9]{2}\/[0-9]{2}\/[0-9]{4})"/*"\b\d{8}\b"*/).matcher(parsedText);
Matcher matcherHora = Pattern.compile("\d{2}[:|;]\d{2}[:|;]\d{2}").matcher(parsedText);
Matcher matcherAut = Pattern.compile(/*"\s\b\d{9}\b|*/"\b\d{9}\b").matcher(parsedText);
int vAut = 0, vData = 0, vHora = 0;
if (!matcherAut.find()) {
System.out.println("Autorização: Não encontrado");
//arq.println("Autorização: Não encontrado");
} else {
//while (matcherAut.find()) {
Pattern pattern = Pattern.compile("\s^[0126789].*|^[0126789].*"); // Segundo Filtro (Elimina os que não começam com 3|4)
Scanner scanner = new Scanner(matcherAut.group()).useDelimiter(pattern);
Matcher matcher2 = pattern.matcher(aut);
while (scanner.hasNext()) {
aut = scanner.next();
if (!linhasGravadas.contains(aut)) {
System.out.println("Autorização: " + matcherAut.group());
arq.println("Autorização: " + matcherAut.group());
Aut = Aut + 1;
}
}
//}
}