PHP realizes the effect of imitating Baidu Wenku and Docin online documents (word, excel, ppt to flash), _PHP tutorial

WBOY
Release: 2016-07-12 08:57:35
Original
1093 people have browsed it

PHP realizes the effect of imitating Baidu Library and Docin online document (word, excel, ppt to flash),

This article describes the example of PHP realizing imitating Baidu Library and Docin online document Effect. 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:
Copy code The code is as follows: exec("C:FlashPaper2.2FlashPrinter.exe C:Flex Technology Introduction.ppt -o C:Flex Technology Introduction.swf");

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 on the Internet. 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, but after my testing, this thing has a big flaw and cannot be used concurrently, which means that 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 

Copy after login

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, just google it if you don’t know how to do 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 

Copy after login

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, then install swftools. The installation of swftools is relatively simple,

# tar zxvf swftools-0.9.1.tar.gz 
#cd swftools-0.9.1 
# ./configure –prefix=/usr/local/swftools/ 
# make && make install 

Copy after login

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
Copy code The code is as follows: #/opt/openoffice.org3/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" - nofirststartwizard &

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:
Copy the code The code is as follows: #/usr/local/swftools/bin/pdf2swf -T 9 XXX.pdf XXX.swf

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 for this application are still the same. 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 of this site: "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Summary of PHP date and time usage", "php-oriented "Introduction Tutorial on Object Programming", "Summary of PHP String Usage", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • php check whether the page is included in Baidu
  • php method to get the Baidu snapshot date of the website
  • php get included in Baidu , Baidu hot words and Baidu snapshot method
  • PHP method to calculate the distance between two GPS coordinates on Baidu map
  • php generate Baidu sitemap site map class function instance
  • ThinkPHP Call Baidu translation class to achieve online translation
  • php code example using Baidu ping service
  • How to create PowerPoint2007 document using PHP
  • Principles and examples of using PHP to export Word documents
  • Customized php class (search/modify) xml document
  • PHP generated Flash animation implementation code
  • flash php mysql to create a simple message book tutorial
  • Use PHP dynamic Create Flash animation

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1108614.htmlTechArticlePHP realizes the effect of imitating Baidu Library and Docin online documents (word, excel, ppt to flash), this article describes the examples Use PHP to achieve the effect of imitating Baidu Library and Docin online documents. Sharing it with everyone for your reference,...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template