如何使用python从doc,docx和pdf文件中获取基于页面的字数统计?

时间:2019-01-18 07:11:36

标签: python

我的情况是,我正在尝试使用page based word count获得python。我尝试了下面的代码,现在我可以得到字数统计,但是我正在努力获取基于页面的字数统计。请提供一些建议和代码行。

import os
import os.path
import time
import string
import urllib

def text_file(inF):

    num_lines = 0
    num_words = 0
    num_chars = 0

    with open(inF, 'r') as input_file:
        for line in input_file:
            num_lines += 1
            line_words = line.split()
            num_words += len(line_words)
            for word in line_words:
                num_chars += len(word)

    file = open(inF, 'r') 
    print 'File Content: ' + file.read() 
    print 'File Word: ' + num_words

text_file('Sample.txt')

期望输出:

  

总页数:2页01:120字页面02:220字

0 个答案:

没有答案