質問編集履歴
2
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,14 +1,4 @@
|
|
1
|
-
提示コードですが
|
1
|
+
提示コードですがPDDcoument docuoment = new PDDocument();の行で下記のエラーでます。なぜでしょうか?パスは提示画像の通り通したのですが原因がわかりません。ライブラリがないと言われているみたいですが。
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
######試したこと
|
8
|
-
|
9
|
-
サイトよりApache Commons Logging 1.2をダウンロードしてパスを通しました。
|
10
|
-
|
11
|
-
https://commons.apache.org/proper/commons-logging/download_logging.cgi
|
12
2
|
|
13
3
|
|
14
4
|
|
@@ -16,41 +6,49 @@
|
|
16
6
|
|
17
7
|
|
18
8
|
|
19
|
-
|
9
|
+
利用ライブラリ: pdfbox
|
20
10
|
|
21
|
-
|
11
|
+
利用IDE: eclipse
|
22
12
|
|
23
13
|
|
24
14
|
|
25
|
-
|
15
|
+
参考サイト: https://technicalnote.hatenablog.com/entry/2019/01/28/080138
|
26
16
|
|
27
|
-
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
|
28
|
-
|
29
|
-
at org.apache.pdfbox.pdmodel.PDDocument.<clinit>(PDDocument.java:98)
|
30
|
-
|
31
|
-
at Main.main(Main.java:57)
|
32
|
-
|
33
|
-
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
|
34
|
-
|
35
|
-
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
|
36
|
-
|
37
|
-
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
|
38
|
-
|
39
|
-
|
17
|
+
参考サイト: https://try2explore.com/questions/jp/10757960
|
40
|
-
|
41
|
-
... 2 more
|
42
|
-
|
43
|
-
]
|
44
18
|
|
45
19
|
|
46
20
|
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
エラーコード
|
26
|
+
|
27
|
+
[
|
28
|
+
|
29
|
+
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/pdfbox/pdmodel/PDDocument
|
30
|
+
|
31
|
+
at Main.main(Main.java:11)
|
32
|
+
|
33
|
+
Caused by: java.lang.ClassNotFoundException: org.apache.pdfbox.pdmodel.PDDocument
|
34
|
+
|
35
|
+
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
|
36
|
+
|
37
|
+
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
|
38
|
+
|
39
|
+
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
|
40
|
+
|
41
|
+
... 1 more
|
42
|
+
|
43
|
+
]
|
44
|
+
|
45
|
+
![イメージ説明](bee7f359b7682d4772771ab0691fa156.png)
|
46
|
+
|
47
|
+
![イメージ説明](8e12b608a33471d195d28d75d568a1b3.png)
|
48
|
+
|
47
49
|
```java
|
48
50
|
|
49
|
-
import java.io.
|
51
|
+
import java.io.IOException;
|
50
|
-
|
51
|
-
import java.util.*;
|
52
|
-
|
53
|
-
|
54
52
|
|
55
53
|
|
56
54
|
|
@@ -58,169 +56,43 @@
|
|
58
56
|
|
59
57
|
import org.apache.pdfbox.pdmodel.PDPage;
|
60
58
|
|
61
|
-
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
62
59
|
|
63
|
-
import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
64
60
|
|
61
|
+
public class Main {
|
62
|
+
|
65
|
-
i
|
63
|
+
public static void main(String args[]) {
|
64
|
+
|
65
|
+
try {
|
66
|
+
|
67
|
+
// 空のドキュメントオブジェクトを作成します
|
68
|
+
|
69
|
+
PDDocument document = new PDDocument();
|
66
70
|
|
67
71
|
|
68
72
|
|
73
|
+
// 新しいページのオブジェクトを作成します
|
74
|
+
|
75
|
+
PDPage page = new PDPage();
|
76
|
+
|
77
|
+
document.addPage(page);
|
69
78
|
|
70
79
|
|
71
80
|
|
81
|
+
// ドキュメントを保存します
|
72
82
|
|
83
|
+
document.save("sample.pdf");
|
73
84
|
|
85
|
+
document.close();
|
74
86
|
|
75
|
-
|
87
|
+
}
|
76
88
|
|
77
|
-
{
|
89
|
+
catch (IOException e) {
|
78
90
|
|
91
|
+
e.printStackTrace();
|
79
92
|
|
93
|
+
}
|
80
94
|
|
81
|
-
public static void PrintPath(String path,List<String> data)
|
82
|
-
|
83
|
-
{
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
File file = new File(path);
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
data.clear();
|
92
|
-
|
93
|
-
//////////////////////////////////////////////////////////////
|
94
|
-
|
95
|
-
//data = new ArrayList<>(Arrays.asList(file.listFiles()));
|
96
|
-
|
97
|
-
/////////////////////////////////////////////////////////////
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
for(int i = 0; i < data.size(); i++)
|
102
|
-
|
103
|
-
{
|
104
|
-
|
105
|
-
System.out.println(i +": "+ data.get(i));
|
106
|
-
|
107
|
-
|
95
|
+
}
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
public static void main(String[] args)
|
116
|
-
|
117
|
-
{
|
118
|
-
|
119
|
-
List<String> pathList = new ArrayList<>();
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
//PDFドキュメントを作成
|
126
|
-
|
127
|
-
try
|
128
|
-
|
129
|
-
{
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
System.out.println("directory drag here: ");
|
138
|
-
|
139
|
-
InputStreamReader isr = new InputStreamReader(System.in);
|
140
|
-
|
141
|
-
BufferedReader br = new BufferedReader(isr);
|
142
|
-
|
143
|
-
String path;
|
144
|
-
|
145
|
-
path = br.readLine();
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
File file = new File(path);
|
150
|
-
|
151
|
-
File[] fileList = file.listFiles();
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
//パスを格納
|
156
|
-
|
157
|
-
for(int i = 0; i< fileList.length; i++)
|
158
|
-
|
159
|
-
{
|
160
|
-
|
161
|
-
PDDocument document = new PDDocument();
|
162
|
-
|
163
|
-
PDImageXObject imageObject = PDImageXObject.createFromFile(fileList[i].getPath(), document);
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
//サイズ指定
|
170
|
-
|
171
|
-
PDRectangle rec = new PDRectangle();
|
172
|
-
|
173
|
-
rec.setUpperRightX(0);
|
174
|
-
|
175
|
-
rec.setUpperRightY(0);
|
176
|
-
|
177
|
-
rec.setLowerLeftX(imageObject.getWidth());
|
178
|
-
|
179
|
-
rec.setLowerLeftY(imageObject.getHeight());
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
PDPage page = new PDPage(rec);
|
186
|
-
|
187
|
-
document.addPage(page);
|
188
|
-
|
189
|
-
PDPageContentStream stream = new PDPageContentStream(document, page);
|
190
|
-
|
191
|
-
stream.drawImage(imageObject, 0, 0);
|
192
|
-
|
193
|
-
stream.close();
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
document.save( fileList[i].getName() + ".pdf");
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
document.close();
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
catch (IOException e)
|
214
|
-
|
215
|
-
{
|
216
|
-
|
217
|
-
e.printStackTrace();
|
218
|
-
|
219
|
-
}
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
|
224
96
|
|
225
97
|
}
|
226
98
|
|
1
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,6 +4,14 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
+
######試したこと
|
8
|
+
|
9
|
+
サイトよりApache Commons Logging 1.2をダウンロードしてパスを通しました。
|
10
|
+
|
11
|
+
https://commons.apache.org/proper/commons-logging/download_logging.cgi
|
12
|
+
|
13
|
+
|
14
|
+
|
7
15
|
|
8
16
|
|
9
17
|
|
@@ -20,7 +28,7 @@
|
|
20
28
|
|
21
29
|
at org.apache.pdfbox.pdmodel.PDDocument.<clinit>(PDDocument.java:98)
|
22
30
|
|
23
|
-
at Main.main(Main.java:
|
31
|
+
at Main.main(Main.java:57)
|
24
32
|
|
25
33
|
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
|
26
34
|
|
@@ -38,7 +46,11 @@
|
|
38
46
|
|
39
47
|
```java
|
40
48
|
|
41
|
-
import java.io.
|
49
|
+
import java.io.*;
|
50
|
+
|
51
|
+
import java.util.*;
|
52
|
+
|
53
|
+
|
42
54
|
|
43
55
|
|
44
56
|
|
@@ -54,85 +66,153 @@
|
|
54
66
|
|
55
67
|
|
56
68
|
|
57
|
-
|
69
|
+
|
58
|
-
|
59
|
-
|
70
|
+
|
60
|
-
|
61
|
-
|
71
|
+
|
62
|
-
|
63
|
-
|
72
|
+
|
64
|
-
|
73
|
+
|
74
|
+
|
65
|
-
public class Main
|
75
|
+
public class Main
|
76
|
+
|
66
|
-
|
77
|
+
{
|
78
|
+
|
79
|
+
|
80
|
+
|
67
|
-
|
81
|
+
public static void PrintPath(String path,List<String> data)
|
82
|
+
|
68
|
-
|
83
|
+
{
|
84
|
+
|
85
|
+
|
86
|
+
|
69
|
-
|
87
|
+
File file = new File(path);
|
70
|
-
|
88
|
+
|
89
|
+
|
90
|
+
|
71
|
-
|
91
|
+
data.clear();
|
92
|
+
|
72
|
-
|
93
|
+
//////////////////////////////////////////////////////////////
|
94
|
+
|
95
|
+
//data = new ArrayList<>(Arrays.asList(file.listFiles()));
|
96
|
+
|
97
|
+
/////////////////////////////////////////////////////////////
|
98
|
+
|
99
|
+
|
100
|
+
|
73
|
-
|
101
|
+
for(int i = 0; i < data.size(); i++)
|
102
|
+
|
74
|
-
|
103
|
+
{
|
104
|
+
|
105
|
+
System.out.println(i +": "+ data.get(i));
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
75
|
-
public static void main(String[] args)
|
115
|
+
public static void main(String[] args)
|
116
|
+
|
117
|
+
{
|
118
|
+
|
119
|
+
List<String> pathList = new ArrayList<>();
|
120
|
+
|
121
|
+
|
76
122
|
|
77
123
|
|
78
124
|
|
79
125
|
//PDFドキュメントを作成
|
80
126
|
|
81
|
-
try
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
re
|
94
|
-
|
95
|
-
re
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
//
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
PD
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
127
|
+
try
|
128
|
+
|
129
|
+
{
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
System.out.println("directory drag here: ");
|
138
|
+
|
139
|
+
InputStreamReader isr = new InputStreamReader(System.in);
|
140
|
+
|
141
|
+
BufferedReader br = new BufferedReader(isr);
|
142
|
+
|
143
|
+
String path;
|
144
|
+
|
145
|
+
path = br.readLine();
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
File file = new File(path);
|
150
|
+
|
151
|
+
File[] fileList = file.listFiles();
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
//パスを格納
|
156
|
+
|
157
|
+
for(int i = 0; i< fileList.length; i++)
|
158
|
+
|
159
|
+
{
|
160
|
+
|
161
|
+
PDDocument document = new PDDocument();
|
162
|
+
|
163
|
+
PDImageXObject imageObject = PDImageXObject.createFromFile(fileList[i].getPath(), document);
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
//サイズ指定
|
170
|
+
|
171
|
+
PDRectangle rec = new PDRectangle();
|
172
|
+
|
173
|
+
rec.setUpperRightX(0);
|
174
|
+
|
175
|
+
rec.setUpperRightY(0);
|
176
|
+
|
177
|
+
rec.setLowerLeftX(imageObject.getWidth());
|
178
|
+
|
179
|
+
rec.setLowerLeftY(imageObject.getHeight());
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
PDPage page = new PDPage(rec);
|
186
|
+
|
187
|
+
document.addPage(page);
|
188
|
+
|
189
|
+
PDPageContentStream stream = new PDPageContentStream(document, page);
|
190
|
+
|
191
|
+
stream.drawImage(imageObject, 0, 0);
|
192
|
+
|
193
|
+
stream.close();
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
document.save( fileList[i].getName() + ".pdf");
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
document.close();
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
catch (IOException e)
|
214
|
+
|
215
|
+
{
|
136
216
|
|
137
217
|
e.printStackTrace();
|
138
218
|
|