This is my code
import os
import PyPDF2
# set the directory where the PDF files are located
pdf_directory = '/Users/humnerohit/Desktop/test_pdf_files'
# loop through each file in the directory
for filename in os.listdir(pdf_directory):
if filename.endswith('.pdf'):
# create a PDF file object
pdf_file = open(os.path.join(pdf_directory, filename), 'rb')
# create a PDF reader object
pdf_reader = PyPDF2.PdfFileReader(pdf_file)
# loop through each page in the PDF file
text = ''
for page_num in range(pdf_reader.numPages):
# extract the text from the page
page = pdf_reader.getPage(page_num)
text += page.extractText()
# close the PDF file object
pdf_file.close()
# create a text file object
text_file = open(os.path.join(pdf_directory, filename[:-4] + '.txt'), 'w')
# write the extracted text to the text file
text_file.write(text)
# close the text file object
text_file.close()
output
gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003
খࢢදொͷ࠶։ൃϏϧɾαϯϓϥβớຊࣾখỜͷখࢁ౻ࢢձͱ੪౻ਗ਼͕ࣾҰỏब͍͋ͭ͞ͷͨΊখຽใࣾΛ๚Εỏ தࣾ࣍ܒͱ࠙ஊỐủத৺֗ͷ֩ళฮͱͯ͠ỏ
ޙࠓؤுΓ·͢Ứͱ๊ෛΛड़ͨỐ
Ӻલ࠶։ൃϏϧͱͯ͠ҰࣣࣣʹΦồϓϯͨ͠αϯϓϥβỏࠓۀೋेೋỐ֩ςφϯτͷμΠΤồͱͷेؒͷܖΛऴ
͑ỏࡢશؗϦχỿồΞϧͨ͠ỐҰ෦ỏςφϯτ༠க͕Ε͕ͨỏ͜ͷ΄ͲΊͲ͕͍ͭͨͨΊỏখࢁલࣾࡢेೋ݄ͷגओ૯ձͰୀΛਃ͠ೖΕỐࡾ݄ࡾेͷऔకձͰঝೝ͞ΕͨỐ৽ࣾʹࡾͷ੪౻ਗ਼ࠪΛબỐখࢯࢁձʹबͨ͠Ố
খࢁձủࢥ͍ग़Λ͖ͤΓ͕ͳ͍ỨͱΛࡉΊủαϯϓϥβమೆͷ֩Ͱͳ͚ΕͳΒͳ͍Ứͱޙࠓͷళͮ͘ΓʹҙཉỐ੪౻ࣾủখࢁձͷԿͷҰͰ͖ͳ͍ͱࢥ͏͕ỏैۀһʹڠྗͯ͠Βỳͯؤுỳ͍͖͍ͯͨỨͱܾҙΛड़ͨỐݩ͔Βٿͷ۱
ʑ
·ͰỏڥѱԽ͕ਂࠁͷ߹͍Λ૿͍ͯ͠ΔỐμΠΦΩγϯỏ ԹஆԽỏࢎੑӍỏΦκϯഁյỏੜछݮগỏީؾมಈ
/gai007ỐڥࠃΛ͑ỏͦ͢Λ͛ͯ࣍ʑʹಥ͖͚ΒΕΔҟมʹỏҬͲ͏ཱ͔ͪ͏͔Ố͔ͭͯओʹެۀ࢈ͷࢹʹҙΛ͏͚ͩͩ
Текст извлекается из PDF-файла и сохраняется в той же папке с тем же именем и расширением .txt.
но кажется, что данные не преобразуется в японский текст.
Ожидается получение чистого японского текста в текстовый файл.
код, отображающий японский символ с нежелательными символами< /p>
import fitz
from mecab_text_cleaner import to_reading, to_ascii_clean
def pdf_to_text(pdf_path, txt_path):
# Open the PDF
pdf_document = fitz.open(pdf_path)
# Create a text file to store the extracted text
with open(txt_path, "w", encoding="utf-8") as text_file:
for page_number in range(len(pdf_document)):
page = pdf_document.load_page(page_number)
text = page.get_text()
text_file.write(text)
# Close the PDF
pdf_document.close()
# Example usage
pdf_path = "/Users/humnerohit/python_pdf_to_text/S19990401A10010001001.pdf"
txt_path = "/Users/humnerohit/python_pdf_to_text/S19990401A10010001001.txt"
pdf_to_text(pdf_path, txt_path)
print("PDF converted to text successfully!")
[output][1]
Подробнее здесь: https://stackoverflow.com/questions/791 ... -in-python
Как я могу извлечь чистый японский текст из папки PDF в Python ⇐ Python
Программы на Python
-
Anonymous
1729676553
Anonymous
This is my code
import os
import PyPDF2
# set the directory where the PDF files are located
pdf_directory = '/Users/humnerohit/Desktop/test_pdf_files'
# loop through each file in the directory
for filename in os.listdir(pdf_directory):
if filename.endswith('.pdf'):
# create a PDF file object
pdf_file = open(os.path.join(pdf_directory, filename), 'rb')
# create a PDF reader object
pdf_reader = PyPDF2.PdfFileReader(pdf_file)
# loop through each page in the PDF file
text = ''
for page_num in range(pdf_reader.numPages):
# extract the text from the page
page = pdf_reader.getPage(page_num)
text += page.extractText()
# close the PDF file object
pdf_file.close()
# create a text file object
text_file = open(os.path.join(pdf_directory, filename[:-4] + '.txt'), 'w')
# write the extracted text to the text file
text_file.write(text)
# close the text file object
text_file.close()
output
gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003/gai003/gai004/gai003
খࢢදொͷ࠶։ൃϏϧɾαϯϓϥβớຊࣾখỜͷখࢁ౻ࢢձͱ੪౻ਗ਼͕ࣾҰỏब͍͋ͭ͞ͷͨΊখຽใࣾΛ๚Εỏ தࣾ࣍ܒͱ࠙ஊỐủத৺֗ͷ֩ళฮͱͯ͠ỏ
ޙࠓؤுΓ·͢Ứͱ๊ෛΛड़ͨỐ
Ӻલ࠶։ൃϏϧͱͯ͠ҰࣣࣣʹΦồϓϯͨ͠αϯϓϥβỏࠓۀೋेೋỐ֩ςφϯτͷμΠΤồͱͷेؒͷܖΛऴ
͑ỏࡢશؗϦχỿồΞϧͨ͠ỐҰ෦ỏςφϯτ༠க͕Ε͕ͨỏ͜ͷ΄ͲΊͲ͕͍ͭͨͨΊỏখࢁલࣾࡢेೋ݄ͷגओ૯ձͰୀΛਃ͠ೖΕỐࡾ݄ࡾेͷऔకձͰঝೝ͞ΕͨỐ৽ࣾʹࡾͷ੪౻ਗ਼ࠪΛબỐখࢯࢁձʹबͨ͠Ố
খࢁձủࢥ͍ग़Λ͖ͤΓ͕ͳ͍ỨͱΛࡉΊủαϯϓϥβమೆͷ֩Ͱͳ͚ΕͳΒͳ͍Ứͱޙࠓͷళͮ͘ΓʹҙཉỐ੪౻ࣾủখࢁձͷԿͷҰͰ͖ͳ͍ͱࢥ͏͕ỏैۀһʹڠྗͯ͠Βỳͯؤுỳ͍͖͍ͯͨỨͱܾҙΛड़ͨỐݩ͔Βٿͷ۱
ʑ
·ͰỏڥѱԽ͕ਂࠁͷ߹͍Λ૿͍ͯ͠ΔỐμΠΦΩγϯỏ ԹஆԽỏࢎੑӍỏΦκϯഁյỏੜछݮগỏީؾมಈ
/gai007ỐڥࠃΛ͑ỏͦ͢Λ͛ͯ࣍ʑʹಥ͖͚ΒΕΔҟมʹỏҬͲ͏ཱ͔ͪ͏͔Ố͔ͭͯओʹެۀ࢈ͷࢹʹҙΛ͏͚ͩͩ
Текст извлекается из PDF-файла и сохраняется в той же папке с тем же именем и расширением .txt.
но кажется, что данные не преобразуется в японский текст.
Ожидается получение чистого японского текста в текстовый файл.
код, отображающий японский символ с нежелательными символами< /p>
import fitz
from mecab_text_cleaner import to_reading, to_ascii_clean
def pdf_to_text(pdf_path, txt_path):
# Open the PDF
pdf_document = fitz.open(pdf_path)
# Create a text file to store the extracted text
with open(txt_path, "w", encoding="utf-8") as text_file:
for page_number in range(len(pdf_document)):
page = pdf_document.load_page(page_number)
text = page.get_text()
text_file.write(text)
# Close the PDF
pdf_document.close()
# Example usage
pdf_path = "/Users/humnerohit/python_pdf_to_text/S19990401A10010001001.pdf"
txt_path = "/Users/humnerohit/python_pdf_to_text/S19990401A10010001001.txt"
pdf_to_text(pdf_path, txt_path)
print("PDF converted to text successfully!")
[output][1]
Подробнее здесь: [url]https://stackoverflow.com/questions/79102087/how-can-i-extract-clean-japanese-text-from-the-pdf-folder-in-python[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия