openoffice
要实现文档转换为PDF,可利用jodconverter开源jar实现文档的转换。 而jodconverter的转换原理是利用openoffice实现转换。而jodconverter必须要有Java环境才可转换。故要实现word -> pdf -> swf
需要安装的软件有
- openoffice
- jodconverter jar包
- swftools
- jdk/jre
word转换PDF
function word2pdf ($wordpath, $outPdfPath, $jodconverterPath) {
if (empty($wordpath)) return false;
try {
$p = "java -jar ". $jodconverterPath . ' ' . $wordpath . ' ' . $outPdfPath;
exec($p);
return true;
} catch (Exception $e) {
return false;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
在执行转换前, 必须先启动openoffice服务,可直接用cmd窗口进入openoffice的安装目录即
C:\User\Administrator>cd D:\openoffice\program
C:\User\Administrator>d:
D:\openoffice\program>soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
PDF2SWF
function pdf2swf($pdf2swf, $swfPath, $pdfpath){
$c = $pdf2swf . ' -o ' . $swfPath . ' -T -z -t -f ' . $pdfpath . ' -s flashversion=9';
exec($c);
}
我的测试代码如下
<?php
$startOpenofficeExc = 'soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard';
$openoffice = 'D://openoffice//program//';
$jodconverter = 'D://jodconverter//jodconverter-2.2.2//lib//jodconverter-cli-2.2.2.jar';
$testDoc = 'F://duanxin.doc';
$testOut = 'F://duanxin.pdf';
$javaPath = 'C:\Program Files\Java\jdk1.7.0_79\bin\\';
$pdf2swf = 'D://SWFTools//pdf2swf.exe';
function word2pdf ($wordpath, $outPdfPath, $jodconverterPath) {
if (empty($wordpath)) return false;
try {
$p = "java -jar ". $jodconverterPath . ' ' . $wordpath . ' ' . $outPdfPath;
exec($p);
return true;
} catch (Exception $e) {
return false;
}
}
if(word2pdf($testDoc, $testOut, $jodconverter)) {
header("location: show.php?swfName=duanxin.swf");
} else {
echo 'error';
}
function pdf2swf($pdf2swf, $swfPath, $pdfpath){
$c = $pdf2swf . ' -o ' . $swfPath . ' -T -z -t -f ' . $pdfpath . ' -s flashversion=9';
exec($c);
}
echo '--------------------------------------------------------------------------<br>';
$swfPath2 = 'F://duanxin.swf';
$pdfpath2 = 'F://duanxin.pdf';
pdf2swf($pdf2swf, $swfPath2, $pdfpath2);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
显示SWF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>查看</title>
<meta charset="utf-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="js/flexpaper_flash.js"></script>
<script language="JavaScript">
function Request(argname) {
var url = document.location.href;
var arrStr = url.substring(url.indexOf("?")+1).split("&");
for(var i =0;i<arrStr.length;i++) {
var loc = arrStr[i].indexOf(argname+"=");
if(loc!=-1) {
return arrStr[i].replace(argname+"=","").replace("?","");
break;
}
}
return "";
}
</script>
<style>
body { margin: 0px;}
</style>
</head>
<body >
<div style="position:absolute;left:10px;top:10px;">
<a id="viewerPlaceHolder" style="width:690px;height:790px;display:block"></a>
<script type="text/javascript">
var flexpaper = new FlexPaperViewer(
'FlexPaperViewer',
'viewerPlaceHolder', { config : {
SwfFile : encodeURI("upload/"+Request("swfName")),
ZoomInterval : 0.2,
MinZoomSize : 0.2,
MaxZoomSize : 1.4,
ZoomTime : 0.5,
Scale : 1,
ZoomTransition : 'easeOut',
FitPageOnLoad : true,
FitWidthOnLoad : true,
FullScreenAsMaxWindow : false,
ProgressiveLoading : true,
SearchMatchAll : true,
ViewModeToolsVisible : true,
ZoomToolsVisible : true,
NavToolsVisible : true,
CursorToolsVisible : true,
SearchToolsVisible : true,
localeChain: 'zh_CN'
}});
</script>
</div>
</body>
</html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
flexpaper_flash.js, FlexPaperViewer.swf 下载地址
暂无评论