質問編集履歴
5
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
Python 3.7.3
|
11
11
|
Windows7
|
12
12
|
### 質問
|
13
|
-
ご指摘のおかげでコードを修正し結合することはできたのですが、PDFが読み込めません。エラーメッセージが出ないので原因がわかりません。結合に失敗する原因を教えていただ
|
13
|
+
ご指摘のおかげでコードを修正し結合することはできたのですが、PDFが読み込めません。エラーメッセージが出ないので原因がわかりません。結合に失敗する原因を教えていただけると助かります。よろしくお願いいたします。
|
14
14
|
|
15
15
|
|
16
16
|
|
4
ご回答により以前のエラーが改善し、不明点が変更になったため
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Python
|
1
|
+
Python 5ページ写真つきPDF結合に失敗してしまいます。
|
body
CHANGED
@@ -3,23 +3,19 @@
|
|
3
3
|
購入した書籍に書いてある例文をそのまま入力しました。
|
4
4
|
wordに単語を入力してPDF化したものは結合することができました。
|
5
5
|
|
6
|
+
### 今やろうとしていること
|
6
7
|
PDFの容量:900KB
|
7
|
-
2ファイル結合しようと思っています。
|
8
|
+
5ページ2ファイル結合しようと思っています。
|
8
9
|
|
9
10
|
Python 3.7.3
|
10
11
|
Windows7
|
11
12
|
### 質問
|
12
|
-
|
13
|
+
ご指摘のおかげでコードを修正し結合することはできたのですが、PDFが読み込めません。エラーメッセージが出ないので原因がわかりません。結合に失敗する原因を教えていただきたけると助かります。よろしくお願いいたします。
|
13
|
-
よろしくお願いいたします。
|
14
|
-
Python始めたばかりで見当違いな質問でしたらすみません。
|
15
14
|
|
16
|
-
### 確認したこと
|
17
|
-
unicodeエラーなのか、と思い下記のようにして確認しました。
|
18
15
|
|
19
|
-
sys.getdefaultencoding()
|
20
|
-
'utf-8'
|
21
16
|
|
22
17
|
|
18
|
+
|
23
19
|
### 使ったプログラム
|
24
20
|
```
|
25
21
|
import PyPDF2, os
|
@@ -33,7 +29,7 @@
|
|
33
29
|
|
34
30
|
for filename in pdf_files:
|
35
31
|
pdf_file_obj = open(filename, 'rb')
|
36
|
-
pdf_reader = PyPDF2.PdfFileReader(pdf_file_obj)
|
32
|
+
pdf_reader = PyPDF2.PdfFileReader(pdf_file_obj, strict=False)
|
37
33
|
|
38
34
|
for page_num in range(1, pdf_reader.numPages):
|
39
35
|
page_obj = pdf_reader.getPage(page_num)
|
@@ -42,73 +38,4 @@
|
|
42
38
|
pdf_output = open('newtest.pdf', 'wb')
|
43
39
|
pdf_writer.write(pdf_output)
|
44
40
|
pdf_output.close()
|
45
|
-
```
|
46
|
-
|
47
|
-
### エラーの内容
|
48
|
-
```
|
49
|
-
Traceback (most recent call last):
|
50
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
51
|
-
\PyPDF2\generic.py", line 484, in readFromStream
|
52
|
-
return NameObject(name.decode('utf-8'))
|
53
|
-
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 8: invalid
|
54
|
-
start byte
|
55
|
-
|
56
|
-
During handling of the above exception, another exception occurred:
|
57
|
-
|
58
|
-
Traceback (most recent call last):
|
59
|
-
File "C:\Users\userid123\Desktop\作業\python\pdftest.py", line 19, in <module>
|
60
|
-
pdf_writer.write(pdf_output)
|
61
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
62
|
-
\PyPDF2\pdf.py", line 482, in write
|
63
|
-
self._sweepIndirectReferences(externalReferenceMap, self._root)
|
64
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
65
|
-
\PyPDF2\pdf.py", line 571, in _sweepIndirectReferences
|
66
|
-
self._sweepIndirectReferences(externMap, realdata)
|
67
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
68
|
-
\PyPDF2\pdf.py", line 547, in _sweepIndirectReferences
|
69
|
-
value = self._sweepIndirectReferences(externMap, value)
|
70
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
71
|
-
\PyPDF2\pdf.py", line 571, in _sweepIndirectReferences
|
72
|
-
self._sweepIndirectReferences(externMap, realdata)
|
73
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
74
|
-
\PyPDF2\pdf.py", line 547, in _sweepIndirectReferences
|
75
|
-
value = self._sweepIndirectReferences(externMap, value)
|
76
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
77
|
-
\PyPDF2\pdf.py", line 556, in _sweepIndirectReferences
|
78
|
-
value = self._sweepIndirectReferences(externMap, data[i])
|
79
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
80
|
-
\PyPDF2\pdf.py", line 571, in _sweepIndirectReferences
|
81
|
-
self._sweepIndirectReferences(externMap, realdata)
|
82
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
83
|
-
\PyPDF2\pdf.py", line 547, in _sweepIndirectReferences
|
84
|
-
value = self._sweepIndirectReferences(externMap, value)
|
85
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
86
|
-
\PyPDF2\pdf.py", line 547, in _sweepIndirectReferences
|
87
|
-
value = self._sweepIndirectReferences(externMap, value)
|
88
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
89
|
-
\PyPDF2\pdf.py", line 547, in _sweepIndirectReferences
|
90
|
-
value = self._sweepIndirectReferences(externMap, value)
|
91
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
92
|
-
\PyPDF2\pdf.py", line 577, in _sweepIndirectReferences
|
93
|
-
newobj = data.pdf.getObject(data)
|
94
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
95
|
-
\PyPDF2\pdf.py", line 1611, in getObject
|
96
|
-
retval = readObject(self.stream, self)
|
97
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
98
|
-
\PyPDF2\generic.py", line 66, in readObject
|
99
|
-
return DictionaryObject.readFromStream(stream, pdf)
|
100
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
101
|
-
\PyPDF2\generic.py", line 579, in readFromStream
|
102
|
-
value = readObject(stream, pdf)
|
103
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
104
|
-
\PyPDF2\generic.py", line 60, in readObject
|
105
|
-
return NameObject.readFromStream(stream, pdf)
|
106
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
107
|
-
\PyPDF2\generic.py", line 492, in readFromStream
|
108
|
-
raise utils.PdfReadError("Illegal character in Name Object")
|
109
|
-
PyPDF2.utils.PdfReadError: Illegal character in Name Object
|
110
|
-
|
111
|
-
```### 修正して新たに発生したエラー
|
112
|
-
```
|
113
|
-
PdfReadWarning: Illegal character in Name Object [generic.py:489]
|
114
41
|
```
|
3
エラーの変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -110,16 +110,5 @@
|
|
110
110
|
|
111
111
|
```### 修正して新たに発生したエラー
|
112
112
|
```
|
113
|
-
Traceback (most recent call last):
|
114
|
-
File "C:\Users\userid123\Desktop\作業\python\test.py", line 12, in <mo
|
115
|
-
dule>
|
116
|
-
|
113
|
+
PdfReadWarning: Illegal character in Name Object [generic.py:489]
|
117
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
118
|
-
\PyPDF2\pdf.py", line 1084, in __init__
|
119
|
-
self.read(stream)
|
120
|
-
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
121
|
-
\PyPDF2\pdf.py", line 1689, in read
|
122
|
-
stream.seek(-1, 2)
|
123
|
-
OSError: [Errno 22] Invalid argument
|
124
|
-
|
125
114
|
```
|
2
情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
購入した書籍に書いてある例文をそのまま入力しました。
|
4
4
|
wordに単語を入力してPDF化したものは結合することができました。
|
5
5
|
|
6
|
+
PDFの容量:900KB
|
7
|
+
2ファイル結合しようと思っています。
|
8
|
+
|
6
9
|
Python 3.7.3
|
7
10
|
Windows7
|
8
11
|
### 質問
|
1
エラーの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
購入した書籍に書いてある例文をそのまま入力しました。
|
4
4
|
wordに単語を入力してPDF化したものは結合することができました。
|
5
5
|
|
6
|
+
Python 3.7.3
|
7
|
+
Windows7
|
6
8
|
### 質問
|
7
9
|
PDFに写真が添付されているものを結合しようとしたらエラーが起きました。PDFに写真が添付されているとこのプログラムでは結合することはできないのでしょうか?それと、このエラーの原因を教えて頂きたいです。
|
8
10
|
よろしくお願いいたします。
|
@@ -103,4 +105,18 @@
|
|
103
105
|
raise utils.PdfReadError("Illegal character in Name Object")
|
104
106
|
PyPDF2.utils.PdfReadError: Illegal character in Name Object
|
105
107
|
|
108
|
+
```### 修正して新たに発生したエラー
|
109
|
+
```
|
110
|
+
Traceback (most recent call last):
|
111
|
+
File "C:\Users\userid123\Desktop\作業\python\test.py", line 12, in <mo
|
112
|
+
dule>
|
113
|
+
pdf_reader = PyPDF2.PdfFileReader(pdf_file_obj,strict=False)
|
114
|
+
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
115
|
+
\PyPDF2\pdf.py", line 1084, in __init__
|
116
|
+
self.read(stream)
|
117
|
+
File "C:\Users\userid123\AppData\Local\Programs\Python\Python37\Lib\site-packages
|
118
|
+
\PyPDF2\pdf.py", line 1689, in read
|
119
|
+
stream.seek(-1, 2)
|
120
|
+
OSError: [Errno 22] Invalid argument
|
121
|
+
|
106
122
|
```
|