最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】用xpdf的pdftotext打算把PDF转换为HTML时出错:Permission Error: Copying of text from this document is not allowed

工作和技术 crifan 4884浏览 0评论

【问题】

折腾:

【未解决】将不可拷贝复制的PDF中的表格数据导出并转换为xml格式数据

期间,想要用xpdf的pdftotext把一个禁止拷贝的pdf文件转换为html,但是出错了:

D:\tmp\dev_tools\python\pdf\xpdfbin-win-3.03\xpdfbin-win-3.03\bin64>pdftotext.exe
pdftotext version 3.03
Copyright 1996-2011 Glyph & Cog, LLC
Usage: pdftotext [options] <PDF-file> [<text-file>]
  -f <int>          : first page to convert
  -l <int>          : last page to convert
  -layout           : maintain original physical layout
  -fixed <fp>       : assume fixed-pitch (or tabular) text
  -raw              : keep strings in content stream order
  -htmlmeta         : generate a simple HTML file, including the meta information
  -enc <string>     : output text encoding name
  -eol <string>     : output end-of-line convention (unix, dos, or mac)
  -nopgbrk          : don't insert page breaks between pages
  -opw <string>     : owner password (for encrypted files)
  -upw <string>     : user password (for encrypted files)
  -q                : don't print any messages or errors
  -cfg <string>     : configuration file to use in place of .xpdfrc
  -v                : print copyright and version info
  -h                : print usage information
  -help             : print usage information
  --help            : print usage information
  -?                : print usage information

D:\tmp\dev_tools\python\pdf\xpdfbin-win-3.03\xpdfbin-win-3.03\bin64>pdftotext.exe -htmlmeta D:\tmp\tmp_dev_root\python\answer_question\self\pdf_table_to_xml\pdf\spec183r21.0.pdf hart183.html
Permission Error: Copying of text from this document is not allowed.

【解决过程】

1.参考了一堆:

pdftohtml / Discussion / Help:Copying of text from document isn’t allowed

#145558 – xpdf doesn’t want me to copy text from document. it’s none of it’s business – Debian Bug report logs

但是无解。

2.这里:

http://www.cs.cmu.edu/~dst/Adobe/Gallery/xpdf-0.93-ro-removed.patch

有补丁,据说可以解决此问题。

但是该补丁是c语言代码,而我此处的xpdf是二进制版本的。

没法去使用该补丁。放弃之。

3.再去参考:

Kindle Paperwhite电子书转换工具集

的“

Okular 电子书阅读器,可以将PDF转换成html。Linux自带基于xpdf的pdf2html无法会遇到如下错误。

Permission Error: Copying of text from this document is not allowed.

好像只支持转换成txt

Use Okular. (on Linux)

If you get “Copying forbidden by DRM”, simply go to “Settings” -> “Configure Okular” and in the “General Options”, “Program Feature” disable “Obey DRM limitations”.

真是超级笨,pdftohtml有一个选项叫-nodrm,加上这个选项就OK了。”

所以去进入Ubuntu系统中,找那个pdf2html的工具,试试效果。

4.打开Ubuntu,去找找pdf2html,没找到,但是可以找到并安装xpdf:

crifan@crifan-Ubuntu:~$ pdf2html
未找到 'pdf2html' 命令,您要输入的是否是:
 命令 'odf2html' 来自于包 'docvert' (universe)
pdf2html:未找到命令
crifan@crifan-Ubuntu:~$ xpdf
程序“xpdf”尚未安装。 您可以使用以下命令安装:
sudo apt-get install xpdf
crifan@crifan-Ubuntu:~$ sudo apt-get install xpdf
[sudo] password for crifan: 
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会安装下列额外的软件包:
  gsfonts-x11 lesstif2
下列【新】软件包将被安装:
  gsfonts-x11 lesstif2 xpdf
升级了 0 个软件包,新安装了 3 个软件包,要卸载 0 个软件包,有 26 个软件包未被升级。
需要下载 786 kB 的软件包。
解压缩后会消耗掉 2,135 kB 的额外空间。
您希望继续执行吗?[Y/n]y
获取:1 http://cn.archive.ubuntu.com/ubuntu/ raring/universe lesstif2 i386 1:0.95.2-1.1 [661 kB]
获取:2 http://cn.archive.ubuntu.com/ubuntu/ raring/main gsfonts-x11 all 0.22 [9,108 B]
获取:3 http://cn.archive.ubuntu.com/ubuntu/ raring-updates/universe xpdf i386 3.03-10ubuntu1.1 [115 kB]
下载 786 kB,耗时 3秒 (245 kB/s)
Selecting previously unselected package lesstif2:i386.
(正在读取数据库 ... 系统当前共安装有 165577 个文件和目录。)
正在解压缩 lesstif2:i386 (从 .../lesstif2_1%3a0.95.2-1.1_i386.deb) ...
Selecting previously unselected package gsfonts-x11.
正在解压缩 gsfonts-x11 (从 .../gsfonts-x11_0.22_all.deb) ...
Selecting previously unselected package xpdf.
正在解压缩 xpdf (从 .../xpdf_3.03-10ubuntu1.1_i386.deb) ...
正在处理用于 fontconfig 的触发器...
正在处理用于 mime-support 的触发器...
正在处理用于 man-db 的触发器...
正在处理用于 bamfdaemon 的触发器...
Rebuilding /usr/share/applications/bamf-2.index...
正在处理用于 desktop-file-utils 的触发器...
正在处理用于 gnome-menus 的触发器...
正在设置 lesstif2:i386 (1:0.95.2-1.1) ...
正在设置 gsfonts-x11 (0.22) ...
正在设置 xpdf (3.03-10ubuntu1.1) ...
正在处理用于 libc-bin 的触发器...
ldconfig deferred processing now taking place
crifan@crifan-Ubuntu:~$ 

然后去使用:

ubuntu search and open xpdf

running xpdf open pdf

然后再去找pdf文件去打开:

found pdf then open in xpdf

然后另存为:

save as in xpdf

结果没有可以到处为html的选项。

 

【总结】

最终结果是:

没有搞定此问题,还是无法用pdftotext将pdf转为文本或html。

转载请注明:在路上 » 【未解决】用xpdf的pdftotext打算把PDF转换为HTML时出错:Permission Error: Copying of text from this document is not allowed

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
87 queries in 0.170 seconds, using 22.13MB memory