`

类似百度文档库的flash播放器FlexPaper

 
阅读更多
你可以从http://flexpaper.googlecode.com/svn/trunk上下载flexpaer播放器,还有源码 ,用要SVN检出,
1 :下载openoffice,安装到本机,然后能过命令行打开服务
  cd C:\Program Files\OpenOffice.org 3\program
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

  在程序中你可以能过代码将word,txt,...数据源转化成Pdf格式的,
这是测试代码:

public static void main(String[] args) {

File inputFile = new File("D:\\新建文件夹 (2)\\河南分公司“创先争优”活动简报  第一期.doc");
File outputFile = new File("D:\\新建文件夹 (2)\\河南分公司“创先争优”活动简报  第一期.pdf");

// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
try {
connection.connect();
} catch (ConnectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// close the connection


connection.disconnect();

}

2:安装swftoos到本机,可以能过代码将pdf格式 的文件转化成swf
public static int ConvertPdfToSwf(String fileName,String destPath){  
        String destName = "",fileExt = "";  
        StringBuffer command = new StringBuffer();  
        fileExt = fileName.split("\\.")[fileName.split("\\.").length-1].toLowerCase();
        try{  
            File file = new File(fileName);  
            if(!file.exists()){//判断源文件是否存在  
                return 1;  
            }else if(!fileExt.equals("pdf")){//判断文件是否是pdf格式的文件  
                return 2;  
            }  
            else{  
                String swftoolsPath = "C:\\Program Files\\SWFTools";//获取pdf转swf工具的路径  
                if(!swftoolsPath.substring(swftoolsPath.length()-1, swftoolsPath.length()).equals("\\")){  
                    swftoolsPath = swftoolsPath+"\\";    //在目录后加 "\"  
                }  
                if(!destPath.substring(destPath.length()-1, destPath.length()).equals("\\")){  
                    destPath = destPath+"\\";    //在目录后加 "\"  
                }  
                File destFile = new File(destPath);  
                if(!destFile.exists()){//目标文件路径如果不存在,则创建目录  
                    destFile.mkdirs();  
                }  
                destName = file.getName().substring(0, file.getName().length()-4)+".swf";//目标文件名称  
                command.append(swftoolsPath).append("pdf2swf.exe ").append(fileName).append(" -o ").append(destPath).append(destName);  
                Process pro = Runtime.getRuntime().exec(command.toString());  
                BufferedReader buffer = new BufferedReader(new InputStreamReader(pro.getInputStream()));  
                while(buffer.readLine()!=null);  
                return pro.exitValue();  
            }  
        }catch (Exception e){  
            e.printStackTrace();  
            return 3;  
        }  
3:最后再把Exmple/FlexPaperViewer.html里面的SwfFile : escape("20100826124510.swf?v1.4.0rc2-refresh2"),文件名改成你要播放的那个swf,就可以看到效果了。
分享到:
评论
1 楼 niunan 2012-02-13  
请问那段转PDF的代码是.NET的还是JAVA的啊?看起来是.NET的。我用了但是不知道需要导入什么类库啊。。

相关推荐

Global site tag (gtag.js) - Google Analytics