当前位置: 首页>>技术教程>>正文


在 Evince 中获取 pdf 文档的字数

,

问题描述

有什么方法可以获取我在 Evince(Ubuntu 的默认 pdf 查看器)中查看的 PDF 文档的字数?我能够将文档转换为文本文件并从终端获取字数,但我非常希望能够快速获取它们而无需使用终端。是否有任何插件可以做到这一点,或者它已经内置,我只是想念它?

附言我不想更改我的查看器,因为 Evince 是 Ubuntu 中的默认 PDF 查看器,我非常希望尽可能多地使用默认应用程序,因为其中很多,包括 Evince,都非常好。

最佳答案

您可以通过命令行执行此操作:

pdftotext filename.pdf - | tr -d '.' | wc -w

次佳答案

一个需要 zenity 和 evince 的快速 bash 脚本怎么样?当不带参数调用时,它会给你一个对话框,让你可以选择一个文件。当使用参数调用时(或在所述对话框之后),它会在 evince 中打开文件并为您提供一个包含字数的对话框。

换句话说,将以下内容复制到名为 evince-word-count.sh 或其他名称的文本文件中,将其保存在路径中的某个位置(例如 ~/bin/ ),使其可执行(通过 Nautilus 的右键单击和属性或使用 chmod +x ~/bin/evince-word-count.sh ),

#!/bin/bash
if [ "$#" -gt "0" ] ; then
    filename="$1"
else
    filename="$(zenity --file-selection)"
fi
evince "$filename" &
zenity --info --text "This PDF has $(pdftotext "$filename" - | tr -d '.' | wc -w) words"
exit 0

现在,在 nautilus 中的某些 PDF 上单击鼠标右键,选择“打开方式…”,然后使用 evince-word-count.sh 打开它。现在,当您打开 PDF 时,它会在 evince 中打开,并为您提供字数统计。

第三种答案

来自 Evince 邮件列表的 Olaf Leidinger 的回复:

I think such a feature is better suited for document editors, as they have more information on the document as a plain viewer and counting words is trivial. Take a PDF file as an example. What you see as text might actually be some kind of vector graphic shape. Even if the text is contained as such in the PDF file, those words you see might be composed of multiple “draw text at position (y,x)”-commands — e.g. in case of umlauts or end of line. So a single word might count as multiple words. Therefore I think it might be hard to implement such a feature reliably. Have a look at pdftotext to see what I mean.

第四种答案

我不相信这是可能的(这在技术上是可能的,但尚未实施)。

您必须记住,Evince 是一个文档查看器,而字数统计是编辑器中通常需要的一项功能(是的,我知道并非总是如此)。

您可能想 contact the Evince developers 并询问他们是否有兴趣实现此功能。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/12762.html,未经允许,请勿转载。