The example in this article describes how PHP can imitate Baidu Library and Docin Online Documentation. Share it with everyone for your reference, the details are as follows:
Since the project needs to implement functions similar to Baidu Library, and it is a project I am doing alone, I thought of finding a free ready-made one to use. Everything found online is the same. As follows:
Flash Paper supports the direct conversion of Office documents (.doc, .xls, .ppt) to PDF or SWF, which is very fast and has good effect. Unfortunately, Flash Paper has not been updated since V2.2. After installing Flash Paper, you can directly use the command to call FlashPrinter.exe to achieve batch conversion.
For example: C:FlashPaper2.2FlashPrinter.exe C:Flex Technology Introduction.ppt -o C:Flex Technology Introduction.swf
Download FlashPaper. After installation, a virtual printer will appear under the printer in the control panel. This means that the installation is successful. I have tried both 32-bit and 64-bit versions under win7 and cannot install it.
Try the above command on the command line and adjust the path according to yourself. After execution, success means it can be used.
The next step is to use php. PHP uses exec, or system, etc. to execute cmd commands, such as:
Before executing this, you need to configure the following php.ini. Set the safe mode to off (safe_mode = Off), or leave it on. Set the path that allows exe in safe_mode_exec_dir = and set it to the path of flashpaer.
Test it and it works successfully!
These can all be found online. Since I am using office 2007, the word suffix .docx failed during the conversion. I can’t find the reason online. Inadvertently, I converted the a The .docx was renamed a.doc and the conversion was successful. I can't figure it out, because it is possible to convert .docx directly under cmd. In the same way, if you want to convert the 2007 ppt or excel, you can convert it by removing the x from the suffix.
Supplement:
Recently, there was a project that required document conversion and reading functions similar to DOCIN, so I started looking for relevant information and finally concluded two solutions. Let’s discuss the respective implementations of the two methods below.
The first method: Convert DOC documents to directly generate SWF through FLASH PAPER. This is very simple. Download a FLASH PAPER and install it to call it. We use CMD to call it in the program. The calling command is: C:Program FilesMacromediaFlashPaper 2FlashPrinter.exe xxx.ppt -o xxx.swf. However, after my testing, this thing has a big flaw and cannot be used concurrently. In other words, it can only convert one document at the same time. I don’t know if there is any other method. To solve this problem, if you have a solution, please tell me. The conversion principle of FLASH PAPER is as follows: create a virtual printer, open the document, virtually print, obtain the printed content and directly generate SWF, so converting a document requires When a virtual printer is running, a window for printing and opening documents will pop up. This plan does not meet my requirements, so I will pass directly.
The second type: Use the open source software OPENOFFICE to convert the document into PDF, and then use SWFTOOLS to convert the PDF into SWF. There are many things that need to be used. Let’s go through them one by one. This solution can be run under Microsoft system or LINUX. I ran it under CENTOS5.5 character interface. The following is the process:
First install the CENTOS5.5 system. The installation process is no longer tedious. I installed it in the simplest way
After installing the system, download all the 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, all our applications are based on it: jodconverter
The download address is: http://sourceforge.net/projects/jodconverter/files/
Okay, the software package is ready, let’s start work⌒_⌒
Install JDK & tomcat first. The installation process is not verbose. If you don’t know how, just google it
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
This is how OPENOFFICE is installed. If your system does not have Chinese fonts, install Chinese fonts, otherwise the converted PDF will be garbled
After installing openoffice, install swftools. The installation of swftools is also relatively simple,
# tar zxvf swftools-0.9.1.tar.gz #cd swftools-0.9.1 # ./configure –prefix=/usr/local/swftools/ # make && make install
At this point, all the software that needs to be installed has been installed, since I am now using
Now let’s start all the required services,
First start OPENOFFICE. We start it as a service. The startup command is as follows
Then start TOMCAT and use jodconverter as a WEB APP conversion service, so first unzip the jodconverter-webapp-2.2.2.zip that was recovered from the disaster, and put jodconverter-webapp-2.2.2.war into the TOMCAT root Directory, after running TOMCAT, the APP folder will be automatically generated. To simplify writing, we rename it to converter. Assume that your server IP is: 192.168.1.123www.linghan56.cn, the TOMCAT port is 8080, and the browser input is: http:/ /192.168.1.123:8080/converter/ and see if the conversion program is running normally. If it starts normally, more than half of our work is completed. The main work has been done, and now the only thing left is how to apply it. I used PHP to call the conversion program, and the user uploaded the file through PHP,
Determine the file type. If it is a JPG, GIF, PNG, PDF, etc. file that can be directly converted using SWFTOOLS, convert it directly. Otherwise, convert the file to PDF through http://192.168.1.123:8080/converter/. Then use SWFTOOLS to convert PDF to SWF. It is worth noting that when converting PDF to SWF, pay attention to converting the version to 9. If you convert to a version below 9, AS3 operation will be very troublesome. The SWFTOOLS conversion command is as follows:
Where -T is the version information, which can be queried through #/usr/local/swftools/bin/pdf2swf -help
Now 3/4 of the whole process is completed. The only thing left is to use AS3 to write something and operate the SWF generated by PDF. The format of the generated SWF file is as follows. Each page of the document will generate a movieclip. Specifically I won’t post the code, I believe this is not difficult.
I originally wanted to put an online DEMO, but the configuration of my VPS is too low, with 512M of memory, and I can’t add swap myself. I ran PHP MYSQL and couldn’t run this. The memory and CPU required by this application are still Quite high.
Comparing the two methods, the first converted thing should be better and support more formats. Theoretically, anything that can be printed can be converted, but it cannot be concurrent, so it is of little significance. If If you can use this principle to write a conversion server yourself to solve concurrency problems, then the first method should be the most suitable.
The second method can only convert formats supported by openoffice, which has very high requirements on the server. I don’t know what the solution is for DOCIN and BAIDU documents
Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of PHP operating office document skills (including word, excel, access, ppt)", "php date Time usage summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation Introductory tutorial " and " Summary of common PHP database operation skills "
I hope this article will be helpful to everyone in PHP programming.