windows下用php开发类似百度文库应用需要的工具和问题

 大致原理:用swftools下的pdf2swf.exe转换 word,excel,ppt,pdf 文件。办公软件需要用到openoffice转换为pdf,,最后转换为swf文件,转换为swf需要注意的就是中文乱码的问题,传送给flexpaper.

requires:

1.flexpaper 下载地址:http://flexpaper.devaldi.com/download/

2.swftools 下载地址:http://www.swftools.org/download.html 配置环境变量或者使用绝对路径定位转换的exe文件

3.openoffice 下载地址: http://www.openoffice.org/启动服务(配置环境变量或者使用绝对路径定位转换的exe文件):soffice -headless -accept=”socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard

4.gkai00mp.ttf、Gbsn00lp.ttf 解决转换时候中文乱码 (自行搜索下载)

5.xpdf-chinese-simplified 下载地址:http://foolabs.com/xpdf/download.html

6.xpdfbin-win-3.03.zip 下载地址:http://foolabs.com/xpdf/download.html

question:

1.转换pdf路径的问题 “file:///d:\\xx\xxx\x”
2.转换swf时候flash版本问题。 -s flashversion=9 指定flash版本
3.转换swf时候中文乱码问题。-s languagedir=D:\xpdf\xpdf-chinese-simplified 指定字体位置
4.选中文本问题 转换swf的时候添加这个参数 -s storeallcharacters

中文乱码问题解决办法:

1.解压缩xpdfbin-win-3.03.zip到指定目录(D:\xpdf)
2.解压缩xpdf-chinese-simplified.tar.gz 到上面的目录下(D:\xpdf\xpdf-chinese-simplified)
3.拷贝两个字体文件gkai00mp.ttf、Gbsn00lp.ttf到CMap目录下(D:\xpdf\xpdf-chinese-simplified\CMap)
4.修改D:\xpdf\xpdf-chinese-simplified下的add-to-xpdfrc文件

#—– begin Chinese Simplified support package
cidToUnicode Adobe-GB1 D:\xpdf\xpdf-chinese-simplified\Adobe-GB1.cidToUnicode
unicodeMap ISO-2022-CN D:\xpdf\xpdf-chinese-simplified\ISO-2022-CN.unicodeMap
unicodeMap EUC-CN D:\xpdf\xpdf-chinese-simplified\EUC-CN.unicodeMap
unicodeMap GBK D:\xpdf\xpdf-chinese-simplified\GBK.unicodeMap
cMapDir Adobe-GB1 D:\xpdf\xpdf-chinese-simplified\CMap
toUnicodeDir D:\xpdf\xpdf-chinese-simplified\CMap
displayCIDFontTT Adobe-GB1 D:\xpdf\xpdf-chinese-simplified\CMap\gbsn00lp.ttf
displayCIDFontTT Adobe-GB1 D:\xpdf\xpdf-chinese-simplified\CMap\gkai00mp.ttf
#—– end Chinese Simplified support package

其他的问题看我写的这个类就好了。里面有标注

 

 

<?php
/**  * 文件转换swf程序,支持pdf,word,ppt,excel. 需要安装客户端软件。  * 需要安装的软件 openoffice   * swftools http://www.swftools.org/download.html 然后找到pdf2swf.exe,php需要调用这个应用程序来生成swf.  * flexpaper http://flexpaper.devaldi.com/download/ 用来显示swf  * @author youlipin <[email protected]>  * @date 2012-8-31  */
class Convert2Swf {
 
	public static $pdfFileDir;
	public static $pdfFileDirFixd; //调用openoffice api时候路径为"file:///d:\\xx\xxx\x"
	public static $swfFileDir;
 
	public static function setPdfDir($pdfDir) {
		self::$pdfFileDir = $pdfDir;
	}
 
	public static function setPdfDirFixd($pdfDirFixd) {
		self::$pdfFileDirFixd = $pdfDirFixd;
	}
 
	public static function setSwfDir($swfDir) {
		self::$swfFileDir = $swfDir;
	}
 
 
	/** 	 * pdf转换swf.需要安装flexpaper swftools. swftools配置环境变量(windows),还有需要注意flash版本      * @author youlipin <[email protected]> 	 * @date 2012-8-31 	 * @param inputFilePath string 输入pdf文件路径 	 * @param outFilePath string 输出swf文件路径 	 */
 
	public static function pdf2Swf($inputFile,$outputFile) {
		$command = "pdf2swf"; //命令
		$pdfFile = self::$pdfFileDir . $inputFile ; //输入文件
		$swfFile = self::$swfFileDir . $outputFile ; //输出文件
		$cmd = $command . ' -t ' . $pdfFile . ' -o ' . $swfFile . " -s flashversion=9 -s languagedir=D:\xpdf\xpdf-chinese-simplified -s storeallcharacters"; //解决转换时中文乱码问题
		echo $cmd;
		ob_start();
		system($cmd);
		ob_end_flush();
	}
 
	/** 	 * 调用openoffice的 API 	 */
 
	private static function makePropertyValue($name,$value,$osm){  
		$oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");  
		$oStruct->Name = $name;  
		$oStruct->Value = $value; 
		return $oStruct;  
	}
 
	private static function word2Pdf($officeFile, $pdfFile) { 
		$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed"); 
		$args = array(self::makePropertyValue("Hidden",true,$osm));  
		$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");  
		$oWriterDoc = $oDesktop->loadComponentFromURL(self::$pdfFileDirFixd.$officeFile,"_blank", 0, $args);  
		$export_args = array(self::makePropertyValue("FilterName","writer_pdf_Export",$osm));
		$oWriterDoc->storeToURL(self::$pdfFileDirFixd.$pdfFile,$export_args);  
		$oWriterDoc->close(true);
	}
 
}
 
?>  稍后更新整合sphinx

 

你可能感兴趣的:(百度文库)