20230507 python3을 사용하여 DOCX 문서를 TXT로 일괄 변환

20230507 python3을 사용하여 DOCX 문서를 TXT로 일괄 변환
2023/5/7 20:22

WIN10은 python3.11을 사용합니다.

# – 코딩: gbk –
import os
from pdf2docx import Converter
from win32com import client as wc
"""An subcontract pywin32com is required here"""

# pdf 파일의 텍스트 내용 읽기
def DocxToTxt(inputFinallyPath, outputFinallyPath):
    wordhandle = wc.Dispatch("Word.Application")
    wordhandle.Visible = 0 # 백그라운드에서 실행, 표시하지 않음
    wordhandle.DisplayAlerts = 0 # 실행 not warning
    doc = wordhandle.Documents.Open(inputFinallyPath)
    doc.SaveAs(outputFinallyPath, 4) # txt=4, html=10, docx=16,pdf=17
    doc.Close


__name__ == '__main__'인 경우:

        # 입력 경로
        inputPath = r'D:\pythonproject\pdf_to_txt\input'
        # 출력 경로, 가급적이면 절대 경로
        outputPath = r'D:\pythonproject\pdf_to_txt\output'
      
        # 폴더에 있는 파일 나열
        pdfList = os.listdir( inputPath)
        # 일괄 읽기 저장
        pdf_num = 1
        for li in pdfList:
            print(li)
            inputFinallyPath = inputPath + '/' + li
            li = li.replace('.docx', '.txt')
            outputFinallyPath = outputPath + '/' + li
            DocxToTxt(inputFinallyPath, outputFinallyPath)
            print('%d docx가 txt로 변환되었습니다' % pdf_num)
            pdf_num = pdf_num + 1
        print('총 %d개의 docx 문서가 txt로 완전히 변환되었습니다.' % (pdf_num-1))

 


Google 번역을 사용하여 88개의 일본어 DOCX 자막을 중국어 간체 버전으로 번역하세요!
Microsoft Windows [버전 10.0.19044.2728]
(c) Microsoft Corporation. 판권 소유.

C:\사용자\QQ>python3

C:\Users\QQ>파이썬

C:\Users\QQ>python
Python 3.11.3(tags/v3.11.3:f3909b8, 2023년 4월 4일, 23:49:59) [MSC v.1934 64비트(AMD64)] on win32
Type "help", " 자세한 내용은 저작권", "크레딧" 또는 "라이선스"를 참조하십시오.
>>> import os
>>> from pdf2docx import Converter
Traceback (가장 최근 호출 마지막):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pdf2docx'
>>>

 


Microsoft Windows [버전 10.0.19044.2728]
(c) Microsoft Corporation. 판권 소유.

C:\Users\QQ>pip install pdf2docx
pdf2docx 수집
  중 pdf2docx-0.5.6-py3-none-any.whl 다운로드 중(148 kB)
     ---------------------------------- -------------------- 148.4/148.4 kB 368.3 kB/s eta 0:00:00
PyMuPDF 수집 중>=1.19.0
  PyMuPDF 다운로드 중-1.22.2-cp311- cp311-win_amd64.whl(11.7MB)
     ---------------------------------------- 11.7 /11.7MB 12.8MB/s eta 0:00:00
python-docx 수집 중>=0.8.10
  python-docx-0.8.11.tar.gz 다운로드 중(5.6MB)
     ------------ ---------------------------- 5.6/5.6MB 1.6MB/s eta 0:00:00
  메타데이터 준비 중(setup.py) . .. done
fonttools 수집 중>=4.24.0
  fonttools-4.39.3-py3-none-any.whl 다운로드 중(1.0MB)
     ---------------------------------------- 1.0/1.0MB 12.8MB/초 에타 0 :00:00
numpy 수집 중>=1.17.2
  numpy-1.24.3-cp311-cp311-win_amd64.whl 다운로드 중(14.8MB)
     --------------------- ------------------- 14.8/14.8MB 21.1MB/s eta 0:00:00
수집 opencv-python>=4.5
  다운로드 opencv_python-4.7.0.72-cp37-abi3 -win_amd64.whl(38.2MB)
     ---------------------------------------- 38.2/ 38.2MB 12.6MB/s eta 0:00:00
모으는 중>=0.3.0
  fire 다운로드 중-0.5.0.tar.gz (88 kB)
     ------------------ ----------------------- 88.3/88.3 kB 4.9 MB/s eta 0:00:00
  메타데이터 준비 중(setup.py) ... 완료
6개 수집 중
  six-1.16.0-py2.py3-none-any.whl(11kB) 다운로드
termcolor 수집
  termcolor-2.3.0-py3-none-any.whl(6.9kB)
다운로드 lxml>=2.3.2
  수집 lxml-4.9.2-cp311-cp311-win_amd64.whl(3.8MB) 다운로드
     ----- ----------------------------------- 3.8/3.8MB 10.0MB/s eta 0:00:00
설치 중 수집된 패키지: termcolor, six, PyMuPDF, numpy, lxml, fonttools, python-docx, opencv-python, fire, pdf2docx
  경고: 스크립트 f2py.exe는 'C:\Users\QQ\AppData\Local\Packages\에 설치됩니다. PATH에 없는 PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\Scripts'.
  이 디렉토리를 PATH에 추가하거나 이 경고를 표시하지 않으려면 --no-warn-script-location을 사용하십시오.
  경고: 스크립트 fonttools.exe, pyftmerge.exe, pyftsubset.exe 및 ttx.exe는 'C:\Users\QQ\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311에 설치됩니다. \Scripts'는 PATH에 없습니다.
  이 디렉토리를 PATH에 추가하거나 이 경고를 표시하지 않으려면 --no-warn-script-location을 사용하십시오.
  지원 중단: python-docx는 'pyproject.toml'이 없고 'wheel' 패키지가 설치되지 않았기 때문에 레거시 'setup.py install' 방법을 사용하여 설치됩니다. pip 23.1은 이 동작 변경을 적용합니다. 가능한 대체 방법은 '--use-pep517' 옵션을 활성화하는 것입니다. 토론은 https://github.com/pypa/pip/issues/8559에서 찾을 수 있습니다.
  Python-docx에 대한 setup.py 설치 실행 중 ... 완료
  지원 중단: fire는 'pyproject.toml'이 없고 'wheel' 패키지가 설치되지 않았기 때문에 레거시 'setup.py install' 방법을 사용하여 설치됩니다. pip 23.1은 이 동작 변경을 적용합니다. 가능한 대체 방법은 '--use-pep517' 옵션을 활성화하는 것입니다. 토론은 https://github.com/pypa/pip/issues/8559에서 찾을 수 있습니다.
  Running setup.py install for fire ... done
  경고: 스크립트 pdf2docx.exe는 'C:\Users\QQ\AppData에 설치됩니다. \Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\Scripts' PATH에 없습니다.
  이 디렉토리를 PATH에 추가하거나 이 경고를 표시하지 않으려면 --no-warn-script-location을 사용하십시오.
PyMuPDF-1.22.2 fire-0.5.0 fonttools-4.39.3 lxml-4.9.2 numpy-1.24.3 opencv-python-4.7.0.72 pdf2docx-0.5.6 python-docx-0.8.11 six-1.16을 성공적으로 설치했습니다. 0 termcolor-2.3.0

[공지] pip의 새 릴리스 사용 가능: 22.3.1 -> 23.1.2
[공지] 업데이트하려면 다음을 실행하십시오. exe -m pip 설치 --pip 업그레이드

C:\사용자\QQ>

 

 


Microsoft Windows [버전 10.0.19044.2728]
(c) Microsoft Corporation. 판권 소유.

C:\Users\QQ>pip install win32com
오류: win32com 요구 사항을 충족하는 버전을 찾을 수 없습니다(버전: 없음)
오류: win32com에 대해 일치하는 배포를 찾을 수 없습니다.

[공지] pip의 새 릴리스 사용 가능: 22.3.1 -> 23.1.2
[공지] 업데이트하려면 다음을 실행하십시오. exe -m pip 설치 --pip 업그레이드

C:\Users\QQ>
C:\Users\QQ>pip install pypwin32
오류: pypwin32 요구 사항을 충족하는 버전을 찾을 수 없습니다(버전: 없음)
오류: pypwin32에 대해 일치하는 배포를 찾을 수 없습니다.

[공지] pip의 새 릴리스 사용 가능: 22.3.1 -> 23.1.2
[공지] 업데이트하려면 다음을 실행하십시오. exe -m pip 설치 --pip 업그레이드

C:\Users\QQ>
C:\Users\QQ>pip install pypiwin32
수집 pypiwin32
  다운로드 pypiwin32-223-py3-none-any.whl(1.7 kB)
수집 pywin32>=223
  다운로드 pywin32-306-cp311-cp311-win_amd64 다운로드 .whl(9.2MB)
     ---------------------------------------- 9.2/9.2MB 895.2 kB/s eta 0:00:00
수집된 패키지 설치: pywin32, pypiwin32
성공적으로 설치됨 pypiwin32-223 pywin32-306

[공지] pip의 새 릴리스 사용 가능: 22.3.1 -> 23.1.2
[공지] 업데이트하려면 다음을 실행하십시오. exe -m pip 설치 --pip 업그레이드

C:\사용자\QQ>
C:\사용자\QQ>

 

 

 


Microsoft Windows [버전 10.0.19044.2728]
(c) Microsoft Corporation. 판권 소유.

C:\사용자\QQ>d:

D:\>dir *.pty
 드라이브 D의 볼륨은
 DATA 볼륨의 일련 번호이며 547F-1046입니다.

 D:\ 디렉토리

파일을 찾을 수 없습니다

D:\>dir *.py
 드라이브 D의 볼륨은
 DATA 볼륨의 일련 번호는 547F-1046입니다.

 D:\ 디렉토리

2023/05/07 19:55 1,221 pdf2doc2.py
               1 파일 1,221 바이트
               0 디렉토리 195,912,142,848 사용 가능 바이트

D:\>python pdf2doc2.py
SyntaxError: 파일 D:\pdf2doc2.py의 4행에서 '\xd5'로 시작하는 비UTF-8 코드이지만 인코딩이 선언되지 않았습니다. 자세한 내용은 https://peps.python.org/pep-0263/ 참조

D:\>


Microsoft Windows [버전 10.0.19044.2728]
(c) Microsoft Corporation. 판권 소유.

C:\사용자\QQ>d:

D:\>dir *.pty
 드라이브 D의 볼륨은
 DATA 볼륨의 일련 번호이며 547F-1046입니다.

 D:\ 디렉토리

파일을 찾을 수 없습니다

D:\>dir *.py
 드라이브 D의 볼륨은
 DATA 볼륨의 일련 번호는 547F-1046입니다.

 D:\ 디렉토리

2023/05/07 19:55 1,221 pdf2doc2.py
               1 파일 1,221 바이트
               0 디렉토리 195,912,142,848 사용 가능 바이트

D:\>python pdf2doc2.py
SyntaxError: 파일 D:\pdf2doc2.py의 4행에서 '\xd5'로 시작하는 비UTF-8 코드이지만 인코딩이 선언되지 않았습니다. 자세한 내용은 https://peps.python.org/pep-0263/ 참조

D:\>
D:\>python pdf2doc2.py
  File "D:\pdf2doc2.py", line 36
    print('총 %d개의 docx 문서가 txt로 완전히 변환되었습니다' pdf_num-1))
                                           ^
SyntaxError: unmatched ') '

D:\>python pdf2doc2.py
MIDE-599.google.docx
파트 1 docx가 txt로 변환됨
OAE-101.google.docx
파트 2 docx가 txt로 변환됨
OAE-165.google.docx
파트 3 docx가 txt로 변환됨 변환 txt로 변환됨
OFJE-139 1.google.docx
4번째 docx txt로 변환됨 OFJE
-139 2.google.docx
5번째 docx txt로 변환됨
OFJE-189.google.docx
6번째 docx txt로 변환됨
OFJE-236.google.docx
부분 7 docx가 txt로 변환됨
pSSNI-473.google.docx
8부 docx가 txt로 변환됨
SIVR-001.google.docx
9부 docx가 txt로 변환됨
SIVR-002.google .docx
10번째 docx가 txt로 변환됨
SIVR-003.google.docx
11번째 docx를 txt로 변환
SIVR-012 1.google.docx
12번째 docx를 txt로 변환
SIVR-012 2.google.docx
13번째 docx를 txt로 변환
SIVR-015 1.google.docx
14번째 docx를 txt로 변환
SIVR-015 2.google.docx
15번째 docx를 txt로 변환
SIVR-016 1.google.docx
16번째 문서 docx를 txt로 변환
SIVR-016 2. google.docx
17조 docx를 txt로 변환
SIVR-017 1.google.docx
18조 docx를 txt로 변환
SIVR-017 2.google.docx
19조 docx txt로 변환
SIVR-017 3.google.docx
20번째 docx를 txt로 변환
SIVR-033 1.google.docx
21번째 docx를 txt로 변환
SIVR-033 2.google.docx
22번째 docx를 txt로 변환
SIVR-033 3.google.docx
23번째 docx를 txt로 변환
SIVR-033 4.google.docx
24번째 docx를 txt로 변환 txt
SIVR-033 5.google.docx
25번째 docx를 txt로 변환
SIVR-033 6. google.docx
26번 docx를 txt로 변환
SIVR-034 1. google.docx
27번 docx를 txt로 변환
SIVR-034 2. google.docx
28번 docx를 txt로 변환
SIVR-034 3. google.docx
29번째 docx를 txt로 변환
SIVR-044 1. google.docx
30번째 docx를 txt로 변환
SIVR-044 2. google.docx
31번째 docx를 txt로 변환
SIVR-061 1 .google.docx
32번째 docx를 txt로 변환
SIVR-061 2.google.docx
33번째 docx를 txt로 변환
SIVR-061 3.google.docx
34번째 docx를 txt로 변환
SIVR-061 4.google .docx
35번째 docx를 txt로 변환
SIVR-067 1.google.docx
36번째 docx를 txt로 변환
SIVR -061 -067 2.google.docx
37번째 docx를 txt로 변환
SIVR-067 3.google.docx
Article 38 docx를 txt로 변환
SNIS-786.google.docx
Article 39 docx를 txt로 변환
SNIS-800.google.docx
Article 40 docx를 txt로 변환
SNIS-850 1.google.docx
Article 41 docx txt로 변환
SNIS-850 2 .google.docx
42번 docx를 txt로 변환
SNIS-872.google.docx
43번 docx를 txt로 변환
SNIS-896.google.docx
44번 docx를 txt로 변환
SNIS-919.google.docx
45번 docx txt로 변환
SNIS-964.google.docx
No. 46 docx txt로 변환
SNIS-964.google2.docx
No. 47 docx txt로 변환
SNIS-986.google .docx
48th docx txt로 변환
SSNI-009.google.docx
49번째 docx가 txt로 변환됨
SSNI-030.google.docx
50번째 docx가 txt로 변환됨
SSNI-054.google.docx
Article 51 docx를 txt로 변환
SSNI-077.google.docx
Article 52 docx를 txt로 변환
SSNI-101.google.docx
Article 53 docx를 txt로 변환
SSNI-127.google.docx
Article 54 docx를 txt로 변환
SSNI-152. google.docx
55조 docx를 txt로 변환
SSNI-178.google.docx
56조 docx를 txt로 변환
SSNI-205.google.docx
57조 docx를 txt로 변환 SSNI-178.google.docx 57조 docx를
txt로 변환 229. google.docx
58 docx를 txt로 변환
SSNI-254.google.docx
59 docx를 txt로 변환
SSNI-279.google.docx
60 docx를 txt로 변환
SSNI-301.google.docx
Article 61 docx를 txt로 변환 txt
SSNI-322.google.docx
문서 62 docx가 txt로 변환됨
SSNI-344.google.docx
문서 63 docx가 txt로 변환됨
SSNI-388.google.docx
64번째 docx가 txt로 변환됨
SSNI-409.google.docx
65번째 docx가 txt로 변환 됨
SSNI-432.google.docx
66번째 docx가 txt로 변환됨
SSNI-452.google.docx
67번째 docx가 txt로 변환됨
SSNI-473.google.docx
아니요 68 docx txt로 변환
SSNI-493.google.docx
No. 69 docx txt로 변환
SSNI-516.google.docx
No. 70 docx txt로 변환
SSNI- 542.google.docx
71번째 docx txt
SSNI-566으로 변환. google.docx
72번째 docx가 txt로 변환됨
SSNI-589.google.docx
73번째 docx가 txt로 변환됨 SSNI
-618.google.docx
Article 74 docx가 txt로 변환됨
SSNI-644.google.docx
Article 75 docx가 txt로 변환됨
SSNI-674. google.docx
문서 76 docx를 txt로 변환
SSNI-703.google.docx
77번째 docx가 txt로 변환됨
SSNI-730.google.docx
78번째 docx가 txt로 변환됨
TEK-067.google.docx
79번째 docx가 txt로 변환됨
TEK-071.google.docx
80번째 docx가 txt로 변환됨
TEK-072.google.docx
아니요 81 docx를 txt로 변환
TEK-073.google.docx
82 docx를 txt로 변환
TEK-076.google.docx
83 docx를 txt로 변환
TEK-079 Audio only.google.docx
84 docx를 txt로 변환
TEK-080.google.docx
No. 85 docx를 txt로 변환
TEK-081 Audio only.google.docx
No. 86 docx를 txt로 변환
TEK-083 Audio only.google.docx
87장 docx를 txt로 변환
TEK-097.google .docx
88장 docx를 txt로 변환

D:\>


참조:
파이썬 일괄 변환 DOCX TXT


https://blog.csdn.net/weixin_46255747/article/details/129961988
Python은 배치 docx를 txt로 구현합니다.


ModuleNotFoundError: 'pdf2docx'라는 모듈이 없습니다.


파이썬 win32com pip 설치


https://blog.csdn.net/qq_45662588/article/details/130315080
win32com 라이브러리를 python3.9에 설치하는 솔루션


https://blog.csdn.net/longe20111104/article/details/129754624
pip install win32com 오류 해결 방법
pip install pypiwin32


SyntaxError: 파일 D:\pdf2doc2.py의 4행에서 '\xd5'로 시작하는 비UTF-8 코드이지만 인코딩 d는 없습니다.


https://blog.csdn.net/coco_apple/article/details/113437552
SyntaxError: 파일 #에서 '\xd5'로 시작하는 비UTF-8 코드
– 코딩: gbk –

 

 

 

 

추천

출처blog.csdn.net/wb4916/article/details/130547425