回答編集履歴

2

補足を追記

2017/06/14 14:53

投稿

can110
can110

スコア38266

test CHANGED
@@ -63,3 +63,17 @@
63
63
  たしかPDFに埋め込まれている文字列`!"#$%#$~`は何等かのエンコードが施されており、それがそのまま取得されていると思われます。
64
64
 
65
65
  上記の回答では、別モジュール`textract`で取得するように回答されていますので、`textract`を利用されてはいかがでしょうか?
66
+
67
+
68
+
69
+ #### 補足
70
+
71
+ 公式の[extractText()](https://pythonhosted.org/PyPDF2/PageObject.html#PyPDF2.pdf.PageObject.extractText)にも以下のように記載されていました。
72
+
73
+ > Locate all text drawing commands, in the order they are provided in the content stream, and extract the text. This works well for some PDF files, but poorly for others, depending on the generator used. This will be refined in the future. Do not rely on the order of text coming out of this function, as it will change if this function is made more sophisticated.
74
+
75
+
76
+
77
+ ざっくりまとめると、`extractText()`はPDFのテキスト描画コマンド文字列をそのまま抽出するだけで、まだまだ貧弱な機能なようです。
78
+
79
+

1

追記

2017/06/14 14:53

投稿

can110
can110

スコア38266

test CHANGED
@@ -24,13 +24,11 @@
24
24
 
25
25
 
26
26
 
27
- 当方の環境で以下を実行しても同じ結果が得られました。
27
+ 当方の環境で以下を実行したところ、ページ情報はおそらく正しく取得でき、extractTextは上記ページと同じ結果が得られました。
28
28
 
29
29
  ```Python
30
30
 
31
31
  import PyPDF2
32
-
33
- pdf_file_obj = open('sample.pdf', 'rb')
34
32
 
35
33
  pdf_reader = PyPDF2.PdfFileReader(pdf_file_obj)
36
34