Java simulation Implementation of Baidu document online browsing
This idea is my reference to the Internet, code is my implementation.
Use the OpenOffice below Apache to convert the resource file into a PDF file, then convert the PDF file into a SWF file and browse with Flexpaper.
Ok
A, download OpenOffice (convert resource file)
B. Download Jodconverter (call OpenOffice)
C, download swftools (pdf2swf)
D. Download flexpaper (browse swf file)
Here I have all downloaded, all you need to download: http://down.51cto.com/data/1980603
After the download, do not hurry to install, please read this blog post
1, first look at our MYECLIPSE engineering structure
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/59/4F/wKiom1TPOomBqJi9AAI16KIMH8Y013.jpg "title=" Java simulation Baidu Library online. jpg "alt=" wkiom1tpoombqji9aai16kimh8y013.jpg "/>
2.
650 we downloaded) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M01/59/4F/wKiom1TPOwCAE5YQAAAZW7nJ3Nk933.jpg " Title= "1.jpg" alt= "wkiom1tpowcae5yqaaazw7nj3nk933.jpg"/> after extracting all the jar files to the Baidudoc go under Lib.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/4C/wKioL1TPPA2was0bAAEC_rTHC-k842.jpg "title=" 2.jpg " alt= "Wkiol1tppa2was0baaec_rthc-k842.jpg"/>
3. Create a new 650 under WebRoot) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M01/59/4C/ Wkiol1tppfkqcg8vaaao_bfzbdc134.jpg "title=" 3.jpg "alt=" wkiol1tppfkqcg8vaaao_bfzbdc134.jpg "/> folder, will be decompressed after 650) this.width=650, "src=" http://s3.51cto.com/wyfs02/M02/59/4F/wKiom1TPO5Piigy_AAAg5uWVZqM672.jpg "title=" 4.jpg "alt= "Wkiom1tpo5piigy_aaag5uwvzqm672.jpg"/> All copies to Flexpaper .
4. New Baiduservlet.java file
package com.baidu.util;import java.io.bufferedinputstream;import java.io.file;import java.io.fileinputstream;import java.io.ioexception;import java.io.inputstream;import java.net.connectexception;import javax.imageio.stream.fileimageinputstream;import javax.servlet.servletexception;import javax.servlet.http.httpservlet;import javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;import com.artofsolving.jodconverter.documentconverter;import com.artofsolving.jodconverter.openoffice.connection.openofficeconnection;import com.artofsolving.jodconverter.openoffice.connection.socketopenofficeconnection;import com.artofsolving.jodconverter.openoffice.converter.openofficedocumentconverter;/** * @Author: NuoYan * @Date:2015-2-2 pm 2:24:58 * todo: 1, first get to the file you need to see * 2, part II, documents to be acquired (doc,xls,txt,ppt,03/07 version to PDF), this step calls Openoffice * 3, the third, convert the resource file to a SWF file to convert a good PDF file, Use flexpaperviewer.swf to browse and view */public class baiduservlet extends httpservlet { private file sourcefile;// the source file to be converted Private file pdffile;// pdf Intermediate file object private The file swffile;// swf target file object private string filepath;// is used to save the file path private string filename;// does not include the name of the suffix public file getsourcefile () {return sourcefile;} Public void setsourcefile (File sourcefile) {this.sourcefile = sourcefile;} Public file getpdffile () {return pdffile;} Public void setpdffile (File pdffile) {this.pdffile = pdffile;} Public file getswffile () {return swffile;} Public void setswffile (File swffile) {this.swffile = swffile;} Public string getfilepath () {return filEpath;} Public void setfilepath (String filepath) {this.filepath = filepath;} Public string getfilename () {return filename;} Public void setfilename (String filename) {this.filename = filename;} Public void doget (Httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {string savefilename = request.getparameter (" Savfile "); System.out.println (Savefilename); String webpath = request.getrealpath ("/");filepath = webpath + "reader\\" + savefilename;filename = filepath.substring (0, filepath.lastindexof (".")); / Create three file Objects Sourcefile = new file (filePath);pd Ffile = new file (filename + ". pdf"); Swffile = new file (filename + ". swf"); System.out.println (Pdffile); System.out.println (swffile);// 1, converting source files to PDF formatFile Src2pdf (); try {// 2, convert pdf file to swf file pdf2swf ();} catch (exception e) {e.printstacktrace ();} Bind converted files to session request.getsession (). SetAttribute ("Swfname", swffile.getname ()); System.out.println (Swffile.getname ());// Redirect to preview page Response.sendredirect (Request.getcontextpath () + "/reader/basefile.jsp");} /** * @Author:nuoyan * @Date:2015-2-2 pm 2:28:22 todo://source file to PDF file */ Private void src2pdf () {if (Sourcefile.exists ()) {// if not present, need to be transferred to PDF file if (! Pdffile.exists ()) {// enable conversion services provided by OpenOffice openofficeconnection conn = new Socketopenofficeconnection (8100);// connection OpenOffice Server Try {conn.connect ();// Establish a File Converter object Documentconverter converter = new openofficedocumentconverter (conn); Converter.convert (sourcefile, pdffile);// broken link conn.disconnect (); System.out.println ("conversion succeeded");} catch (Connectexception e) {e.printstacktrace ();}} else {system.out.println ("already exists PDF file and does not need to be converted!! ");}} else {system.out.println ("File path does not exist!!! ");}} /** * @Author:nuoyan * @Date:2015-2-2 pm 2:28:32 * @throws exception * todo:pdf Convert to SWF file */private void pdf2swf () throws exception {if (!swffile.exists ()) {if (Pdffile.exists ()) {String command = "c:\\pdf2swf\ \pdf2swf.exe "+ pdffile.getpath () + " -o " + swffile.getpath () + " -t 9 "; System.out.println ("Convert command:" + command);// java invoke external command to convert PDF to swfruntime r = Runtime.getruntime (); Process p = r.exec (command); System.out.println (Loadstream (P.getinputstream ())); System.out.println ("SWF file is successfully transferred!!! "); System.out.println (Swffile.getpath ());} else {system.out.println ("No PDF file exists");}}} Private static string loadstream (inputstream IN) throws exception {int len = 0;in = new bufferedinputstream (in ); Stringbuffer buffer = new stringbuffer ();while ((Len = in.read ()) != -1) {buffer.append ((char) len);} Return buffer.tostring ();}}
5, modify the index.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><! Doctype html public "-//w3c//dtd html 4.01 transitional//en" >
6. Writing basefile.jsp files
<%@ page language= "java" contenttype= "Text/html; charset=utf-8" pageencoding= "UTF-8"%><! doctype html public "-//w3c//dtd html 4.01 transitional//en" "HTTP// Www.w3.org/TR/html4/loose.dtd ">Note The code in the basefile.jsp, not you can refer to here
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/4F/wKiom1TPPH6w-eXHAADBd6XYdeo117.jpg "title=" 5.jpg " alt= "Wkiom1tpph6w-exhaadbd6xydeo117.jpg"/>
/**************************************************************************************/
7, to be completed here, it is important to note that:
1, 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/59/4C/wKioL1TPPbDCQ7SOAAAj1OEioRA406.jpg "title=" 6. JPG "alt=" wkiol1tppbdcq7soaaaj1oeiora406.jpg "/> file installation path not too deep, lest Java Call external command, cannot execute, I here is C under the plate
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/4C/wKioL1TPPdeTPZf0AAAk56wHaeA554.jpg "title=" 7.jpg " alt= "Wkiol1tppdetpzf0aaak56whaea554.jpg"/>
2, 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/59/4C/wKioL1TPPfzR23txAACPHt6wVzY664.jpg "title=" 8. JPG "alt=" wkiol1tppfzr23txaacpht6wvzy664.jpg "/>
2.1, Red 1 mark the path can not be wrong, I made this mistake
2.2, Red Flag 2 can also write http://127.0.0.1:8080/baiduDoc/reader/...
3, start the OpenOffice command, not directly double-click to start.
After installing OpenOffice
1. Installation Services
CD C:\Program Files (x86) \openoffice4\program
This step you can see where your OpenOffice is installed
Perform
Soffice-headless-accept= "SOCKET,HOST=127.0.0.1,PORT=8100;URP;"-nofirststartwizard
2. See if the installation was successful
2.1 Viewing the PID of the port
Netstat-ano|findstr "8100"
2.2 View the PID corresponding service program name
Tasklist|findstr "IPD Value"
Shown
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/4C/wKioL1TPPoOQd_tjAAEMAKYmX0A849.jpg "title=" 9.jpg " alt= "Wkiol1tppooqd_tjaaemakymx0a849.jpg"/>
Source Address:
http://down.51cto.com/data/1980608
If you have any questions, come and find me!
This article from "Promise always attached to the small wood 、、、" blog, please be sure to keep this source http://1936625305.blog.51cto.com/6410597/1610836
Java simulation Implementation of Baidu document online browsing