caj转pdf

caj转pdf


CAJ文件中国知网下载论文的一种.caj为后缀的文件,想要打开这种文件就必须下载知网的‘全球学术快报’或者CAJViewer软件。想要打开caj非常的麻烦。

caj2pdf是[github](https://link.zhihu.com/?target=https%3A//github.com/caj2pdf/caj2pdf)上的一个有1.7k star项目,是由github用户caj2pdf发布的,遵守GLWT开源许可的开源软件。项目地址:[https://github.com/caj2pdf/caj2pdf]()

本教程使用centos服务器。使用java操作caj转pdf(附代码)
一、代码获取

打开Github上caj2pdf网页,下载源代码文件caj2pdf.zip(通过git clone或者直接下载zip包)

在这里插入图片描述

2.解决依赖,caj2pdf至少需要3个依赖

1.查看python版本,如果版本低于3.3,可跳转另一篇文章 http://www.123ou.top/blog/8

[root@xxx Python-3.6.8]# python3 -V
Python 3.6.8

2.安装PyPDF2

sudo pip3 install PyPDF2

3.安装mutool

cd /usr/local #可自行选中安装目录
wget https://mupdf.com/downloads/archive/mupdf-1.20.3-source.tar.gz
tar -zxvf mupdf-1.20.3-source.tar.gz
cd mupdf-1.20.3-source
make
make install

安装编译mutool 报错 及解决方案见文章末尾

3.准备好环境,将下载的caj2pdf通过ftp上传到服务器。我是放在/usr/local目录下,可自行选中解压目录
cd /usr/local/caj2pdf/
ll

在这里插入图片描述

查看文件是否有执行(x)权限,没有权限的话执行以下

 chmod +x caj2pdf
 chmod +x jbi*

再次查看文件权限

在这里插入图片描述

创建软连接

 ln -s /usr/local/caj2pdf/caj2pdf /usr/bin/

用法

# 打印文件基本信息(文件类型、页面数、大纲项目数)
caj2pdf show [input_file]

# 转换文件
caj2pdf convert [input_file] -o/--output [output_file]

# 从 CAJ 文件中提取大纲信息并添加至 PDF 文件
## 遇到不支持的文件类型或 Bug 时,可用 CAJViewer 打印 PDF 文件,并用这条命令为其添加大纲
caj2pdf outlines [input_file] -o/--output [pdf_file]

示列

caj2pdf show test.caj
caj2pdf convert test.caj -o output.pdf
caj2pdf outlines test.caj -o printed.pdf
4.java代码示例
 /**
   * @param fileUrl caj文件存放路径 (/usr/local/caj2pdf/test.caj)
   * @param outPath 输出文件位置 (/mydata/file/test.pdf)
   */
public static String caj2pdf(String fileUrl, String outPath) {
        try {
            Runtime rt = Runtime.getRuntime();
            Long startTime = System.currentTimeMillis();
            String commands ="caj2pdf convert " + fileUrl + " -o " + outPath;
            System.out.println("开始执行caj2pdf,------->" + commands);
            Process p = rt.exec(commands);
            //等待执行完成
            p.waitFor();
            Long endTime = System.currentTimeMillis();
            System.out.println("执行完毕,耗时" + (endTime - startTime) + "ms");
            return "执行完毕,耗时" + (endTime - startTime) + "ms";

        } catch (Exception var8) {
            var8.printStackTrace();
            return "执行失败,error(" + var8.getMessage() + ")";
        }
    }

编译mupdf可能出现错误

1.1报错

无法验证 mupdf.com 的由 “/C=US/O=Let’s Encrypt/CN=R3” 颁发的证书

解决方案
yum install -y ca-certificates
2.1报错
g++: 错误:unrecognized command line option ‘-std=c++17’
make: *** [build/release/source/fitz/tessocr.o] 错误 1

出现这个编译错误的原因在g++ gcc 版本过低不支持C++17

解决办法 使用centos-release-scl安装高版本gcc参考连接
$sudo yum install gcc -y		#默认安装旧版本4.85
$sudo yum -y install centos-release-scl	#安装centos-release-scl
$sudo yum list all --enablerepo='centos-sclo-rh'		#列出scl有哪些源可以使用
$sudo yum list all --enablerepo='centos-sclo-rh'|grep gcc		# 查看scl中gcc版本

devtoolset-10-gcc.x86_64                   10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-gcc-c++.x86_64               10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-gcc-gdb-plugin.x86_64        10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-gcc-gfortran.x86_64          10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-gcc-plugin-devel.x86_64      10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-libgccjit.x86_64             10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-libgccjit-devel.x86_64       10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-libgccjit-docs.x86_64        10.2.1-11.2.el7        centos-sclo-rh
devtoolset-11-annobin-plugin-gcc.x86_64    9.82-1.el7.1           centos-sclo-rh
devtoolset-11-gcc.x86_64                   11.2.1-1.2.el7         centos-sclo-rh
devtoolset-11-gcc-c++.x86_64               11.2.1-1.2.el7         centos-sclo-rh
devtoolset-11-gcc-gdb-plugin.x86_64        11.2.1-1.2.el7         centos-sclo-rh
devtoolset-11-gcc-gfortran.x86_64          11.2.1-1.2.el7         centos-sclo-rh
devtoolset-11-gcc-plugin-devel.x86_64      11.2.1-1.2.el7         centos-sclo-rh
devtoolset-11-libgccjit.x86_64             11.2.1-1.2.el7         centos-sclo-rh
devtoolset-11-libgccjit-devel.x86_64       11.2.1-1.2.el7         centos-sclo-rh
devtoolset-11-libgccjit-docs.x86_64        11.2.1-1.2.el7         centos-sclo-rh

$sudo yum -y install devtoolset-11-gcc devtoolset-11-gcc-c++ devtoolset-11-binutils  #安装新版本
$scl enable devtoolset-11 bash      #临时切换,退出服务器恢复
$echo "source /opt/rh/devtoolset-11/enable" >>/etc/profile  #永久切换

2.2报错
In file included from thirdparty/freeglut/include/GL/freeglut.h:17,
                 from platform/gl/gl-app.h:36,
                 from platform/gl/gl-annotate.c:23:
thirdparty/freeglut/include/GL/freeglut_std.h:143:13: fatal error: GL/gl.h: 没有那个文件或目录
  143 | #   include <GL/gl.h>
      |             ^~~~~~~~~
compilation terminated.
make: *** [build/release/platform/gl/gl-annotate.o] 错误 1

错误原因:系统里面缺少OpenGl

解决方案, 配置OpenGL开发环境(也可以只安装opengl库)
sudo yum list mesa*	#三维计算机图形库,以开源形式实现了OpenGL的应用程序接口。
sudo yum install -y mesa*
sudo yum install -y freeglut*
sudo yum install -y *glew* 
2.3报错
In file included from thirdparty/freeglut/src/fg_internal.h:192,
                 from thirdparty/freeglut/src/fg_callbacks.c:29:
thirdparty/freeglut/src/x11/fg_internal_x11.h:42:10: fatal error: X11/extensions/XInput.h: 没有那个文件或目录
   42 | #include <X11/extensions/XInput.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [build/release/thirdparty/freeglut/src/fg_callbacks.o] 错误 1
解决方案
$sudo yum install -y libXi-devel.x86_64
2.4报错
In file included from thirdparty/freeglut/src/fg_internal.h:192,
                 from thirdparty/freeglut/src/fg_callbacks.c:29:
thirdparty/freeglut/src/x11/fg_internal_x11.h:47:14: fatal error: X11/extensions/Xrandr.h: 没有那个文件或目录
   47 | #    include <X11/extensions/Xrandr.h>
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [build/release/thirdparty/freeglut/src/fg_callbacks.o] 错误 1
解决方案
$sudo yum install -y libXrandr-devel.x86_64
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用Python将CAJ文件换为PDF,你可以使用caj2pdf工具。首先,你需要安装caj2pdf工具和其所需的依赖项。根据引用\[2\]中的描述,你可以在Anaconda Prompt中使用以下命令安装pypdf2依赖项: ``` pip install pypdf2 ``` 然后,你需要安装MuPDF工具,可以从MuPDF官方网站进行下载和安装。安装完成后,你可以使用以下命令将CAJ文件换为PDF: ``` caj2pdf convert \[input_file\] -o \[output_file\] ``` 其中,\[input_file\]是你要换的CAJ文件的路径,\[output_file\]是换后的PDF文件的路径。例如,如果你要将test.caj文件换为output.pdf文件,可以使用以下命令: ``` caj2pdf convert test.caj -o output.pdf ``` 如果你想从CAJ文件中提取大纲信息并将其添加到PDF文件中,可以使用以下命令: ``` caj2pdf outlines \[input_file\] -o \[pdf_file\] ``` 其中,\[pdf_file\]是要添加大纲信息的PDF文件的路径。例如,如果你要将test.caj文件的大纲信息添加到printed.pdf文件中,可以使用以下命令: ``` caj2pdf outlines test.caj -o printed.pdf ``` 请确保你已经正确安装了caj2pdf工具和其所需的依赖项,并按照上述命令使用正确的文件路径进行换。 #### 引用[.reference_title] - *1* [CAJ 文件换为 PDF 文件](https://blog.csdn.net/qq837993702/article/details/123759339)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [亲测好用的caj文件换成带目录的文字版PDF文件工具](https://blog.csdn.net/lyw19990827/article/details/124431490)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值