Improve metadata handling

This commit is contained in:
Christian Tzolov
2024-02-23 22:41:28 +01:00
parent 8532cb7bcc
commit 433f820e8b
3 changed files with 6 additions and 8 deletions

View File

@@ -17,7 +17,6 @@
package org.springframework.ai.reader.pdf;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -58,7 +57,7 @@ public class PagePdfDocumentReader implements DocumentReader {
private PdfDocumentReaderConfig config;
private File resourceFileName;
private String resourceFileName;
public PagePdfDocumentReader(String resourceUrl) {
this(new DefaultResourceLoader().getResource(resourceUrl));
@@ -80,7 +79,7 @@ public class PagePdfDocumentReader implements DocumentReader {
new org.apache.pdfbox.io.RandomAccessReadBuffer(pdfResource.getInputStream()));
this.document = pdfParser.parse();
this.resourceFileName = pdfResource.getFile();
this.resourceFileName = pdfResource.getFilename();
this.config = config;
}
catch (Exception e) {

View File

@@ -17,7 +17,6 @@
package org.springframework.ai.reader.pdf;
import java.awt.Rectangle;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -65,7 +64,7 @@ public class ParagraphPdfDocumentReader implements DocumentReader {
private PdfDocumentReaderConfig config;
private File resourceFileName;
private String resourceFileName;
/**
* Constructs a ParagraphPdfDocumentReader using a resource URL.
@@ -108,7 +107,7 @@ public class ParagraphPdfDocumentReader implements DocumentReader {
this.paragraphTextExtractor = new ParagraphManager(this.document);
this.resourceFileName = pdfResource.getFile();
this.resourceFileName = pdfResource.getFilename();
}
catch (IllegalArgumentException iae) {
throw iae;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2023-2023 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class PagePdfDocumentReaderTests {
@Test
public void test1() {
public void classpathRead() {
PagePdfDocumentReader pdfReader = new PagePdfDocumentReader("classpath:/sample1.pdf",
PdfDocumentReaderConfig.builder()