1
내 파일이 PDDocument 객체에로드되지 않는 이유를 알아내는 데 문제가 있습니다. 다음과 같이Java pdfbox 파일이로드되지 않습니다.
내 프로세스는 다음과 같습니다
- 열기 파일
- 과 디렉토리 PDDocument에 디렉토리
- 로드 파일에서 파일의 배열을 가져옵니다.
아래 코드를 참조하십시오.
public class Main {
public static void main(String[] args) throws IOException {
//open directory
File folder = new File("pdfs");
//Extract Files
File[] files = folder.listFiles();
//print out file names
for (File file:files) {
System.out.println(file.getName());
System.out.println("Can read?: " + file.canRead());
System.out.println("Can write?: " + file.canWrite());
}
//Load PDF
PDDocument firstDocument = new PDDocument();
try {
firstDocument.load(files[0]);
}
finally
{
if (firstDocument != null) {
firstDocument.close();
}
}
System.out.println("Num Pages: " + firstDocument.getNumberOfPages());
출력 :
EnterpriseArchitectInvoice.pdf
Can read?: true
Can write?: true
ooad_textbooks_invoice.pdf
Can read?: true
Can write?: true
Num Pages: 0
나는 PDF가 유효 함을 보장 할 수 있습니다.
도움 주셔서 감사합니다.
우수 감사합니다. – btbam91