Java implementation Online Preview Doc,txt,ppt,xls and other documents, the use of Libreoffice,openoffice,swftools,jodconverter,flexpaper

Source: Internet
Author: User

Please see the attached picture.

LibreOffice the converted code:

Public String Dodoctofdplibre () {

File Inputfile = new file ("D:/1.txt");
File Inputfile = new file ("D:/ppt.ppt");
File Inputfile = new file ("D:/pptx.pptx");
File Inputfile = new file ("D:/doc.doc");
File Inputfile = new file ("D:/docx.docx");
File Inputfile = new file ("D:/xls.xls");
File Inputfile = new file ("D:/jpg.jpg");
File Inputfile = new file ("D:/gif.gif");
System.out.println ("LibreOffice start the conversion .... ...)" ................
Long starttime = new Date (). GetTime ();
//
TXT: use LibreOffice to convert PDF, conversion successful, but Chinese have garbled!!!!!
Doc: This is a DOC document in office that can be converted successfully, and Chinese is not garbled
Docx: This is the docx document in office, it can be converted successfully, and Chinese is not garbled
PPT and pptx: conversion succeeded.
XLS: Conversion successful, no Chinese garbled
XLSX: Conversion Successful
JPG and PNG: Success
String Libreofficepath = "D:/program Files (x86)/libreoffice 4";
This class exists in version 3 of Jodconverter and does not exist in version 2.2.2
Defaultofficemanagerconfiguration configuration = Newdefaultofficemanagerconfiguration ();
installation directory for LibreOffice
Configuration.setofficehome (New File (Libreofficepath));
Port number
Configuration.setportnumber (8100);
Configuration.settaskexecutiontimeout (1000 * 5L);//
Set task execution timeout to 5 minutes
Configuration.settaskqueuetimeout (1000 * 24L);/
Set task queue timeout to 24 hours
Officemanager Officemanager = Configuration.buildofficemanager ();
Officemanager.start ();
System.out.println ("... start ...");
Officedocumentconverter converter = new Officedocumentconverter (Officemanager);
File outputfile = new file ("D:/jpglibre.pdf");
Converter.convert (Inputfile, outputfile);
Converter.convert (Inputfile, STW, outputfile, pdf);
Transition End
System.out.println ("End of conversion .....") ");
String Pdfpath = Outputfile.getpath ();
Long endtime = new Date (). GetTime ();
Long time = Endtime-starttime;
System.out.println ("LibreOffice Conversion time is:" +time);
return pdfpath;
}

OpenOffice The converted code:

Public String Dodoctofdpopen () {
File Inputfile = new file ("D://unicode.txt");
File Inputfile = new file ("D:/pptx.pptx");
File Inputfile = new file ("D:/ppt.ppt");
File Inputfile = new file ("D:/docx.docx");
File Inputfile = new file ("D:/doc.doc");
File Inputfile = new file ("D:/xlsx.xlsx");
File Inputfile = new file ("D:/jpg.jpg");
File Inputfile = new file ("D:/gif.gif");
System.out
. println ("OpenOffice start the conversion ... .... ...)................. ...
TXT: use OpenOffice to convert PDF, conversion successful, but there are garbled!!!!!
The reason is that the coding format is not uniform, if the source file is Utf-8 file, there will be no garbled
DOC,DOCX,XLS,XLSX: Conversion successful, no garbled
//!!!!! Jpg,png,gif cannot be converted
Ppt.pptx can be converted

Long starttime = new Date (). GetTime ();
Openofficeconnection connection = new socketopenofficeconnection (8100);
try {
Connection.connect ();
catch (Connectexception e) {
E.printstacktrace ();
}
Documentconverter converter = new Openofficedocumentconverter (
connection);
File outputfile = new file ("D:/gifopen.pdf");
Converter.convert (Inputfile, outputfile);
Connection.disconnect ();
String Pdfpath = Outputfile.getpath ();
Long endtime = new Date (). GetTime ();
Long time = Endtime-starttime;
System.out.println ("OpenOffice Time used for:" +time);
return pdfpath;
}

PDF format to SWF-formatted code:

public void dopdftoswf (String pdfpath) {
Runtime r = Runtime.getruntime ();
System.out.println ("Pdfpath:" +pdfpath);
String Swfpath = pdfpath.substring (0,pdfpath.lastindexof ('. '));
System.out.println ("D:/program Files (x86)/swftools/pdf2swf.exe-t" +pdfpath+ "-S Flashversion=9-o" +swfpath+ ". swf");
try {
Process p = r.exec ("D:/program Files (x86)/swftools/pdf2swf.exe-t" +pdfpath+ "-S Flashversion=9-o" +swfpath+ ". swf");

catch (IOException e) {
E.printstacktrace ();
}
}

New Web Project

Copy the JS file in the Flexpaper to the project as shown in the figure, and then create the HTML file with the following code:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.0transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>FlexPaper</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/flexpaper_flash.js" ></script>
<body>
<div style= "position:absolute;left:10px;top:10px;" >
<a id= "Viewerplaceholder" style= "Width:680px;height:480px;display:block" ></a>

<script type= "Text/javascript" >
document.write (Escape ("d://ppt.swf"))
var fp = new Flexpaperviewer (
' Flexpaperviewer ',
' Viewerplaceholder ', {config: {
Note the wording of the address
Swffile:escape (' d://doclibre.swf '),
scale:0.8,//Zoom ratio
Zoomtransition: ' Easeout ',//Zoom style
zoomtime:0.5,//the time required to transform the scaling ratio
zoominterval:0.2,//the spacing between scale
Adaptive page when initializing fitpageonload:true,//
fitwidthonload:true,//Content Adaptive Page width
fullscreenasmaxwindow:false,//can maximize
When the progressiveloading:false,//value is true, it is gradually loaded
minzoomsize:0.2,//Minimum zoom ratio
maxzoomsize:5,//Max Zoom ratio
When searchmatchall:false,//search, the target is high and the test is not effective.
Initviewmode: ' Portrait ',//Start mode
Printpaperasbitmap:false,

Whether to display a style selection box on the viewmodetoolsvisible:true,//toolbar (that is, a tool that displays thumbnails or pagination)
Whether the zoom tool is displayed on the zoomtoolsvisible:true,//toolbar, including full screen
Whether the navigation tool (that is, the page number tool) is displayed on the navtoolsvisible:true,//toolbar
Whether the cursor tool is displayed on the cursortoolsvisible:true,//toolbar
Whether the search is displayed on the searchtoolsvisible:true,//toolbar

Localechain: ' en_US '/language
Localechain: ' ZH_CN '
}});
</script>
</div>
</body>

Attention:

Fill in the address of the generated SWF file

Running HTML files

If the loading status appears as shown in the illustration, click this link: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html#119065,

Select the third item on the left, and then add the address of the newly created HTML file to the lower-right position and choose always Allow.

Then run the HTML file again, and the SWF file will be displayed correctly online.


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.