PHP implementation of imitation Baidu Library, bean-Ding online document effects (word,excel,ppt to flash) _php tips

Source: Internet
Author: User
Tags php database

This article describes the PHP implementation of imitation Baidu Library, bean-ding online document effect. Share to everyone for your reference, specific as follows:

As the project to achieve similar functions of Baidu Library, I am a person to do the project, so think of finding free ready-made to use. Found on the Internet are the same. As follows:

Flash paper supports Office documents (. doc,.xls,.ppt) directly converted to PDF or SWF, which is fast and works better. Unfortunately, Flash Paper V2.2 has not been updated after. After installing the Flash paper, you can call FlashPrinter.exe directly using the command to implement batch conversion.

For example: C:\FlashPaper2.2\FlashPrinter.exe C:\Flex Technology profile. Introduction to Ppt-o C:\Flex technology. swf

Download a flashpaper, installed, control Panel of the printer there will be a virtual printer, this means that the installation was successful, Win7 I tried 32-bit and 64-bit can not install.

At the command line, try the above command, and the path adjusts to its own. After execution, success means that it can be used.

The next step is PHP, which uses exec, or system, to execute the cmd command, such as:

Copy Code code as follows:
EXEC ("C:\FlashPaper2.2\FlashPrinter.exe C:\Flex technology Introduction. Ppt-o C:\Flex); SWF");

Before performing this, configure the following php.ini to set the safe mode to OFF (Safe_mode = off), or on or off, in Safe_mode_exec_dir = Set the path to allow EXE, set to Flashpaer path.

Test and execute successfully!

These can be found on the Internet, because I use the office2007 so word suffix. docx, the conversion of the time to fail, has been on the internet can not find the reason, inadvertently, I would like to convert the A.docx renamed to A.doc conversion succeeded, so I also do not understand, Because directly under CMD, conversion. docx is OK. The same thing to turn 2007 Ppt,excel is to remove the suffix that x can be converted.

Add:

Recently, there is a project to use similar docin document conversion and reading functions, so began to find relevant information, and finally summed up 2 solutions, the following to explore the next two methods of implementation.

The first: through the flash PAPER to convert doc documents directly generated SWF, this is very simple, download a flash PAPER installation can be invoked, we are in the program is called with CMD, call the command is: C:\Program Files\macromedia\ Flashpaper 2\flashprinter.exe Xxx.ppt-o xxx.swf, but after my test, this thing has a lot of flaws, can not be combined with several, that is, only one document can be converted at the same time, I do not know whether there are other ways to solve this problem, If you have the solution, also please tell me, FLASH paper conversion principle is this: establishes a virtual printer, opens the document, the virtual printing, obtains the printing content directly to generate the SWF, therefore transforms a document to need a virtual printer's running ~ ~ ~ The middle will eject the printing and opens the document the window. This program does not meet my requirements, direct pass.

Second: Using open source software OpenOffice to convert documents to PDF, in the Swftools pdf into SWF, where there are more things to use, the following one by one. This program can be run under Microsoft's system, also can run under Linux, I am running under the CENTOS5.5 character interface, the following is the process:

First install CENTOS5.5 system, installation process is no longer verbose, I was the most simple installation of

When you install the system, you download all the packages you need: The packages we use have

# 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 a OpenOffice plugin, all of our applications are based on it: Jodconverter

Download address is: http://sourceforge.net/projects/jodconverter/files/

All right, the package is ready, so here we go. ⌒_⌒

Install JDK & Tomcat First, the installation process will not be verbose, will not Google under

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 

So OpenOffice installed, if your system does not have Chinese fonts, the Chinese font installation, otherwise turned out of the PDF will be garbled

After installing the OpenOffice, then install the Swftools,swftools installation 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 

By this time, all of the installed software has been installed, since I am now using

Now start to start the services you need,

Start the OpenOffice first, we started it as a service, and the start command is as follows

Copy Code code as follows:
#/opt/openoffice.org3/program/soffice-headless-accept= "SOCKET,HOST=127.0.0.1,PORT=8100;URP;"- Nofirststartwizard &

Then the Tomcat started, the Jodconverter as a web App conversion service, so first the next disaster down the Jodconverter-webapp-2.2.2.zip decompression, the jodconverter-webapp-2.2.2. War into the Tomcat root directory, after running Tomcat, will automatically generate the app folder, in order to write simple, we renamed to Converter, assuming your server IP: 192.168.1.123www.linghan56.cn,tomcat port is 8080, browser input: http://192.168.1.123:8080/converter/, see the conversion program is not normal, start normal, Our work is finished half. The main work has been done, now the rest is how to apply, I am using PHP to invoke the conversion of the program, users upload files through PHP,

To determine the type of file, if it is jpg,gif,png,pdf and other use Swftools can be directly converted to the file, directly converted, otherwise, through the http://192.168.1.123:8080/converter/to convert the file to PDF, And then use Swftools to convert PDF swf, it is noteworthy that the PDF to SWF, note that the version of the conversion to 9, if the version below 9, AS3 operation will be very troublesome, swftools conversion commands are as follows:

Copy Code code as follows:
#/usr/local/swftools/bin/pdf2swf-t 9 Xxx.pdf xxx.swf

Where-T is version information, which can be queried by #/usr/local/swftools/bin/pdf2swf-help

Now the whole process is finished 3/4, and the rest is to write a thing with AS3, the operation of the PDF generated SWF, the generated SWF file format is this, each page of the document will generate a MovieClip, the specific code I will not paste out, this is not difficult to believe.

Originally wanted to put an online demo, but I this VPS configuration is too low, 512M of memory, can not add their own swap, ran Php+mysql, ran this, the application requirements of the memory and CPU is quite high.

Comparing the two methods, the first one converts something that should be better, and support the format more, theoretically speaking, as long as the things can be printed, can be converted, just can not concurrency, so the significance is not, if you can use this principle, write a transformation server yourself, solve the concurrency problem, that the first should be the most appropriate.

The second type can only be converted to OpenOffice supported formats, the server requirements are very high. I don't know how the Docin and Baidu documents are going to work.

For more information on PHP-related content readers can view the site topics: "PHP operation Office Document tips summary (including word,excel,access,ppt)", "PHP date and Time usage summary", "PHP object-oriented Program Design Introductory Course", "PHP string (string) Summary of usage, Getting Started tutorial on Php+mysql database operations, and summary of common PHP database operations techniques

I hope this article will help you with the PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.