栖霞酒店网站设计价格,网站设计规划书,en wordpress,网站制作报价是否合法pdf 转 word
一、思路
直接调用LibreOffice 命令进行文档转换的命令行工具 使用的前系统中必须已经安装了
libreofficelibreoffice已翻译的用户界面语言包: 中文 (简体)libreoffice离线帮助文档: 中文 (简体)上传字体
重点#xff1a;重点#xff1a;重点#xff1a;
亲…pdf 转 word
一、思路
直接调用LibreOffice 命令进行文档转换的命令行工具 使用的前系统中必须已经安装了
libreofficelibreoffice已翻译的用户界面语言包: 中文 (简体)libreoffice离线帮助文档: 中文 (简体)上传字体
重点重点重点
亲测 7.1.8版本pdf 转word后正常 7.4.6版本转出来的样式有问题都挤在一页重叠在一起。
二、软件安装下载
1. windows安装
下载 LibreOffice | LibreOffice 简体中文官方网站 - 自由免费的办公套件 a.安装 直接一键默认安装 环境变量在path前加入libreoffice安装路径如D:\Program Files\LibreOffice\program
进入dos窗口输入soffice 如果弹出libreoffice界面则表示安装成功
b. 中文包 另外再下载安装下以中文包此处略过
libreoffice已翻译的用户界面语言包: 中文 (简体)libreoffice离线帮助文档: 中文 (简体)
soffice --infilterwriter_pdf_import --convert-to doc 11种绕过CDN查找真实IP 方法.pdf 21
2 certos7版本安装 CentOS系统环境
[rootlocalhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)7.1.8包下载地址Index of /libreoffice/old/7.1.8.1/rpm/x86_64
## 下载下面三个包
wget https://downloadarchive.documentfoundation.org/libreoffice/old/7.1.8.1/rpm/x86_64/LibreOffice_7.1.8.1_Linux_x86-64_rpm.tar.gz
wget https://downloadarchive.documentfoundation.org/libreoffice/old/7.1.8.1/rpm/x86_64/LibreOffice_7.1.8.1_Linux_x86-64_rpm_helppack_zh-CN.tar.gz
wget https://downloadarchive.documentfoundation.org/libreoffice/old/7.1.8.1/rpm/x86_64/LibreOffice_7.1.8.1_Linux_x86-64_rpm_langpack_zh-CN.tar.gz解压并安装
## 主包
tar -xvf LibreOffice_7.1.8.1_Linux_x86-64_rpm.tar.gz
yum install ./LibreOffice_7.1.8.1_Linux_x86-64_rpm/RPMS/*.rpm -y## 已翻译的用户界面语言包: 中文 (简体)
tar -xvf LibreOffice_7.1.8.1_Linux_x86-64_rpm_langpack_zh-CN.tar.gz
yum install ./LibreOffice_7.1.8.1_Linux_x86-64_rpm_langpack_zh-CN/RPMS/*.rpm -y## 离线帮助文档: 中文 (简体)
tar -xvf LibreOffice_7.1.8.1_Linux_x86-64_rpm_helppack_zh-CN.tar.gz
yum install ./LibreOffice_7.1.8.1_Linux_x86-64_rpm_helppack_zh-CN/RPMS/*.rpm -y3. Debian 版本安装
root4f14d865967a:/# cat /etc/issue
Debian GNU/Linux 11 \n \lDebian 系统从下面地址下载安装包Index of /libreoffice/old/7.1.8.1/deb/x86_64 7.1.8包下载地址
wget https://downloadarchive.documentfoundation.org/libreoffice/old/7.1.8.1/deb/x86_64/LibreOffice_7.1.8.1_Linux_x86-64_deb.tar.gz
wget https://downloadarchive.documentfoundation.org/libreoffice/old/7.1.8.1/deb/x86_64/LibreOffice_7.1.8.1_Linux_x86-64_deb_helppack_zh-CN.tar.gz
wget https://downloadarchive.documentfoundation.org/libreoffice/old/7.1.8.1/deb/x86_64/LibreOffice_7.1.8.1_Linux_x86-64_deb_langpack_zh-CN.tar.gz解压并安装
## 主包
tar -xvf LibreOffice_7.1.8.1_Linux_x86-64_deb.tar.gz
dpkg -i LibreOffice_7.1.8.1_Linux_x86-64_deb/DEBS/*.deb## 离线帮助文档: 中文 (简体)
tar -xvf LibreOffice_7.1.8.1_Linux_x86-64_deb_helppack_zh-CN.tar.gz
dpkg -i LibreOffice_7.1.8.1_Linux_x86-64_deb_helppack_zh-CN/DEBS/*.deb## 已翻译的用户界面语言包: 中文 (简体)
tar -xvf LibreOffice_7.1.8.1_Linux_x86-64_deb_langpack_zh-CN.tar.gz
dpkg -i LibreOffice_7.1.8.1_Linux_x86-64_deb_langpack_zh-CN/DEBS/*.deb使用帮助 测试是否安装成功libreoffice7.1 -help 根据使用的版本自己调整命令版本号查看版本
[rootlocalhost testPdf2word]# libreoffice7.1 -version
Warning: -version is deprecated. Use --version instead.
LibreOffice 7.1.8.1 e1f30c802c3269a1d052614453f260e49458c82c4. 安装字体
安装字体是为了防止中文乱码问题处理
1查看fonts目录cat /etc/fonts/fonts.conf | grep fon 得知字体存放位置/usr/share/fonts
[rootlocalhost Fonts]# cat /etc/fonts/fonts.conf | grep fon
!DOCTYPE fontconfig SYSTEM fonts.dtd
!-- /etc/fonts/fonts.conf file to configure system font access --
fontconfigproblems to the fontconfig bugzilla system located at fontconfig.orgNote that the normal make install procedure for fontconfig is toreplace any existing fonts.conf file with the new version. Placedir/usr/share/fonts/dirdir/usr/share/X11/fonts/Type1/dir dir/usr/share/X11/fonts/TTF/dir dir/usr/local/share/fonts/dirdir prefixxdgfonts/dirdir~/.fonts/dircachedir/usr/lib/fontconfig/cache/cachedircachedir prefixxdgfontconfig/cachedircachedir~/.fontconfig/cachedir
/fontconfig
2: 新建/usr/share/fonts/Fonts文件夹 mkdir /usr/share/fonts/Fonts
3把Windows下的字体C:\Windows\Fonts下的宋体即 simsun.ttc上传到linux服务器 /usr/share/fonts/Fonts/ 路径下即可
[rootlocalhost Fonts]# ll
总用量 17788
-rw-r--r--. 1 root root 18214472 4月 21 09:39 SIMSUN.TTC4: 查看刚指定的字体
[rootlocalhost Fonts]# fc-list :langzh
/usr/share/fonts/Fonts/SIMSUN.TTC: 新宋体,NSimSun:style常规,Regular
/usr/share/fonts/Fonts/SIMSUN.TTC: 宋体,SimSun:style常规,Regular5至此安装成功
三、实现PDF转word文档
pdf 转 word 2003
参数说明
## --outdir为 输出目标
## --convert-to 转换格式libreoffice7.1 --infilterwriter_pdf_import --convert-to doc ip.pdf --outdir ./ 21pdf 转 word 2007
libreoffice7.1 --infilterwriter_pdf_import --convert-to docx ip.pdf --outdir ./ 21四、制作自己的镜像 运行容器 基于cypress/browsersdocker run --namebrowsers -itd cypress/browsers 进入容器安装 LibreOffice_7.1.8.1软件 进入browsers容器 使用上面的Debian 版本安装方式安装好 打包镜像docker commit 4f14d865967a 10.10.11.145:8082/cypress/browsers_libreoffice7.1:latest 查看打好镜像
[rootcert-admin-api-service ~]# docker images | grep browsers_libreoffice7.1
10.10.11.145:8082/cypress/browsers_libreoffice7.1 latest 5d2e6f5dc95b 3 minutes ago 3.34GB
登录镜像仓库sudo docker login 127.0.0.1:8082 -u 用户名 -p 密码
6.推送到镜像仓库
docker push 127.0.0.1:8082/cypress/browsers_libreoffice7.1:latest
五、遇到的坑
1. 版本问题
亲测 7.1.8版本pdf 转word后正常 7.4.6版本转出来的样式有问题都挤在一页重叠在一起。 解决方法安装7.1.8版本安装7.1.8版本安装7.1.8版本
2. 字体重叠问题 解决方法
为因是 html 转的 pdf ,然后再用 pdf 转为 word 出现字体重叠问题是因为使用粗体导致所以 html css 样式不要使用font-weight: bold;
六、go代码实现
使用 golang 执行 cmd 命令调用 libreoffice7实现 pdf 转 word
/*参数说明## --outdir 为 输出目文件夹路径## --convert-to 转换格式 例 doc / docx /pdfsourcePdfPath pdf源文件路径 例 staitc/download/ip.pdfcreateWordPath 生成的word文件夹路径 例 static/download/usr/local/bin/libreoffice7.1 --infilterwriter_pdf_import --convert-to doc staitc/download/ip.pdf --outdir staitc/download 21
*/
//Pdf2Word pdf 转 wordfunc Pdf2Word(sourcePdfPath, createWordDirPath string) (filePath string, err error) {argStr : fmt.Sprintf(libreoffice7.1 --infilterwriter_pdf_import --convert-to doc %s --outdir %s, sourcePdfPath, createWordDirPath)cmd : exec.Command(/bin/sh, -c, argStr)log.Println(cmd:--, cmd.String())// 方法一//stderr, err : cmd.StderrPipe()//if err ! nil {// log.Println(stderr1:--, err.Error())// return//}//stdout, err : cmd.StdoutPipe()//if err ! nil {// log.Println(stderr2:--, err.Error())// return//}//if err cmd.Start(); err ! nil {// log.Println(stderr3:--, err.Error())// return//}//outErr, err : io.ReadAll(stderr)//if err ! nil {// log.Println(stderr4:--, err.Error())// return//}//out, err : io.ReadAll(stdout)//if err ! nil {// log.Println(stderr5:--, err.Error())// return//}//if err cmd.Wait(); err ! nil {// log.Println(stderr6:--, err.Error())// return//}//log.Printf(Result: %s, outErr: %s; /n, out, outErr)// 方法二var out bytes.Buffervar stderr bytes.Buffercmd.Stdout outcmd.Stderr stderrerr cmd.Run()//log.Println(cmd.Run() failed:, fmt.Sprint(err): stderr.String())if err ! nil {log.Println(cmd.Run() failed22:, fmt.Sprint(err): stderr.String())return}log.Println(pdf2Word success . Result: out.String())//获取文件名带后缀filenameWithSuffix : path.Base(sourcePdfPath)//获取文件后缀fileSuffix : path.Ext(filenameWithSuffix)//获取文件名filenameOnly : strings.TrimSuffix(filenameWithSuffix, fileSuffix)filePath createWordDirPath / filenameOnly .docreturn filePath, nil
}
文章转载自: http://www.morning.dcccl.cn.gov.cn.dcccl.cn http://www.morning.attorneysportorange.com.gov.cn.attorneysportorange.com http://www.morning.qftzk.cn.gov.cn.qftzk.cn http://www.morning.xgzwj.cn.gov.cn.xgzwj.cn http://www.morning.rhzzf.cn.gov.cn.rhzzf.cn http://www.morning.lbgfz.cn.gov.cn.lbgfz.cn http://www.morning.kgqww.cn.gov.cn.kgqww.cn http://www.morning.xkwrb.cn.gov.cn.xkwrb.cn http://www.morning.wdxr.cn.gov.cn.wdxr.cn http://www.morning.xxwfq.cn.gov.cn.xxwfq.cn http://www.morning.lmxzw.cn.gov.cn.lmxzw.cn http://www.morning.gtcym.cn.gov.cn.gtcym.cn http://www.morning.djpps.cn.gov.cn.djpps.cn http://www.morning.hrpmt.cn.gov.cn.hrpmt.cn http://www.morning.tgts.cn.gov.cn.tgts.cn http://www.morning.sbrrf.cn.gov.cn.sbrrf.cn http://www.morning.fflnw.cn.gov.cn.fflnw.cn http://www.morning.lblsx.cn.gov.cn.lblsx.cn http://www.morning.nkkpp.cn.gov.cn.nkkpp.cn http://www.morning.mxnrl.cn.gov.cn.mxnrl.cn http://www.morning.wdykx.cn.gov.cn.wdykx.cn http://www.morning.wjlhp.cn.gov.cn.wjlhp.cn http://www.morning.kaakyy.com.gov.cn.kaakyy.com http://www.morning.ntzfj.cn.gov.cn.ntzfj.cn http://www.morning.lgtzd.cn.gov.cn.lgtzd.cn http://www.morning.qcdtzk.cn.gov.cn.qcdtzk.cn http://www.morning.rqqmd.cn.gov.cn.rqqmd.cn http://www.morning.fbxdp.cn.gov.cn.fbxdp.cn http://www.morning.xmpbh.cn.gov.cn.xmpbh.cn http://www.morning.mhmcr.cn.gov.cn.mhmcr.cn http://www.morning.dmxzd.cn.gov.cn.dmxzd.cn http://www.morning.wbfg.cn.gov.cn.wbfg.cn http://www.morning.pbtdr.cn.gov.cn.pbtdr.cn http://www.morning.dtnjr.cn.gov.cn.dtnjr.cn http://www.morning.ntlxg.cn.gov.cn.ntlxg.cn http://www.morning.cljmx.cn.gov.cn.cljmx.cn http://www.morning.nhlyl.cn.gov.cn.nhlyl.cn http://www.morning.flfdm.cn.gov.cn.flfdm.cn http://www.morning.daxifa.com.gov.cn.daxifa.com http://www.morning.slqzb.cn.gov.cn.slqzb.cn http://www.morning.smkxm.cn.gov.cn.smkxm.cn http://www.morning.yxwcj.cn.gov.cn.yxwcj.cn http://www.morning.hwbf.cn.gov.cn.hwbf.cn http://www.morning.yrjkp.cn.gov.cn.yrjkp.cn http://www.morning.bwqcx.cn.gov.cn.bwqcx.cn http://www.morning.rcklc.cn.gov.cn.rcklc.cn http://www.morning.zwdrz.cn.gov.cn.zwdrz.cn http://www.morning.myzfz.com.gov.cn.myzfz.com http://www.morning.lhptg.cn.gov.cn.lhptg.cn http://www.morning.rnmc.cn.gov.cn.rnmc.cn http://www.morning.bytgy.com.gov.cn.bytgy.com http://www.morning.xsfny.cn.gov.cn.xsfny.cn http://www.morning.qlhkx.cn.gov.cn.qlhkx.cn http://www.morning.bwfsn.cn.gov.cn.bwfsn.cn http://www.morning.bhmnp.cn.gov.cn.bhmnp.cn http://www.morning.gqjzp.cn.gov.cn.gqjzp.cn http://www.morning.nfccq.cn.gov.cn.nfccq.cn http://www.morning.nqmhf.cn.gov.cn.nqmhf.cn http://www.morning.sqhtg.cn.gov.cn.sqhtg.cn http://www.morning.tstwx.cn.gov.cn.tstwx.cn http://www.morning.yfffg.cn.gov.cn.yfffg.cn http://www.morning.qkzdc.cn.gov.cn.qkzdc.cn http://www.morning.ydmml.cn.gov.cn.ydmml.cn http://www.morning.fbbpj.cn.gov.cn.fbbpj.cn http://www.morning.grxyx.cn.gov.cn.grxyx.cn http://www.morning.jcffp.cn.gov.cn.jcffp.cn http://www.morning.ssxlt.cn.gov.cn.ssxlt.cn http://www.morning.clwhf.cn.gov.cn.clwhf.cn http://www.morning.skbkq.cn.gov.cn.skbkq.cn http://www.morning.rrdch.cn.gov.cn.rrdch.cn http://www.morning.rjjys.cn.gov.cn.rjjys.cn http://www.morning.kwblwbl.cn.gov.cn.kwblwbl.cn http://www.morning.wklmj.cn.gov.cn.wklmj.cn http://www.morning.dlbpn.cn.gov.cn.dlbpn.cn http://www.morning.qmkyp.cn.gov.cn.qmkyp.cn http://www.morning.npcxk.cn.gov.cn.npcxk.cn http://www.morning.brlgf.cn.gov.cn.brlgf.cn http://www.morning.ngpdk.cn.gov.cn.ngpdk.cn http://www.morning.khpx.cn.gov.cn.khpx.cn http://www.morning.mngyb.cn.gov.cn.mngyb.cn