PHP implements the effect of copying Baidu Library and douding online documents (word, excel, ppt to flash ),
The example in this article describes how PHP implements the online documents of imitation Baidu Library and douding. We will share this with you for your reference. The details are as follows:
Because the project needs to implement functions similar to those of Baidu Library, and I am working on a project by myself, I want to find free ready-made products for use. The same is found on the Internet. As follows:
Flash papersupports direct conversion of officedocument (.doc,.xls,.ppt) to PDF or SWF, which is fast and effective. Unfortunately, Flash Paper V2.2 has not been updated. After installing Flash paper, you can directly use the command to call flashprinter.exe to implement batch conversion.
Example: C: \ FlashPaper2.2 \ FlashPrinter.exe C: \ flex .ppt-o C: \ flex .swf
Download a FlashPaper. After installation, a virtual printer will appear in the control panel printer. This indicates that the installation is successful, I tried to install both 32-bit and 64-bit Windows 7.
In the command line, try the above command and adjust the path according to your own. After the command is executed, it indicates you can use it.
Next, php is used. php uses exec or system to execute cmd commands, for example:
Copy codeThe Code is as follows: exec ("C: \ FlashPaper2.2 \ FlashPrinter.exe C: \ flex ..ppt-o C: \ flex .swf ");
Configure the following php before executing this command. ini sets the security mode to off (safe_mode = Off), or the path to allow the exe is set in safe_mode_exec_dir =.
Run the test successfully!
All of these can be found on the Internet. Since I use the wordsuffix .docx for office2007, the conversion fails. I still cannot find the cause on the Internet. Accidentally, I changed the.docx to a.doc, in this case, I do not understand, because it is possible to convert .docx directly under cmd. Similarly, if you want to convert a 2007 ppt file, you can convert the file by removing the suffix x in excel.
Recently, there was a project that needed to use DOCIN-like document conversion and reading functions, so I began to look for relevant information and finally summarized the two solutions, the following describes the implementation of the two methods.
First, convert the DOC file using flash paper to generate SWF directly. This is very simple. Download a flash paper and install it. We can call it using CMD in the program, the called command is: C: \ Program Files \ Macromedia \ FlashPaper 2 \ FlashPrinter.exe xxx.ppt-o xxx.swf. However, after my test, this item has a major defect, it cannot be used concurrently. That is to say, only one document can be converted at the same time. I don't know if there are other ways to solve this problem. If you have a solution, please let me know, the conversion principle of flash paper is as follows: create a virtual printer, open the file, virtual print, and obtain the printed content to directly generate SWF. Therefore, to convert a file, you need to run a virtual printer ~~~ The document printing and opening window appears in the middle. This solution does not meet my requirements. PASS it directly.
Type 2: Use open-source software OPENOFFICE to convert a document to a PDF file, and convert a PDF file to a SWF file through SWFTOOLS. There are many things to be used, as shown below. This solution can be run in a Microsoft system or in a LINUX system. I ran it on the CENTOS5.5 character page. The process is as follows:
First install and install the CENTOS5.5 system. The installation process is no longer long.
After installing the system, download all required software packages: The software packages we use include
# wget http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/C DS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/ jdk-6u20-linux-i586.bin?BundledLineItemUUID=fdeJ_hC vMVcAAAEpabADyW5K&OrderID=JRuJ_hCvMlQAAAEpWrADyW5K& ProductID=guBIBe.oc_wAAAEnaDJHqPYe&FileName=/jdk-6u 20-linux-i586.bin # wget http://download.services.openoffice.org/files/loca lized/zh-cn/3.2.0/OOo_3.2.0_LinuxIntel_install_zh-C N.tar.gz # wget http://www.swftools.org/swftools-0.9.1.tar.gz wget http://apache.etoak.com/tomcat/tomcat-6/v6.0.26/bi n/apache-tomcat-6.0.26.tar.gz
There is also an openoffice plug-in based on which all our applications are based: jodconverter
All right, the software package is ready, and the ready _ ready
Install JDK and tomcat first. The installation process will not be too long.
Next, install openoffice,
# tar zxvf OOo_3.2.0_LinuxIntel_install_zh-CN.tar.gz #cd OOO320_m12_native_packed-1_zh-CN.9483/RPMS #rpm -ivh –force –nodeps *.rpm
In this way, the OPENOFFICE is installed. If your system does not have a Chinese font, you can install the Chinese font. Otherwise, the exported PDF will be garbled.
Install swftools after installing openoffice,
# tar zxvf swftools-0.9.1.tar.gz #cd swftools-0.9.1 # ./configure –prefix=/usr/local/swftools/ # make && make install
By now, all the installed software has been installed.
Start all the required services,
Start OPENOFFICE as a Service. The startup command is as follows:
Copy codeThe Code is as follows: #/opt/openoffice. org3/program/soffice-headless-accept = "socket, host = 127.0.0.1, port = 8100; urp;"-nofirststartwizard &
Start TOMCAT and use jodconverter as the WEB app service. In this case, we first decompress jodconverter-webapp-2.2.2.zip, And put jodconverter-webapp-2.2.2.war In the TOMCAT root directory. After running TOMCAT, the APP folder is automatically generated, assume that your server IP address is 192.168.1.123www.linghan56.cn and TOMCAT port is 8080. Enter http: // 192.168.1.123: 8080/converter/in the browser to see if the conversion program is running normally, if it starts normally, our work will be completed by more than half. The main work has been completed, and now the rest is how to apply it. I use PHP to call the Conversion Program. The user uploads files through PHP,
Determine the file type. If it is a JPG, GIF, PNG, or PDF file that can be directly converted using SWFTOOLS, convert it directly. Otherwise, Use http: // 192.168.1.123: 8080/converter/convert the file to PDF, and use SWFTOOLS to convert the PDF to SWF. It is worth noting that when converting the PDF to SWF, note that the version is converted to 9, if it is converted to a version earlier than 9, The AS3 operation will be very troublesome. The SWFTOOLS conversion command is as follows:
Copy codeThe Code is as follows: #/usr/local/swftools/bin/export 2swf-T 9 XXX.pdf XXX.swf
Here,-T is the version information, which can be queried through #/usr/local/swftools/bin/4102swf-help.
Now the entire process is 3/4 complete, and the rest is to use AS3 to write something and operate the SWF generated by PDF. The generated SWF file format is as follows, the document on each page generates a movieclip, and the specific Code cannot be pasted out. This is not difficult to believe.
I originally wanted to put an online DEMO, but my VPS configuration is too low. I can't add swap for MB of memory, and I can't run it if I ran PHP + MYSQL, the memory and CPU required by this application are still quite high.
Two methods are compared. The first type of conversion should be better, and more formats are supported. Theoretically, everything that can be printed can be converted, but cannot be concurrently, so it doesn't make much sense. If you can use this principle to write a conversion server and solve the concurrency problem, the first one should be the most appropriate.
The second type can only be converted to formats supported by openoffice, which has high requirements on servers. I don't know how the DOCIN and BAIDU documents work.