前提・実現したいこと
python初心者で勉強中です。
購入した本の例文をそのまま打ち込んだのですがエラーになりうまく動きません。
エラーの原因を教えていただきたいです。
内容はカレントディレクトリにあるPDFを合体させるもののようです。
PDFの名前以外は本に書いてあるそのまま打ち込みました。
初心者で知識がないので説明不十分かもしれませんが、よろしくお願いいたします。
Python 3.7.3
Windows7
----追記
結合用に用意しているPDFをtestpdfとだけ入力されているものにしたら、エラーが別のものに変わりました。(当初は写真が添付されてたり表などがあった)
でも結局うまく作動しないので原因を教えていただけると助かります。
発生している問題・エラーメッセージ
------PDFを変えた後のエラー UnicodeEncodeError: 'ascii' codec can't encode characters in position 24-25: ordinal not in range(128) ------PDFを変える前のエラー PdfReadError("Illegal character in Name Object") write C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 482 _sweepIndirectReferences C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 571 _sweepIndirectReferences C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 547 _sweepIndirectReferences C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 571 _sweepIndirectReferences C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 547 _sweepIndirectReferences C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 556 _sweepIndirectReferences C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 571 _sweepIndirectReferences C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 547 _sweepIndirectReferences C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 547 _sweepIndirectReferences C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 547 _sweepIndirectReferences C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 577 getObject C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\pdf.py 1611 readObject C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\generic.py 66 readFromStream C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\generic.py 579 readObject C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\generic.py 60 readFromStream C:\Users\userid\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyPDF2\generic.py 492 PdfReadError: Illegal character in Name Object
該当のソースコード
import PyPDF2 pdf1_file = open('test1.pdf','rb') pdf2_file = open('test2.pdf','rb') pdf1_reader = PyPDF2.PdfFileReader(pdf1_file) pdf2_reader = PyPDF2.PdfFileReader(pdf2_file) pdf_writer = PyPDF2.PdfFileWriter() for page_num in range(pdf1_reader.numPages): page_obj = pdf2_reader.getPage(page_num) pdf_writer.addPage(page_obj) for page_num in range(pdf2_reader.numPages): page_obj =pdf2_reader.getPage(page_num) pdf_writer.addPage(page_obj) pdf_output_file =open('newdata.pdf','wb') pdf_writer.write(pdf_output_file) pdf_output_file.close() pdf2_file.close() pdf1_file.close()
試したこと
エラーメッセージを検索しましたがよくわかりませんでした。
補足情報(FW/ツールのバージョンなど)
Python 3.7.3
Windows7
回答1件
あなたの回答
tips
プレビュー