java 预览word文档_Java版office文档在线预览
java将office文档pdf文档转换成swf文件在线预览
第一步,安装openoffice.org
openoffice.org是一套sun的开源office办公套件,能在widows,linux,solaris等操作系统上执行。
主要模块有writer(文本文档),impress(演示文稿),Calc(电子表格),Draw(绘图),Math(公式),base(数据库)
笔者下载的是openoffice.org 3.3.0。下载完直接安装即可。
但是,我们还需要启动openoffice server。有两种做法:
1.以命令行方式启动openoffice server,缺点是每次系统重启,都需要手动去把openoffice server启动。
2.将openoffice server作为操作系统的服务启动,既然成为了系统服务,就可以设定开机自动启动了。
我们先来看第一种方式,
1.以命令行方式启动openoffice server
在cmd命令下,cd opeonofiice的安装路径/program 如:cd c:\program files\openoffice.org 3\program\soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
2.以系统服务的方式启动
这里我们还需要Windows Resource Kit tools ,将openoffice server设为系统服务。
Windows Resource Kit tools 是微软专为管理人员、开发人员和高级用户开发的,包括管理活动目录、组策略、TCP/IP网络、注册表、系统安全、监测等涉及Windows Server 2003 操作系统的其它很多方面的非常规安装的工具组件。Resource Kit Tools for XP的发布使得XP用户也能使用Resource Kit Tools对这些问题进行处理。
下载windows resource kit tools,我们进行默认安装。
1.打开Windows Resource Kit Tools
在Command Shell执行以下命令:
"C:\Program Files\Windows Resource Kits\Tools\instsrv" OpenOfficeUnoServer "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"
打开 管理工具->服务 可以找到以 OpenOfficeUnoServer 命名的服务
2.打开注册表寻找以下路径
HKEY_LOCAL_MACHINE -> SYSTEM ->ControlSet001 ->Services ->OpenOfficeUnoServer
新建项 Parameters,在该项下添加两个字符串值:
key:Application
value:C:\Program Files\OpenOffice.org 3\program\soffice.exe
key:AppParameters
value:-invisible -headless -accept=socket,host=127.0.0.1,port=8100;urp; -nofirststartwizard
3.在服务控制台,启动 openoffice 服务
4.在CMD中用以下命令查看8100是否已被监听:netstat -anop tcp
这样OpenOffice3.0就以服务方式运行在Windows系统上了。(使用cmd命令:netstat -anp tcp查看8100端口是否工作)
然後可以通过socket方式连接openOffice,以使用openoffice提供的某些服务,如文件转换服务,ms office转pdf等等。
开源项目 JODConverter 就是结合openoffice来进行文档转换的java组件。
另外有一个命令行工具swftools,该工具可以将pdf转换为swf格式的文档,提供给ie客戶端流览。
另外,我们可以将该配置用bat文件来快速实现,运行前请先修改相应目录参数:
openoffice service.bat文件
"C:\Program Files\Windows Resource Kits\Tools\instsrv" OpenOfficeUnoServer "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"
reg add
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\OpenOfficeUnoServer\Parameters
/ve /d
reg add
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\OpenOfficeUnoServer\Parameters
/v Application /t REG_SZ /d "C:\Program Files\OpenOffice.org
3\program\soffice.exe"
reg add
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\OpenOfficeUnoServer\Parameters
/v AppParameters /t REG_SZ /d "-invisible -headless
-accept=socket,host=127.0.0.1,port=8100;urp; -nofirststartwizard"
第二步,使用JODConverter将office文档转换为pdf
JODConverter是一个java的OpenDucument文件转换器,可以进行许多文件格式的转换,它利用
OpenOffice来进行转换工作,它能进行以下的转换工作:
1.Microsoft Office格式转换为OpenDucument,以及OpenDucument转换为Microsoft Office
2.OpenDucument转换为PDF,Word、Excel、PowerPoint转换为PDF,RTF转换为PDF等。
它是一个开源项目。
我的项目是在MyEclipse下开发的。
下载最新版的jodconverter-2.2.2,把lib文件夹的包导入到你的DocConverter项目的lib文件夹内。
(假设你的项目是DocConverter)
新建DOC2PDFUtil.java
package com.iori.webapp.util;
import java.io.File;
import java.io.IOException;
import java.net.ConnectException;
import java.util.Date;
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;
public class DOC2PDFUtil extends
java.lang.Thread {
private File inputFile;// 需要转换的文件
private File outputFile;// 输出的文件
public DOC2PDFUtil(File inputFile, File outputFile) {
this.inputFile = inputFile;
this.outputFile = outputFile;
}
public void docToPdf() {
Date start = new Date();
OpenOfficeConnection connection = new
SocketOpenOfficeConnection(8100);
try {
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
} catch (ConnectException cex) {
cex.printStackTrace();
} finally {
// close the connection
if (connection != null) {
connection.disconnect();
connection = null;
}
}
}
/**
* 由于服务是线程不安全的,所以……需要启动线程
*/
public void run() {
this.docToPdf();
}
public File getInputFile() {
return inputFile;
}
public void setInputFile(File inputFile) {
this.inputFile = inputFile;
}
public File getOutputFile() {
return outputFile;
}
public void setOutputFile(File outputFile) {
this.outputFile = outputFile;
}
/**
* 测试main方法
* @param args
*/
public static void main(String[] args) {
File inputFile = new File("c://temp//333.xls");
File outputFile = new File("c://temp//333.pdf");
DOC2PDFUtil dp=new DOC2PDFUtil(inputFile,outputFile);
dp.start();
}
}
在DOC2PDFUtil.java,右键属性 - >Run as - >Java Application ,输出main的测试结果。
在jsp中执行
新建MyDOC2PDFTest.jsp
import="java.io.*"%>
import="com.artofsolving.jodconverter.openoffice.connection.*"%>
import="com.artofsolving.jodconverter.openoffice.connection.*"%>
import="com.artofsolving.jodconverter.openoffice.converter.*"%>
import="com.artofsolving.jodconverter.*"%>
import="java.util.*"%>
File inputFile = new
File("c://temp//333.xls");
File outputFile = new
File("c://temp//333.pdf");
DOC2PDFUtil dp=new
DOC2PDFUtil(inputFile,outputFile);
dp.start();
%>
Simple jsp
page
here
在项目DocConverter根目录,右键属性 - >Run as - >MyEclipse Server Application
发布到之前安装的Tomcat 6.0的根目录,然后用url路径访问:Http://localhost:8080/DocConverter/MyDOC2PDFTest.jsp 进行测试。
JODConverter将office文档转换pdf,用到的代码如下:
File inputFile = new
File("c://temp//333.xls");
File outputFile = new
File("c://temp//333.pdf");
// 链接 一个运行在8100端口的OpenOffice.org 实例
OpenOfficeConnection connection = new
SocketOpenOfficeConnection(8100);
connection.connect();
// 创建一个converter对象并转换格式
DocumentConverter converter = new
OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// 关闭连接
connection.disconnect();
第三步,使用swftools将pdf转换为swf
建议下载swftools-0.9.1,笔者起先下载的是最新版的swftools-1.0版。貌似转换时出错,缺少什么组件。
继续笔者的DocConverter项目。笔者使用的开发环境是MyEclipse
9.0。
新建PDF2SWFUtil.java
package com.iori.webapp.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class PDF2SWFUtil {
/**
* 利用SWFTools工具将pdf转换成swf,转换完后的swf文件与pdf同名
* @author iori
* @param fileDir PDF文件存放路径(包括文件名)
* @param exePath 转换器安装路径
* @throws IOException
*/
public static synchronized void pdf2swf(String fileDir, String exePath)
throws IOException {
//文件路径
String filePath = fileDir.substring(0,
fileDir.lastIndexOf("/"));
//文件名,不带后缀
String fileName = fileDir.substring((filePath.length() + 1), fileDir.lastIndexOf("."));
Process pro = null;
if (isWindowsSystem()) {
//如果是windows系统
//命令行命令
String cmd = exePath + "
\"" + fileDir + "\" -o \"" + filePath +
"/" + fileName + ".swf\"";
//Runtime执行后返回创建的进程对象
pro =
Runtime.getRuntime().exec(cmd);
} else {
//如果是linux系统,路径不能有空格,而且一定不能用双引号,否则无法创建进程
String[] cmd = new String[3];
cmd[0] = exePath;
cmd[1] = fileDir;
cmd[2] = filePath + "/" + fileName + ".swf";
//Runtime执行后返回创建的进程对象
pro =
Runtime.getRuntime().exec(cmd);
}
//非要读取一遍cmd的输出,要不不会flush生成文件(多线程)
new DoOutput(pro.getInputStream()).start();
new DoOutput(pro.getErrorStream()).start();
try {
//调用waitFor方法,是为了阻塞当前进程,直到cmd执行完
pro.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
/**
* 判断是否是windows操作系统
* @author iori
* @return
*/
private static boolean isWindowsSystem() {
String p = System.getProperty("os.name");
return p.toLowerCase().indexOf("windows") >= 0 ? true :
false;
}
/**
* 多线程内部类
* 读取转换时cmd进程的标准输出流和错误输出流,这样做是因为如果不读取流,进程将死锁
* @author iori
*/
private static class DoOutput extends Thread {
public InputStream is;
//构造方法
public DoOutput(InputStream is) {
this.is = is;
}
public void run() {
BufferedReader br = new BufferedReader(new InputStreamReader(this.is));
String str = null;
try {
//这里并没有对流的内容进行处理,只是读了一遍
while ((str = br.readLine())
!= null);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
/**
* 测试main方法
* @param args
*/
public static void main(String[] args) {
//转换器安装路径
String exePath = "c:/Program Files/SWFTools/pdf2swf.exe";
try {
PDF2SWFUtil.pdf2swf("c:/temp/333.pdf", exePath);
} catch (IOException e) {
System.err.println("转换出错!");
e.printStackTrace();
}
}
}
在PDF2SWFUtil.java,右键属性 - >Run as - >Java Application ,输出main的测试结果。
在jsp中执行
新建MyPDF2SWFTest.jsp
import="java.io.*"%>
import="com.artofsolving.jodconverter.openoffice.connection.*"%>
import="com.artofsolving.jodconverter.openoffice.connection.*"%>
import="com.artofsolving.jodconverter.openoffice.converter.*"%>
import="com.artofsolving.jodconverter.*"%>
import="java.util.*"%>
import="com.iori.webapp.util.*"%>
//转换器安装路径
String exePath = "c:/Program
Files/SWFTools/pdf2swf.exe";
try {
PDF2SWFUtil.pdf2swf("c:/temp/333.pdf", exePath);
} catch (IOException e) {
System.err.println("转换出错!");
e.printStackTrace();
}
%>
Simple jsp page
here
在项目DocConverter根目录,右键属性 - >Run as - >MyEclipse Server Application
第四步,office文档转为pdf,同时进一步转为swf
网上资料有很多office文档转为pdf,pdf转为swf,但都是单步转换。关于一起转换的资料比较少。
一起转换有个问题就是转为pdf时,这个转换过程将花费一段时间才能成功,如何控制在pdf转换成功后,才进行swf的转换。
以及多个文档批量转换又该怎么办。
有幸笔者还是找到了一篇同时转换的代码:
新建DocConverter.java
package com.iori.webapp.util;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
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;
/*
*
doc docx格式转换
*
@author Administrator
*/
public class DocConverter {
private static final int environment=1;//环境1:windows 2:linux(涉及pdf2swf路径问题)
private String fileString;
private String outputPath="";//输入路径,如果不设置就输出在默认位置
private String fileName;
private File pdfFile;
private File swfFile;
private File docFile;
public DocConverter(String fileString)
{
ini(fileString);
}
/*
* 重新设置 file
* @param fileString
*/
public void setFile(String fileString)
{
ini(fileString);
}
/*
* 初始化
* @param fileString
*/
private void ini(String fileString)
{
this.fileString=fileString;
fileName=fileString.substring(0,fileString.lastIndexOf("."));
docFile=new File(fileString);
pdfFile=new File(fileName+".pdf");
swfFile=new File(fileName+".swf");
}
/*
* 转为PDF
* @param file
*/
private void doc2pdf() throws Exception
{
if(docFile.exists())
{
if(!pdfFile.exists())
{
OpenOfficeConnection
connection=new SocketOpenOfficeConnection(8100);
try
{
connection.connect();
DocumentConverter
converter=new OpenOfficeDocumentConverter(connection);
converter.convert(docFile,pdfFile);
//close the connection
connection.disconnect();
System.out.println("****pdf转换成功,PDF输出:"+pdfFile.getPath()+"****");
}
catch(java.net.ConnectException
e)
{
//ToDo Auto-generated catch
block
e.printStackTrace();
System.out.println("****swf转换异常,openoffice服务未启动!****");
throw e;
}
catch(com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException
e)
{
e.printStackTrace();
System.out.println("****swf转换器异常,读取转换文件失败****");
throw e;
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
else
{
System.out.println("****已经转换为pdf,不需要再进行转化****");
}
}
else
{
System.out.println("****swf转换器异常,需要转换的文档不存在,无法转换****");
}
}
/*
* 转换成swf
*/
private void pdf2swf() throws Exception
{
Runtime r=Runtime.getRuntime();
if(!swfFile.exists())
{
if(pdfFile.exists())
{
if(environment==1)//windows环境处理
{
try {
Process
p=r.exec("C:/Program Files/SWFTools/pdf2swf.exe
"+pdfFile.getPath()+" -o "+swfFile.getPath()+" -T 9");
System.out.print(loadStream(p.getInputStream()));
System.err.print(loadStream(p.getErrorStream()));
System.out.print(loadStream(p.getInputStream()));
System.err.println("****swf转换成功,文件输出:"+swfFile.getPath()+"****");
if(pdfFile.exists())
{
pdfFile.delete();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
else if(environment==2)//linux环境处理
{
try {
Process
p=r.exec("pdf2swf "+pdfFile.getPath()+" -o
"+swfFile.getPath()+" -T 9");
System.out.print(loadStream(p.getInputStream()));
System.err.print(loadStream(p.getErrorStream()));
System.err.println("****swf转换成功,文件输出:"+swfFile.getPath()+"****");
if(pdfFile.exists())
{
pdfFile.delete();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
else {
System.out.println("****pdf不存在,无法转换****");
}
}
else {
System.out.println("****swf已存在不需要转换****");
}
}
static String loadStream(InputStream in) throws IOException
{
int ptr=0;
in=new BufferedInputStream(in);
StringBuffer buffer=new StringBuffer();
while((ptr=in.read())!=-1)
{
buffer.append((char)ptr);
}
return buffer.toString();
}
/*
* 转换主方法
*/
public boolean conver()
{
if(swfFile.exists())
{
System.out.println("****swf转换器开始工作,该文件已经转换为swf****");
return true;
}
if(environment==1)
{
System.out.println("****swf转换器开始工作,当前设置运行环境windows****");
}
else {
System.out.println("****swf转换器开始工作,当前设置运行环境linux****");
}
try {
doc2pdf();
pdf2swf();
} catch (Exception e) {
// TODO: Auto-generated catch block
e.printStackTrace();
return false;
}
if(swfFile.exists())
{
return true;
}
else {
return false;
}
}
/*
* 返回文件路径
* @param s
*/
public String getswfPath()
{
if(swfFile.exists())
{
String tempString
=swfFile.getPath();
tempString=tempString.replaceAll("\\\\", "/");
return tempString;
}
else{
return "";
}
}
/*
* 设置输出路径
*/
public void setOutputPath(String outputPath)
{
this.outputPath=outputPath;
if(!outputPath.equals(""))
{
String
realName=fileName.substring(fileName.lastIndexOf("/"),fileName.lastIndexOf("."));
if(outputPath.charAt(outputPath.length())=='/')
{
swfFile=new
File(outputPath+realName+".swf");
}
else
{
swfFile=new
File(outputPath+realName+".swf");
}
}
}
public static void main(String s[])
{
DocConverter d=new DocConverter("c:/temp/111.ppt");
d.conver();
}
}
在DocConverter.java,右键属性 - >Run as - >Java Application ,输出main的测试结果。笔者分别进行单个转换,及批量转换,都测试可行。
至于为什么能成功进行pdf及swf的完整转换,在代码中没有看到和上述问题相关的控制。笔者在得到预期的结果,偶尔也会装糊涂,不去继续深究。
第五步,flexpaper在线浏览swf文档
FlexPaper是一个开源轻量级的在浏览器上显示各种文档的组件,被设计用来与PDF2SWF一起使用,
使在Flex中显示PDF成为可能,而这个过程并无需PDF软件环境的支持。它可以被当做Flex的库来使用。
另外你也可以通过将一些例如Word、PPT等文档转成PDF,然后实现在线浏览。
FlexPaper_1.2.4_flash:无打印功能
FlexPaper_1.4.7_flash:打印功能,右键打印
这里我们不需要让用户打印,所以笔者选择FlexPaper_1.2.4_flash。
FlexPaper项目中有演示demo,这里笔者不多述。
综上,一个完整的在线文档浏览方案。
其他,使用iText将jpg/jpeg/png转换为pdf
iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库。通过iText不仅可以生成
PDF或rtf的文档,而且可以将XML、Html文件转化为PDF文件。1.在企业的信息系统中,报表处理一直占比较重要的作用,iText--一种生
成PDF报表的Java组件,通过在服务器端使用Jsp或JavaBean生成PDF报表,客户端采用超级连接显示或下载得到生成的报表,这样就很好的解
决了B/S系统的报表处理问题。2.支持文本,表格,图形的操作,可以方便的跟 Servlet 进行结合。
继续笔者的DocConverter项目。开发环境是MyEclipse
9.0。笔者下载的是iText5.0.4。
新建JPG2PDFUtil.java
package com.iori.webapp.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.PdfWriter;
public class JPG2PDFUtil {
private String inputFileString;
private String outputFileString;
public JPG2PDFUtil(String inputFile, String outputFile) {
this.inputFileString = inputFile;
this.outputFileString = outputFile;
}
public void imgtopdf()
{
//创建一个文档对象
Document doc = new Document();
try {
//定义输出文件的位置
PdfWriter.getInstance(doc,
new FileOutputStream(outputFileString));
//开启文档
doc.open();
//设定字体 为的是支持中文
//BaseFont bfChinese = BaseFont.createFont("STSong-Light",
"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
// Font FontChinese = new Font(bfChinese, 12, Font.NORMAL);
//向文档中加入图片
/*//以下是多图合成一个pdf,暂时用不到
for(int i=1;i<32;i++)
{
//取得图片~~~图片格式:
Image jpg1 = Image.getInstance("c:/"+i+".jpg");
//原来的图片的路径
//获得图片的高度
float heigth=jpg1.height();
float width=jpg1.width();
System.out.println("heigth"+i+"----"+heigth);
System.out.println("width"+i+"-----"+width);
//合理压缩,h>w,按w压缩,否则按w压缩
//int
percent=getPercent(heigth, width);
//统一按照宽度压缩
int percent=getPercent2(heigth,
width);
//设置图片居中显示
jpg1.setAlignment(Image.MIDDLE);
//直接设置图片的大小~~~~~~~第三种解决方案,按固定比例压缩
//jpg1.scaleAbsolute(210.0f,
297.0f);
//按百分比显示图片的比例
jpg1.scalePercent(percent);//表示是原来图像的比例;
//可设置图像高和宽的比例
//jpg1.scalePercent(50, 100);
doc.add(jpg1);
}
*/
//向文档中加入图片
//取得图片~~~图片格式:
Image jpg1 = Image.getInstance(inputFileString); //原来的图片的路径
//获得图片的高度
float heigth=jpg1.height();
float width=jpg1.width();
System.out.println("heigth----"+heigth);
System.out.println("width-----"+width);
//合理压缩,h>w,按w压缩,否则按w压缩
//int percent=getPercent(heigth, width);
//统一按照宽度压缩
int percent=getPercent2(heigth, width);
//设置图片居中显示
jpg1.setAlignment(Image.MIDDLE);
//直接设置图片的大小~~~~~~~第三种解决方案,按固定比例压缩
//jpg1.scaleAbsolute(210.0f, 297.0f);
//按百分比显示图片的比例
jpg1.scalePercent(percent);//表示是原来图像的比例;
//可设置图像高和宽的比例
//jpg1.scalePercent(50, 100);
doc.add(jpg1);
//关闭文档并释放资源
doc.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 第一种解决方案
* 在不改变图片形状的同时,判断,如果h>w,则按h压缩,否则在w>h或w=h的情况下,按宽度压缩
* @param h
* @param w
* @return
*/
public int getPercent(float h,float w)
{
int p=0;
float p2=0.0f;
if(h>w)
{
p2=297/h*100;
}
else
{
p2=210/w*100;
}
p=Math.round(p2);
return p;
}
/**
* 第二种解决方案,统一按照宽度压缩
* 这样来的效果是,所有图片的宽度是相等的,自我认为给客户的效果是最好的
* @param args
*/
public int getPercent2(float h,float w)
{
int p=0;
float p2=0.0f;
p2=530/w*100;
p=Math.round(p2);
return p;
}
/**
* 第三种解决方案,就是直接压缩,不安像素比例,全部压缩到固定值,如210*297
*
* @param args
*/
public static void main(String[] args) {
JPG2PDFUtil pt=new
JPG2PDFUtil("c:/temp/ddd.jpg","c:/temp/ddd.pdf");
pt.imgtopdf();
}
}
在JPG2PDFUtil.java,右键属性 - >Run as - >Java Application ,输出main的测试结果。
在jsp中执行
新建MyJPG2PDFTest.jsp
import="java.io.*"%>
import="java.util.*"%>
import="com.iori.webapp.util.*"%>
JPG2PDFUtil pt=new
JPG2PDFUtil("c:/temp/333.jpg", "c:/temp/333.pdf");
pt.imgtopdf();
%>
Simple jsp page
here
在项目DocConverter根目录,右键属性 - >Run as - >MyEclipse Server Application
1.txt转换swf,发生中文乱码。
txt转换为utf-8编码,或txt格式手动改为odt,上传就不会发生乱码。从根源上解决,暂时就算了...暂时不想去纠结这些鸡毛。
2.加密的pdf可能导致转换为swf失败。
3.Microsoft Excel在公式运算中支持文本型的数值,而OpenOffice.org Calc不支持
此问题暂无解,请手动将Excel中文本型的数值修改为数值型的数值。
4.部分Excel存在过于丰富的样式(大部分指没有数据的单元格也填充了各种样式),即使用专业Adobe
Acrobat 7(或9) Pro来进行转换,
本来可能预计将产生20-30分页的pdf,结果却产生800-900分页的pdf。此类文档在线转换,难以避免的将导致转换死锁。
请在你的Excel文档中删除多余的,毫无必要的样式,或者你有更灵活的做法。
5.有些中文PDF文件转换为SWF后,出现乱码(特别一些专业期刊)
1.下载XPDF:xpdf-chinese-simplified.tar.gz
2.下载字体:gkai00mp.rar
3.修改xpdf-chinese-simplified目录下的add-to-xpdfrc文件。将里面的路径设为自己的路径:
#----- begin Chinese Simplified support package
(2011-sep-02)
cidToUnicode Adobe-GB1
C:\xpdf-chinese-simplified\Adobe-GB1.cidToUnicode
unicodeMap
ISO-2022-CN C:\xpdf-chinese-simplified\ISO-2022-CN.unicodeMap
unicodeMap EUC-CN
C:\xpdf-chinese-simplified\EUC-CN.unicodeMap
unicodeMap
GBK
C:\xpdf-chinese-simplified\GBK.unicodeMap
cMapDir Adobe-GB1
C:\xpdf-chinese-simplified\CMap
toUnicodeDir
C:\xpdf-chinese-simplified\CMap
fontDir
C:\WINDOWS\Fonts
displayCIDFontTT Adobe-GB1
C:\xpdf-chinese-simplified\CMap\gkai00mp.ttf
#fontFileCC Adobe-GB1 /usr/..../gkai00mp.ttf
#----- end Chinese Simplified support package
4.参照上面的代码,在调用pdf2swf命令中加入“ -s languagedir=D:\\xpdf\\xpdf-chinese-simplified ”参数。
PDF2SWFUtil.java
String cmd = exePath + " \"" + fileDir +
"\" -o \"" + filePath + "/" + fileName +
".swf\" -T 9 -s languagedir=c:\\xpdf-chinese-simplified";
这样乱码的问题就解决了。
Java实现word文档在线预览,读取office文件
想要实现word或者其他office文件的在线预览,大部分都是用的两种方式,一种是使用openoffice转换之后再通过其他插件预览,还有一种方式就是通过POI读取内容然后预览. 一.使用openof ...
Java+FlexPaper+swfTools 文档在线预览demo
1.概述 主要原理 1.通过第三方工具openoffice,将word.excel.ppt.txt等文件转换为pdf文件 2.通过swfTools将pdf文件转换成swf格式的文件 3.通过FlexP ...
java 实现word文档在线预览
一.准备工具 1.通过第三方工具openoffice,将word.excel.ppt.txt等文件转换为pdf文件 下载地址:http://www.openoffice.org/download/in ...
Office文档在线预览
工具说明:通过传入文档的Web地址,即可进行Office文档的在线预览. 使用方式: 在http://office.qingshanboke.com地址后,通过url参数传入您想预览的文件路径. 如: ...
Java+FlexPaper+swfTools仿百度文库文档在线预览系统设计与实现
笔者最近在给客户开发文档管理系统时,客户要求上传到管理系统的文档(包括ppt,word,excel,txt)只能预览不允许下载.笔者想到了百度文库和豆丁网,百度文库和豆丁网的在线预览都是利用flash ...
Print2flash在.NET(C#)64位中的使用,即文档在线预览
转:http://www.cnblogs.com/flowwind/p/3411106.html Print2flash在.NET(C#)中的使用,即文档在线预览 office文档(word,ex ...
基于MVC4+EasyUI的Web开发框架经验总结(8)--实现Office文档的预览
在博客园很多文章里面,曾经有一些介绍Office文档预览查看操作的,有些通过转为PDF进行查看,有些通过把它转换为Flash进行查看,但是过程都是曲线救国,真正能够简洁方便的实现Office文档的预览 ...
[转载]基于MVC4+EasyUI的Web开发框架经验总结(8)--实现Office文档的预览
在博客园很多文章里面,曾经有一些介绍Office文档预览查看操作的,有些通过转为PDF进行查看,有些通过把它转换为Flash进行查看,但是过程都是曲线救国,真正能够简洁方便的实现Office文档的预览 ...
随机推荐
Kafka集群模式部署
环境:kafka 0.8.1.1 基本概念 Kafka维护按类区分的消息,称为主题(topic) 生产者(producer)向kafka的主题发布消息 消费者(consumer)向主题注册,并且接收发 ...
Qt全屏显示窗口、子窗口的相关函数
Qt全屏显示函数 window.showFullScreen() Qt最大化显示函数 window.showMaximized() Qt最小化显示函数 ...
Qt 如何处理密集型耗时的事情(频繁调用QApplication::processEvents)
有时候需要处理一些跟界面无关的但非常耗时的事情,这些事情跟界面在同一个线程中,由于时间太长,导致界面无法响应,处于“假死”状态.例如:在应用程序中保存文件到硬盘上,从开始保存直到文件保存完毕,程序不响 ...
windows下创建启动脚本bat
最主要是运用bat命令. call执行命令 比如 启动solr的服务,以前要进去solr的目录,然后bin/solr start 这样很麻烦.可以写个脚本放到桌面. call %CATALINA ...
django框架基础
所有的Web应用本质上就是一个socket服务端,而用户的浏览器就是一个socket客户端. 这样我们就可以自己实现Web框架了. 最简单的web框架 import socket sk = socke ...
绑定域名到JavaWeb项目,由域名直接访问到网站首页
java 预览word文档_Java版office文档在线预览相关推荐
- java 预览word文档_Java实现office文档与pdf文档的在线预览功能
最近项目有个需求要java实现office文档与pdf文档的在线预览功能,刚刚接到的时候就觉得有点难,以自己的水平难以在三四天做完.压力略大.后面查找百度资料.以及在同事与网友的帮助下,四天多把它做完 ...
- SpringBoot+Vue+OpenOffice实现文档管理(文档上传、下载、在线预览)
场景 SpringBoot集成OpenOffice实现doc文档转html: SpringBoot集成OpenOffice实现doc文档转html_BADAO_LIUMANG_QIZHI的博客-CSD ...
- Java通过openOffice实现word,excel,ppt转成pdf实现在线预览
Java通过openOffice实现word,excel,ppt转成pdf实现在线预览 一.OpenOffice 1.1 下载地址 1.2 JodConverter 1.3 新建实体类PDFDemo ...
- 恶意Office文档解析——1. Office文档格式解析
写在前面:这是我最近在做的一个小课题,按照研究进度不定期更新.主要是学习前人的研究思路,自己开发的内容会比较少. 复合文档的概念 复合文档不仅包含文本,而且包括图形.电子数据表格.声音.视频等其他信息 ...
- html怎么转换到百度,类似百度文库在线预览文档flash版(支持word、excel、ppt、pdf)+在线预览文档html版...
类似百度文库在线预览文档flash版(支持word.excel.ppt.pdf)+在线预览文档html版 (1).将文档转换为html,只支持支持office文档 (2).将文档转换为flash,实现 ...
- JAVA实现FTP服务器上文件上传下载以及文件在线预览
(一)介绍文件上传下载: (1)前端思路: 用formData封装好file以及相关参数,然后l利用ajax请求往后台传数据 html的代码:<input id="cm_file&qu ...
- java语言 回文判断_java判断回文字符串的几种方法
java判断回文字符串几种简单的实现: 1.将字符串倒置后逐一比较,实现如下: public class HuiWenTest { /** * @SERLIN */ public static voi ...
- SpringBoot 实现 Office 各种格式在线预览(详细教程,包教包会)
点击关注公众号,实用技术文章及时了解 项目特性 部署过程 2.1 二进制下载部署文件进行部署 2.2 docker方式部署 2.3 通过源代码编绎部署 部分配置说明 3.1 server.contex ...
- 文档格式转换(Office文档转成PDF或XPS)
最近在做微信云打印服务器,云服务器与微信云服务器通信己经OK,现在有一个很核心的功能需要实现,就是服务器端文档的格式转换 目标:将office.txt.图片格式的文档转成PDF 查阅了一些资料,格式转 ...
- 求助:office web apps在线预览问题:url的ip必须替换成域名才能访问,怎么做才能让他敲ip也能访问
最近有个需求需要实现文档的在线预览,调研了一些后,决定使用微软的office web apps实现在线预览. 现在转换server和域控server都配置好了,OWA的文档预览也实现了.但还有个问题, ...
最新文章
- matlab中.P文件的介绍
- NTU 课程笔记:CV6422 样本分布
- 编程之美求二进制数中1的个数扩展题
- text/html与text/plain有什么区别?
- Linux命令行常用小结
- Win10 开启移动热点 WiFi 的简单方法
- 计算机串口接打印机并口,电子连接系统上的串口和并口知识分享
- php upload 上传类,发布一个PHP的文件上传类——Uploader
- take their time用法
- 给临时停车号码牌插上翅膀:lua脚本语言加入—鲁哇客智能挪车号码牌技术升级之路
- pytorch安装(离线包)
- 爬取京东商城中的书籍信息
- 等保三级网络安全相关设备加固笔记
- java识别汉字个数_统计字符串中汉字的个数
- Windows下使用nc(netCat)命令
- CSS中的代表的什么
- CTFHUB-技能树-WEB通关
- SVN conflict的解决办法
- 《计算中的上帝》读书笔记
- 小米空气净化器滤芯RFID解密