The recent use of the document online preview function, did not touch before, everything from scratch, the whole period of time finally realized, now the method to share to everyone!
First, the main ideas
Convert documents in other formats (Office documents, TXT, pictures, and so on) through OpenOffice to PDF documents, and then through Swftools (http://www.swftools.org/ Convert PDF documents to SWF-formatted documents, and finally display SWF-formatted documents with Flexpaper, enabling you to preview documents in multiple formats.
Using the tool to download from the Internet, very easy to find.
Second, the realization process
1. Other documents converted to PDF
To start OpenOffice with a command:
Run->cmd, enter the following command
CD/D E:/openoffice/program & soffice-headless-accept= "SOCKET,HOST=127.0.0.1,PORT=8100;URP;"- Nofirststartwizard
or enter the program directory in CMD and enter soffice-headless-accept= "SOCKET,HOST=127.0.0.1,PORT=8100;URP;"-nofirststartwizard
PHP Implementation code:
Set_time_limit (0);
function Makepropertyvalue ($name, $value, $OSM) {
$oStruct = $osm->bridge_getstruct ("Com.sun.star.beans.PropertyValue");
$oStruct->name = $name;
$oStruct->value = $value;
return $oStruct;
}
function Word2pdf ($doc _url, $output _url) {
$OSM = new COM ("Com.sun.star.ServiceManager") or Die ("Sure this OpenOffice.org is INSTALLED.N");
$args = Array (Makepropertyvalue ("Hidden", True, $OSM));
$oDesktop = $osm->createinstance ("Com.sun.star.frame.Desktop");
$oWriterDoc = $oDesktop->loadcomponentfromurl ($doc _url, "_blank", 0, $args);
$export _args = Array (Makepropertyvalue ("FilterName", "Writer_pdf_export", $OSM));
$oWriterDoc->storetourl ($output _url, $export _args);
$oWriterDoc->close (TRUE);
}
$doc _file = ' D:/wamp/www/onlineread/uploads/docfile.doc ';
$output _file = ' d:/wamp/www/onlineread/uploads/pdffile.pdf ';
$doc _file = "file:///". $doc _file;
$output _file = "file:///". $output _file;
Word2pdf ($doc _file, $output _file);
2.PDF converted to SWF and displayed
PHP Implementation code:
$source = ' d:/wamp/www/onlineread/uploads/pdffile.pdf ';
$convert = ' d:/wamp/www/onlineread/uploads/swffile.swf ';
$command = "D:/wamp/www/onlineread/public/swftools/pdf2swf.exe-t". $source. "-S Flashversion=9-o". $convert;
$WshShell = new COM ("Wscript.Shell");
Execute cmd command
$oExec = $WshShell->run ("cmd/c". $command, 0, true);//If the conversion succeeds $oexec value is 0
swf Display:
<div style= "Width:100%;height:800px;display:block;margin-left:auto;margin-right:auto; margin-top:20px; " >
<a id= "Viewerplaceholder" style= "Width:100%;height:800px;display:block;" ></a>
<script type= "Text/javascript" >
var path= "/<?= $convert?>";//PHP variables, if not implemented can consider the next sentence of the wording
var path= "/<?php Echo $convert?>";
var fp = new Flexpaperviewer (
' __public__/flexpaper/flexpaperflash/flexpaperviewer ',
' Viewerplaceholder ', {config: {//config parameters, can be changed to their own
Swffile:escape (Path),
Scale:1,
Zoomtransition: ' EaseOut ',
zoomtime:0.5,
zoominterval:0.2,
Fitpageonload:false,
Fitwidthonload:false,
Printenabled:true,
Fullscreenasmaxwindow:false,
Progressiveloading:false,
minzoomsize:0.2,
Maxzoomsize:5,
Searchmatchall:false,
Initviewmode: ' Portrait ',
Viewmodetoolsvisible:true,
Zoomtoolsvisible:true,
Navtoolsvisible:true,
Cursortoolsvisible:true,
Searchtoolsvisible:true,
Localechain: ' en_US '
}});
</script>
</div>
3. Pre-run preparation
You need to make the following settings first, or you may get an error during the run!
Control Panel-Administrative Tools-Component Services-computer-My Computer-DOCM configuration, locate the OpenOffice Service Manager (Ver 1.0) Right-click property and configure it as shown:
Locate OpenOffice Service Manager (Ver 1.0) as shown:
In the pop-up box, select ' Security ' and edit ' launch and Activation permissions ' and ' access rights ' separately:
Click Add in the ' Launch and Activation permissions ' pop-up box and enter everyone:
to set permissions for everyone:
In the ' Access ' pop-up box, click Add, and enter everyone:
To set the Everyone permission:
In the Properties dialog box, select ' Identity ' and select ' Interactive user ':
If you encounter problems with COM class instantiation failures, open the PHP configuration file, remove the semicolon in front of com.allow_dcom=true, and add Extension=php_com_dotnet.dll, because php5.4 will not embed COM anymore.
Do not forget to restart the service after setting it up well!
PHP Online preview function under Windows