質問編集履歴
3
print文を入れたソースおよび実行結果の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,6 +7,11 @@
|
|
7
7
|
|
8
8
|
def set_password(src_path, dst_path, user_password, owner_password=None):
|
9
9
|
|
10
|
+
print(src_path)
|
11
|
+
print(ascii(src_path))
|
12
|
+
print(ascii("C:\\temp\\sample2\\0000000AB・CD 株式会社 御中.PDF"))
|
13
|
+
print("C:\\temp\\sample2\\0000000AB\u30fbCD\u3000株式会社 御中.PDF")
|
14
|
+
|
10
15
|
src_pdf = pypdf.PdfReader(src_path)
|
11
16
|
dst_pdf = pypdf.PdfWriter()
|
12
17
|
dst_pdf.clone_reader_document_root(src_pdf)
|
@@ -93,6 +98,17 @@
|
|
93
98
|
src_pdf = pypdf.PdfReader(r"C:\\temp\\sample2\\0000000AB・CD 株式会社 御中.PDF")に
|
94
99
|
変更し実行したところ、ファイル名が全角でも問題なくパスワード付のPDFに変換されたためプログラムそのものに問題は無いかと思います。
|
95
100
|
|
101
|
+
以下、print文を入れた結果のターミナルに表示
|
102
|
+
print(src_path)
|
103
|
+
print(ascii(src_path))
|
104
|
+
print(ascii("C:\\temp\\sample2\\0000000AB・CD 株式会社 御中.PDF"))
|
105
|
+
print("C:\\temp\\sample2\\0000000AB\u30fbCD\u3000株式会社 御中.PDF")
|
106
|
+
|
107
|
+
結果
|
108
|
+
C:\temp\sample2\0000000ABCD 株式会社 御中.PDF
|
109
|
+
'C:\\temp\\sample2\\0000000\uff21\uff22\uff23\uff24\u3000\u682a\u5f0f\u4f1a\u793e \u5fa1\u4e2d.PDF'
|
110
|
+
'C:\\temp\\sample2\\0000000\uff21\uff22\u30fb\uff23\uff24\u3000\u682a\u5f0f\u4f1a\u793e \u5fa1\u4e2d.PDF'
|
111
|
+
C:\temp\sample2\0000000AB・CD 株式会社 御中.PDF
|
96
112
|
|
97
113
|
### 補足
|
98
114
|
windows10
|
2
\(円記号)を\(バックスラッシュ)に統一しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -35,6 +35,7 @@
|
|
35
35
|
// 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
|
36
36
|
"version": "0.2.0",
|
37
37
|
"configurations": [
|
38
|
+
|
38
39
|
{
|
39
40
|
"name": "Python: 現在のファイル",
|
40
41
|
"type": "python",
|
@@ -43,8 +44,8 @@
|
|
43
44
|
"console": "integratedTerminal",
|
44
45
|
"justMyCode": true,
|
45
46
|
"args": [
|
46
|
-
"C:
|
47
|
+
"C:\\temp\\sample2\\0000000AB・CD 株式会社 御中.PDF",
|
47
|
-
"C:
|
48
|
+
"C:\\temp\\sample2\\0000000AB・CD 株式会社 御中.PDF",
|
48
49
|
"pass",
|
49
50
|
"pass"
|
50
51
|
]
|
@@ -64,12 +65,12 @@
|
|
64
65
|
### エラーメッセージ
|
65
66
|
```error
|
66
67
|
例外が発生しました: FileNotFoundError
|
67
|
-
[Errno 2] No such file or directory: 'C:
|
68
|
+
[Errno 2] No such file or directory: 'C:\\temp\\sample2\\0000000ABCD\u3000株式会社 御中.PDF'
|
68
|
-
File "C:\Users\user\PDF_pwSet.py", line 8, in set_password
|
69
|
+
File "C:\Users\user\pytest\PDF_pwSet.py", line 8, in set_password
|
69
70
|
src_pdf = pypdf.PdfReader(src_path)
|
70
|
-
File "C:\Users\
|
71
|
+
File "C:\Users\user\pytest\PDF_pwSet.py", line 21, in <module>
|
71
72
|
set_password(args[1], args[2],args[3], args[4])
|
72
|
-
FileNotFoundError: [Errno 2] No such file or directory: 'C:
|
73
|
+
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\temp\\sample2\\0000000ABCD\u3000株式会社 御中.PDF'
|
73
74
|
```
|
74
75
|
|
75
76
|
### 該当のソースコード
|
@@ -89,7 +90,7 @@
|
|
89
90
|
|
90
91
|
|
91
92
|
src_pdf = pypdf.PdfReader(src_path)の部分を
|
92
|
-
src_pdf = pypdf.PdfReader(r"C:
|
93
|
+
src_pdf = pypdf.PdfReader(r"C:\\temp\\sample2\\0000000AB・CD 株式会社 御中.PDF")に
|
93
94
|
変更し実行したところ、ファイル名が全角でも問題なくパスワード付のPDFに変換されたためプログラムそのものに問題は無いかと思います。
|
94
95
|
|
95
96
|
|
1
補足にバージョン情報を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -94,4 +94,6 @@
|
|
94
94
|
|
95
95
|
|
96
96
|
### 補足
|
97
|
-
|
97
|
+
windows10
|
98
|
+
python 3.9.9
|
99
|
+
pypdf 4.0.1
|