在Centos上的安装swftools+openoffice+unoconv
swftools的安装 1.安装所需的库和组件yum install gcc* automake zlib-devel libjpeg-devel giflib-devel freetype-devel t1lib-devel2.下载并编译安装SWFTOOLS cd /usr/local/srcwget http://www.swftools.org/swftools-0.9.1.tar.gztar vxzf swftools-0.9.1.tar.gzcd swftools-0.9.1./configure –prefix=/usr/local/swftoolsmakemake install3、设置swftools环境变量,使pdf2swf成为一个可执行命令vi /etc/profileexport PATH=$PATH:/usr/local/swftools/bin/执行下source /etc/profile 使环境变量生效。4.安装xpdf语言包,下载xpdf-chinese-simplified.tar.gz文件,解压到/usr/local下,编辑add-to-xpdfrc文件,如下:– 注:需要百度搜索下载xpdf-chinese-simplified.tar.gz 官方的下载太慢了。另外要将windows 字体库中的常用字体复制一份到/usr/share/fonts/winvi /usr/local/xpdf-chinese-simplified/add-to-xpdfrcfontDir /usr/share/fonts/windisplayCIDFontTT Adobe-GB1 /usr/share/fonts/win/simhei.ttfswftools 对中文乱码问题直接将windows系统的相关字体复制到linux字体目录下windows字体目录 c:\windows\fontslinux字体目录 /usr/share/fonts目前我只复制了以下字体simfang.ttf 仿宋体 simhei.ttf 黑体 simkai.ttf 楷体simsun.ttf 宋体和新宋体,原文件名simsun.ttctahoma.ttf tahoma字体tahomabd.ttf tahoma字体的粗体形式verdana.ttf verdana字体verdanab.ttf verdana字体的粗体形式verdanai.ttf verdana字体的斜体形式verdanaz.ttf verdana字体的粗体+斜体形式 在CentOS目录里新建一个win文件夹# mkdir /usr/share/fonts/win# chmod644 /usr/share/fonts/win/*将以上字体文件复制到/usr/share/fonts/win目录下执行# mkfontscale# mkfontdir # mkfont命令是生成win目录下所包含的字体的索引信息# fc-cache # fc-cache命令更新字体缓存# fc-cache -f –v5、最后使用如下转换命令测试:– 注:1.pdf是要存在的文件//转化为swfpdf2swf -s languagedir=/usr/local/xpdf-chinese-simplified -T 9 -s poly2bitmap -s zoom=150 -s flashversion=9 “/usr/local/src/1.pdf” -o “/usr/local/src/1.swf”//转化为txt纯文本pdftotext -q “/usr/local/src/1.pdf” “/usr/local/src/1.txt”openoffice的安装 1.安装OpenOfficeyum install openoffice.org-writer yum install openoffice.org-calc yum install openoffice.org-draw openoffice.org-impress–注:文件安装在 /usr/lib/libreoffice/program 下面启动openoffice服务/usr/lib64/libreoffice/program/soffice.bin “–accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager” –norestore –nofirststartwizard –nologo –headless &如果报错,则虚拟一个x桌面Xvfb :2 -screen 0 800x600x24 2> /dev/null &上面命令可能不执行,需要安装一个serveryum install xorg-x11-server-Xvfb导入环境变量export DISPLAY=localhost:0.02.安装OpenOffice SDK3.3– wget http://ftp.nluug.nl/office/openoffice/stable/3.3.0/OOo-SDK_3.3.0_Linux_x86-64_install-rpm_en-US.tar.gztar -zxvf OOo-SDK_3.3.0_Linux_x86-64_install-rpm_en-US.tar.gzcd OOO330_m20_native_packed-1_en-US.9567/RPMS/rpm -ivh *.rpm –nodeps用到ms office转换程序,需要启动一个服务监听程序,监听8100端口。可以通过设置让系统自动启动该服务。1、创建一个执行脚本runoffice,内容如下#vi /usr/sbin/runoffice/usr/bin/nohup /usr/lib64/libreoffice/program/soffice.bin “–accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager” –norestore –nofirststartwizard –nologo –headless &#chmod 775 /usr/sbin/runoffice2、创建启动脚本#cat /etc/rc.d/rc.local$ cat /etc/rc.local#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don’t# want to do the full Sys V style init stuff.xhost +export DISPLAY=:0.0/usr/sbin/runoffice >/var/log/rc.local.logtouch /var/lock/subsys/local上述脚本会在所有服务启动完之后执行。注意xhost +export DISPLAY=:0.0要不然是不会启动成功的,会显示如下错误信息/program/soffice.bin X11 error: Can’t open display: Set DISPLAY environment variable, use -display option or check permissions of your X-Server (See “man X” resp. “man xhost” for details)加上那两行就会顺利启动了。3、在 Centos上作为服务启动经过一段时间的试用,发现2中的启动脚本有时能够成功,有时不能成功。经过google搜索,有个服务启动脚本,经过修改以后,可以适用。3.1 需要安装Xvfb,是一个虚拟XServerIn the X Window System, Xvfb or X virtual framebuffer is an X11 server that performs all graphical operations in memory, not showing any screen output. From the point of view of the client, it acts exactly like any other server, serving requests and sending events and errors as appropriate. However, no output is shown. This virtual server does not require the computer it is running on to even have a screen or any input device. Only a network layer is necessary.它的图形只存在内存中,而不显示。#yum seach Xvfb#yum xorg-x11-server-Xvfb.x86_643.2 在/etc/init.d/创建服务启动脚本下面是修改后适合Centos 6.3的 脚本内容#cat /etc/init.d/soffice#!/bin/bash# Boot open office so that Alfresco can do transforms.# chkconfig: 2345 55 25# description: OpenOffice Headless## processname: soffice# source function library. /etc/rc.d/init.d/functionsRETVAL=0VDISPLAY=’99′SOFFICE_PATH=’/usr/lib64/libreoffice/program/’SOFFICE_ARGS1=”-nofirststartwizard -nologo -headless -display :$VDISPLAY ”SOFFICE_ARGS2=’-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager’SOFFICE_PIDFILE=/var/run/soffice.bin.pidXVFB=/usr/bin/XvfbXVFB_ARGS=”:$VDISPLAY -screen 0 800x600x8 -fbdir /var/run”XVFB_PIDFILE=/var/run/xvfb.pidstart_soffice() { echo -n $”Starting OpenOffice”$SOFFICE_PATH/soffice.bin $SOFFICE_ARGS1 $SOFFICE_ARGS2 >/dev/null 2>&1 &[ $? -eq 0 ] && echo_success || echo_failurepidof soffice.bin > $SOFFICE_PIDFILEecho}start_xvfb() { echo -n $”Starting Xvfb”$XVFB $XVFB_ARGS >/dev/null 2>&1 &[ $? -eq 0 ] && success || failurepidofproc Xvfb > $XVFB_PIDFILEecho}start() { start_xvfbsleep 3start_soffice}stop() { echo -n $”Stopping OpenOffice”killproc soffice.binechoecho -n $”Stopping Xvfb”killproc Xvfbecho}case “$1″ instart)start;;stop)stop;;restart)stopstart;;*)echo $”Usage: $0 {start|stop|restart}”esac#chkconfig soffice on/etc/init.d/soffice start##################################################3.1 安装unoconvwget http://pkgs.repoforge.org/unoconv/unoconv-0.5-1.el6.rf.noarch.rpmrpm -ivh unoconv-0.5-1.el6.rf.noarch.rpm –nodeps –force或直接 yum install unoconv查看之前安装的unoconv rpm 命令rpm -qa |grep -i unoconv 删除它用rpm -e unoconv-0.5-1.el6.rf.noarch测试:unoconv -help –nogpgcheck//!!! 将某个txt转化为pdf !!!unoconv -f pdf test.txt