


PHP realizes the effect of imitating Baidu Library and Docin online documents (word, excel, ppt to flash)_php skills
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
1 2 3 4 |
|
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,
1 2 3 |
|
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,
1 2 3 4 |
|
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
