Simulation of Baidu Library solution OpenOffice.org 3 + swftools + flexpaper

Source: Internet
Author: User

Recently, when developing a XX System for the customer, the customer requested to upload the documents (including *. doc ;*. docx ;*. XLS ;*. XLSX ;*. PPT ;*. pptx ;*. pdf;) can only be previewed, cannot be downloaded, cannot be printed.

I just wanted to go to Baidu Library and douding network. The Online previews of Baidu Library and douding network both use flash to play documents. I checked a lot of materials online and finally realized this function,

Now you can download your own design and implementation as follows.

 

How can I convert a file to a SWF file supported by flash for online playback?
1. Use OpenOffice*. Doc; *. docx; *. xls; *. XLSX; *. ppt; *. pptx; *. PDFConvert a document type to a PDF file
2. Use swftools to Convert PDF to SwF, and then use the flexpaper plug-in to implement online playback preview.


OpenOffice

OpenOffice.org is a cross-platform office software suite that can be executed on Windows, Linux, MacOS X (X11), Solaris, and other operating systems. It is compatible with major office software kits. OpenOffice.org is a free software that anyone can download, use, and promote for free.

Main modules include writer, impress, Calc, draw, math, and base)

The latest Chinese official version: Apache_OpenOffice_incubating_3.4.1_Win_x86_install_zh-CN.

 

Flexpaper

Flexpaper is an open-source lightweight component used to display various documents in a browser. It is designed to be used with ipv2swf to display PDF in flex, this process does not require the support of the PDF software environment. It can be used as a flex library. In addition, you can convert documents such as Word and PPT into PDF files for online browsing.
1. install necessary tool components
(1) install OpenOffice. OpenOffice is an open-source free text processing software that converts office documents into PDF files (installed in c: \ Program Files (x86) \ OpenOffice 4 \ Program ), openofficehttp: // www.openoffice.org/download/index.html
(2) After installing OpenOffice, you must start its server and start OpenOffice server using the command line. Enter the CMD command line prompt c: \ Program Files (x86) \ OpenOffice 4 \ Program \
Run the following command:
Soffice-Headless-accept = "socket, host = 127.0.0.1, Port = 8100; URP;"-nofirststartwizard

 

Every time you start this command, you can write a BAT file.

 
Log on to the Windows Task Manager and check that there is a process named soffice. bin. This indicates that OpenOffice is started successfully!


(3) install swftools (install to c: \ Program Files). swftools converts PDF files to SWF files for flexpaper playback. : Http://www.swftools.org/download.html
(4) download flexpaper: http://flexpaper.devaldi.com/download/
(5) download the OpenDocument converter jodconverter. jodconverter is a Java openducument file converter that can convert many file formats. It uses OpenOffice for conversion, it can perform the following conversions:
A. convert Microsoft Office to openducument and openducument to Microsoft Office
B. Convert openducument to PDF, convert Word, Excel, PowerPoint to PDF, and convert RTF to PDF.
: Http://sourceforge.net/projects/jodconverter/files/

 

 

Sample Code:

1. copy the file to the root directory of the website (this file is mainly used in the player that plays the SWF file on the webpage). The directory structure is as follows:

 

2. Create an onlineread. jsp file

<HTML xmlns = "http://www.w3.org/1999/xhtml" lang = "en" XML: lang = "en">
<Head>
<Title> </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Style type = "text/CSS" Media = "screen">
HTML, body {Height: 100% ;}
Body {margin: 0; padding: 0; overflow: auto ;}
# Flashcontent {display: none ;}
</Style>

<SCRIPT type = "text/JavaScript" src = "JS/swfobject. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "JS/flexpaper_flash.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
<! -- For Version Detection, set to Min. Required Flash Player version, or 0 (or 0.0.0), for no Version Detection. -->
VaR swfversionstr = "10.0.0 ";
<! -- To use express install, set to playerproductinstall.swf, otherwise the empty string. -->
VaR xiswfurlstr = "playerproductinstall.swf ";

VaR flashvars = {
Swffile: escape ("paper.swf "),
Scale: 0.6,
Zoomtransition: "easeout ",
Zoomtime: 0.5,
Zoominterval: 0.1,
Fitpageonload: false,
Fitwidthonload: True,
Printenabled: True,
Fullscreenasmaxwindow: false,
Progressiveloading: True,

Printtoolsvisible: True,
Viewmodetoolsvisible: True,
Zoomtoolsvisible: True,
Fullscreenvisible: True,
Navtoolsvisible: True,
Cursortoolsvisible: True,
Searchtoolsvisible: True,

Localechain: "en_us"
};

VaR Params = {

}
Params. Quality = "high ";
Params. bgcolor = "# ffffff ";
Params. allowScriptAccess = "samedomain ";
Params. allowfullscreen = "true ";
VaR attributes = {};
Attributes. ID = "flexpaperviewer ";
Attributes. Name = "flexpaperviewer ";
Swfobject. embedswf (
"Flexpaperviewer.swf", "flashcontent ",
"650", "500 ",
Swfversionstr, xiswfurlstr,
Flashvars, Params, attributes );
Swfobject. createcss ("# flashcontent", "display: block; text-align: Left ;");
</SCRIPT>

</Head>
<Body>
<Div id = "flashcontent">
<P>
</P>
</Div>
</Body>
</Html>

 

3 create document conversion class office2swfutil. Java

Package com. Iori. webapp. util;

Import java. Io. file;
Import java. Io. ioexception;
Import java. Io. serializable;

/**
*
* @ Author DTF
*/
Public class office2swfutil implements serializable {
 
Private string export 2swftool = "D:/program files/swftools/export 2swf.exe ";
 
Private Static final long serialversionuid = 8410551332651163557l;
 
 
 
Private string filetype = ".doc;.xls0000.ppt0000.docx0000.xlsx0000.pptx ";
/**
* Office file(.doc;.xls0000.ppt0000.docx0000.xlsx0000.pptx)
**/
Private file officfile = NULL;
/**
* PDF File
**/
Private file pdffile = NULL;
/**
* Swffile
**/
Private file swffile = NULL;
 
Private file swfurl = NULL;
/***
* Test1.doc ---> test1 file name
**/
Private string abfilename = NULL;
 
/**
* Test1.doc ---> Doc
**/
Private string bcfilename = NULL;
 
/**
* Fileurl
**/
Private string fileurl = NULL;
 
Public office2swfutil (){

}
 
Public office2swfutil (string fileurl ){
Officfile = new file (fileurl );
}
 
Public void tochange () throws ioexception {
Setfileurl (officfile. getparent (); // file path
String filename = officfile. getname (); // file name
Setabfilename (filename. substring (0, filename. lastindexof ("."); // the actual name of the file
Setbcfilename (filename. substring (filename. lastindexof ("."), filename. Length (); // file suffix
If (officfile. exists () {// checks whether the object exists.
If (iscontext (this. getbcfilename () {// determine whether the file is an office file
Pdffile = new file (getfileurl () + "/" + getabfilename () + ". pdf ");
Swfurl = new file (getfileurl () + "/" + getabfilename ());
If (! Swfurl. exists ()){
Swfurl. mkdirs ();
}

Doc2pdfutil dp = new doc2pdfutil (officfile, pdffile );
DP. Run ();
%2swfutil%2swf (getfileurl () + "/" + getabfilename () + ". PDF ", getfileurl () +"/"+ getabfilename () +"/"+ getabfilename (), %2swftool );
New file (getfileurl () + "/" + getabfilename () + ". pdf"). Delete ();
} Else if (this. getbcfilename (). Equals (". pdf") {// determine whether it is a PDF file
%2swfutil%2swf (getfileurl () + "/" + getabfilename () + ". PDF ", getfileurl () +"/"+ getabfilename () +"/"+ getabfilename (), %2swftool );
}
}
}
 
Private Boolean iscontext (string bcfilename ){
Boolean flag = false;
If (bcfilename! = NULL &&! "". Endswith (bcfilename )){
String [] typelist = filetype. Split (";");
For (string type: typelist ){

If (type. Equals (bcfilename )){
Return true;
}
}
}
Return flag;
}

 
Public static void main (string [] ARGs ){
Try {
New office2swfutil ("D:/temp/1.docx"). tochange ();
New office2swfutil ("D:/temp/test1.xls"). tochange ();
} Catch (ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}

Public file getofficfile (){
Return officfile;
}

Public void setofficfile (File officfile ){
This. officfile = officfile;
}

Public file getpdffile (){
Return pdffile;
}

Public void setpdffile (File pdffile ){
This.pdf file = pdffile;
}

Public file getswffile (){
Return swffile;
}

Public void setswffile (File swffile ){
This.swf file = swffile;
}

Public String getabfilename (){
Return abfilename;
}

Public void setabfilename (string abfilename ){
This. abfilename = abfilename;
}

Public String getbcfilename (){
Return bcfilename;
}

Public void setbcfilename (string bcfilename ){
This. bcfilename = bcfilename;
}

Public String getfileurl (){
Return fileurl;
}

Public void setfileurl (string fileurl ){
This. fileurl = fileurl;
}

Public file getswfurl (){
Return swfurl;
}

Public void setswfurl (File swfurl ){
This.swf url = swfurl;
}
 
}

 

 

 

 

 

 

 

 

 

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.