PHP to implement Word document online Browsing function, configuration installation Notes

Source: Internet
Author: User

In general, such as OA or CRM management system may encounter the need to re-line to view Word document functions, similar to Baidu Library.

Remember last year, a member of the team responsible for the project needs this function, which is said to be more difficult to implement, will be replaced with the CHM format. Today, see the online article "Linux php file Conversion", how to use the Linux under the OpenOffice 3, pdf2swf tool, Jodconverter, Flexpaper, realize the document online viewing.

Try to install yourself again under Ubuntu, with the following steps:

Because the Ubuntu version for 10.0.4,openoffice has been installed by default. If you don't have OpenOffice installed, Google install it yourself.
First step: Install the Jodconverter, after the installation can implement the doc document into PDF.

File is Http://www.artofsolving.com/opensource/jodconverter
After downloading the direct decompression, extracted to the/OPT directory/opt/jodconverter-2.2.2/, the use of the file is installed in the package Lib/jodconverter-cli-2.2.2.jar.
Test whether you can use

Java-jar/opt/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar/home/php/1.doc/home/php/1.pdf

  

The Java package is missing and prompts several installation packages. Select I install openjdk-6-jre-headless, the command is as follows:

sudo apt_get openjdk-6-jre-headless

  

After installation, the name of the above doc to PDF will be run, prompting the OpenOffice process not to start,

Because the Jodconverter is converted by OpenOffice, it is necessary to install the OpenOffice before use, and to start the OpenOffice service before it can be used. Start command

/usr/lib/soffice-headless-accept= "SOCKET,HOST=127.0.0.1,PORT=8100;URP;"-nofirststartwizard &

  

The command to run the above doc to PDF has been successful.

Second step: Install Swftools, after installation can realize PDF file to SwF

wget Http://www.swftools.org/swftools-0.9.1.tar.gztar xzf swftools-0.9.1.tar.gzcd swftools-0.9.1./ Configuremakemake Install

  

Test whether you can use

Pdf2swf-o/home/php/1.swf-t-z-t-f/home/php/1.pdf-s flashversion=9

  

The third step: using Flexpaper to achieve online preview, there is a detailed demo.

Fourth step: Use the PHP test document Conversion command:
Document to PDF

<?php$doc = './docs/test.txt '; $formatName = './pdf/test.pdf '; $command = ' java-jar/opt/jodconverter-2.2.2/lib/ Jodconverter-cli-2.2.2.jar '. $doc. $formatName; EXEC ($command); Echo ' OK ';

  

PDF to SWF

<?php$pdf = './pdf/test.pdf '; $swf = './swf/test.swf '; $command = '/usr/local/wenku/swftools-0.9.1/src/pdf2swf-o '. $swf. '-t-z-t-f '. $pdf. '-S flashversion=9 '; EXEC ($command); Echo ' OK ';

  

PHP script to run the above command may have permissions problem cannot be executed
One of the PHP scripts I used to test called pdf2swf to convert the file, not generated. This allows you to configure Apache user rights to ensure that the configured user has permission to run the pdf2swf command
The default installation of the PHP environment under Ubuntu Config file is/etc/apache2/apache2.conf modify these two lines,
User ${apache_run_user}
Group ${apache_run_user}

After the configuration is complete, restart Apache.
/etc/init.d/apache2 restart

The installation configuration under this Linux is over.

Window under test

Download the pdf2swf tool and Flexpaper, which are used under window, and manually turn the PDF file into SWF for online viewing.

The steps are organized as follows:

1. After installing the PDF2SWF tool, proceed to convert the PDF to SWF. CMD command line:
Pdf2swf.exe-t D:\wamp5.3\www\test\pdf\c.pdf-s Flashversion=9-o D:\wamp5.3\www\test\swf\c.swf
-T: Source file path, which is the path of the PDF file to be converted.
-S: Set the parameters, here we set to flashversion=9, that can be converted to 9 version.
-O: The path to the output file, where I output to D: Disk

Results of the operation:

2. Use the Flexpaper plugin to display the browse SWF file. The version used here is 1.5.8 Flash version (Release Notes). In the package there is already an HTML version of the demo, slightly change the next sentence can be achieved.

The code is as follows:

<script src= "Js/flexpaper_flash.js" type= "Text/javascript" ></script><a id= "ViewerPlaceHolder" style = "Width:680px;height:480px;display:block;" /></a><script type= "Text/javascript" > var fp = new Flexpaperviewer (' Flexpaperv             Iewer ', ' viewerplaceholder ', {config: {swffile:escape (' c.swf '), scale:0.1, Zoomtransition: ' EaseOut ', zoomtime:0.5, zoominterval:0.2, Fitpageonload : True, Fitwidthonload:false, Fullscreenasmaxwindow:false, PROGRESSIVELOADING:FA LSE, minzoomsize:0.2, Maxzoomsize:5, Searchmatchall:false, INITVIEWM Ode: ' Portrait ', Printpaperasbitmap:false, Viewmodetoolsvisible:true, ZOOMTOOLSV Isible:true, Navtoolsvisible:true, Cursortoolsvisible:true, SearchtoolSvisible:true, Localechain: ' en_US '}}) </script> 

  

This is the end, to see the effect achieved:

PHP to implement Word document online Browsing function, configuration installation Notes

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.