使用 unoconv 将 doc, xls, ppt 转换成 pdf

安装 openoffice 依赖

[shell]
yum install unoconv openoffice.org-core openoffice.org-headless openoffice.org-pyuno openoffice.org-sdk openoffice.org-writer openoffice.org-calc openoffice.org-draw libreoffice-langpack-zh-Hans.x86_64 -y

yum install font-chinese cabextract rpm-build -y
fc-cache -f -v

unoconv -f pdf test.docx
[/shell]

通过word模板实现pdf内容替换
[shell]
#解压word文件
unzip test.docx -d tmp

#替换word模板
sed -i ‘s/{__TITLE__}/title/g’ tmp/word/document.xml

#重新打包word文件
cd tmp && zip -rq ../new.docx \[Content_Types\].xml customXml/ docProps/ _rels/ word/
cd ../ && rm -rf tmp
unoconv -f pdf new.docx
[/shell]

发表评论