(Linux,window)openOffice+pdf2swf+flexpaper(类百度文库)

安装openOffice.org

我安装的是3.3成功

package com.chinacreator.test;

import java.io.File;
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;
import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;


public class JOD4DocToPDF {
	
	public void docToPdf(File inputFile, File outputFile){
		Date start = new Date();
		 // connect to an OpenOffice.org instance running on port 8100
	    OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
	    try{
	    	connection.connect();
	    	
	    	 // convert
		    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;
	    	}
	    }
	    long l = (start.getTime()- new Date().getTime());
	    long day=l/(24*60*60*1000);
	       long hour=(l/(60*60*1000)-day*24);
	       long min=((l/(60*1000))-day*24*60-hour*60);
	       long s=(l/1000-day*24*60*60-hour*60*60-min*60);
	       System.out.println("生成"+outputFile.getName()+"耗费:"+min+"分"+s+"秒");
	}
	
	class TestThread extends java.lang.Thread{
		public File inputFile;
		public File outputFile;
		
		public void run(){
			JOD4DocToPDF t = new JOD4DocToPDF();
			t.docToPdf(inputFile, outputFile);
			System.out.println(outputFile.getName()+"文件已生成");
		}
	}
	
	public void test(String path,String st){
		TestThread t1 = new TestThread();
		t1.inputFile = new File(path+st+".doc");
//		t1.inputFile = new File(path+st+".xls");
		t1.outputFile = new File(path+st+".pdf");
		
//		
//		TestThread t2 = new TestThread();
//		t2.inputFile = new File("d:/document2.doc");
//		t2.outputFile = new File("d:/document2.pdf");
//		
//		TestThread t3 = new TestThread();
//		t3.inputFile = new File("d:/document3.doc");
//		t3.outputFile = new File("d:/document3.pdf");
		
		
//		t2.start();
		t1.start();
//		t3.start();
	}
	
	public static void main(String[] args) throws Exception{
		String Path="D:\\";//转换的文件路径
		String str="中国2s";//转换的文件名称
		try{
			JOD4DocToPDF p = new JOD4DocToPDF(); //生成pdf
			p.test(Path,str);
		}catch(Exception ex)
		{
			System.out.println("error");
		}
		
		
		System.out.println("success");
	  }

}

1:工具准备
swftools.exe 下载
http://www.swftools.org/download.html
安装至D盘
SWFTools提供了一系列将各种文件转成swf的工具:
font2swf.exe
gif2swf.exe
jpeg2swf.exe
pdf2swf.exe
png2swf.exe
wav2swf.exe
这里我们只使用pdf2swf.exe
我用的版本是:swftools-0.9.1.exe


flexpaper下载
http://code.google.com/p/flexpaper/
这里我们使用已经编译好的FlexPaper的flash版本

 

我用的版本是:FlexPaper_1.4.7_flash.zip

把FlexPaper下载解压到项目的webRoot目录下

    	<div style="position:absolute;left:10px;top:10px;">
	        <a id="viewerPlaceHolder" style="width:660px;height:480px;display:block"></a>
	        
	        <script type="text/javascript"> 
				var fp = new FlexPaperViewer(	
						 'FlexPaper/FlexPaperViewer',
						 'viewerPlaceHolder', { config : {
						 SwfFile : escape(Paper.swf'),
						 Scale : 0.6, 
						 ZoomTransition : 'easeOut',
						 ZoomTime : 0.5,
						 ZoomInterval : 0.2,
						 FitPageOnLoad : true,
						 FitWidthOnLoad : false,
						 FullScreenAsMaxWindow : false,
						 ProgressiveLoading : false,
						 MinZoomSize : 0.2,
						 MaxZoomSize : 5,
						 SearchMatchAll : false,
						 InitViewMode : 'Portrait',
						 PrintPaperAsBitmap : false,
						 
						 ViewModeToolsVisible : true,
						 ZoomToolsVisible : true,
						 NavToolsVisible : true,
						 CursorToolsVisible : true,
						 SearchToolsVisible : true,
  						
  						 localeChain: 'en_US'
						 }});
	        </script>
        </div>

 

 

 

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

/*
* PDF转SWF工具
* @author tangs
*
*/
public class Converter {
	public static int convertPDF2SWF(String sourcePath, String destPath, String fileName) throws IOException {
//		//目标路径不存在则建立目标路径
		File dest = new File(destPath);
		if (!dest.exists()) dest.mkdirs();
		
		//源文件不存在则返回
		File source = new File(sourcePath);
		if (!source.exists()) return 0;
		
		//调用pdf2swf命令进行转换
//		String command = "D:\\swftools\\pdf2swf.exe" + " -o \"" + destPath  + fileName +"\"  <SPAN style='COLOR: #ff0000'>-s languagedir=D:\\xpdf\\xpdf-chinese-simplified</SPAN> -s flashversion=9 \"" + sourcePath + "\"";
//		String command = "D:\\swftools\\pdf2swf.exe" + " -o \"" + destPath  +  fileName +"\" -s flashversion=9 \"" + sourcePath + "\"";
		String command= "D:/SWFTools/pdf2swf.exe  -t \""+destPath+"\\Java.pdf\" -o  \""+destPath+"\\test.swf\" -s flashversion=9 -s languagedir=D:\\xpdf\\xpdf-chinese-simplified ";  
		System.out.println("cmd:"+command);
		Process process = Runtime.getRuntime().exec(command); // 调用外部程序   
		final InputStream is1 = process.getInputStream();   
		new Thread(new Runnable() {   
		    public void run() {   
		        BufferedReader br = new BufferedReader(new InputStreamReader(is1));    
		        try {
					while(br.readLine()!= null) ;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}   
		    }   
		}).start(); // 启动单独的线程来清空process.getInputStream()的缓冲区   
		InputStream is2 = process.getErrorStream();   
		BufferedReader br2 = new BufferedReader(new InputStreamReader(is2));    
		StringBuilder buf = new StringBuilder(); // 保存输出结果流   
		String line = null;   
		while((line = br2.readLine()) != null) buf.append(line); // 循环等待ffmpeg进程结束   
		System.out.println("输出结果为:" + buf);
		
//		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(pro.getInputStream()));
		while (br2.readLine() != null); 
		
		try {
			process.waitFor();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return process.exitValue();

		
	}

	
	public static void main(String []args) throws IOException {
		String sourcePath = "D:\\Java.pdf";
		String destPath = "D:\\";
		String fileName = "Javssa.swf";
		try{
		Converter.convertPDF2SWF(sourcePath, destPath, fileName);
		
		}catch(Exception ex)
		{
			System.out.println("error");
		}
		System.out.println("success");
	
		
		
	}
}

 

如果错误:

Error: Unknown character collection 'Adobe-GB1'Error: Couldn't find 'GBK-EUC-H' CMap file for 'Adobe-GB1' collectionError: Unknown CMap 'GBK-EUC-H' for character collection 'Adobe-GB1'Error: Unknown character collection 'Adobe-GB1'Error: Couldn't find 'GBK-EUC-H' CMap file for 'Adobe-GB1' collectionError: Unknown CMap 'GBK-EUC-H' for character collection 'Adobe-GB1'Error: Unknown character collection 'Adobe-GB1'Error: Couldn't find 'GBK-EUC-H' CMap file for 'Adobe-GB1' collectionError: Unknown CMap 'GBK-EUC-H' for character collection 'Adobe-GB1'Error: Unknown character collection 'Adobe-GB1'Error: Couldn't find 'GBK-EUC-H' CMap file for 'Adobe-GB1' collectionError: Unknown CMap 'GBK-EUC-H' for character collection 'Adobe-GB1'Error: Unknown font tag 'F2'Truetype wasn't able to load glyph 0, error 160Truetype wasn't able to load glyph 0, error 160Truetype wasn't able to load glyph 0, error 160Truetype wasn't able to load glyph 0, error

 

改错方法:

swf2pdf转swf时字符集问题

 终于碰到swf2pdf字符集问题呢,今天转一个老的pdf是出现字符集问题,并转换的swf为乱码。
出现的错误如下。

错误现象

 

错误的原因是缺少中文字符集GBK-EUC-H。解决方法使用xpdf增加缺少的字符集。解决步骤如下:

(一) 下载相关的xpdf及字符集

xpdf-3.02pl5-win32.zip
下载地址为
ftp://ftp.foolabs.com/pub/xpdf/xpdf-3.02pl5-win32.zip
xpdf-chinese-simplified.tar.gz
下载地址为
ftp://ftp.foolabs.com/pub/xpdf/xpdf-chinese-simplified.tar.gz

也可以去http://www.foolabs.com/xpdf/download.html查找你自己需要的字符集

以上两个文件我已经放到附件里面有用的话可以下载

(二) 配置xpdf及字符集

       1:解压xpdf-3.02pl5-win32.zip,解压后修改名称为xpdf,并将其考到c盘根目录下【路径可以随意指定,但是执行pdf2swf指令时要指定到当前目录】。

      

 

       2:解压xpdf-chinese-simplified,将xpdf-chinese-simplified放置xpf目录下

    

       3:修改xpdf-chinese-simplified目录下的add-to-xpdfrc文件

Add-to-xpdfrc代码
#----- begin Chinese Simplified support package (2004-jul-27)
cidToUnicode        Adobe-GB1         D:\xpdf\xpdf-chinese-simplified\Adobe-GB1.cidToUnicode 
unicodeMap            ISO-2022-CN    D:\xpdf\xpdf-chinese-simplified\ISO-2022-CN.unicodeMap 
unicodeMap    EUC-CN        D:\xpdf\xpdf-chinese-simplified\EUC-CN.unicodeMap 
unicodeMap    GBK     D:\xpdf\xpdf-chinese-simplified\GBK.unicodeMap 
cMapDir     Adobe-GB1    D:\xpdf\xpdf-chinese-simplified\CMap 
toUnicodeDir  D:\xpdf\xpdf-chinese-simplified\CMap 
fontDir C:\WINDOWS\Fonts 
displayCIDFontTT Adobe-GB1 C:\WINDOWS\Fonts\simhei.ttf 
#displayCIDFontTT	Adobe-GB1	/usr/..../gkai00mp.ttf
#----- end Chinese Simplified support package

 (三) 执行pdf2swf命令时增加字符集指令

      java代码修改为

 

String command= "D:/swftools/pdf2swf.exe  -t \""+path+"\\test.pdf\" -o  \""+path+"\\test.swf\" -s flashversion=9 -s languagedir=C:\\xpdf\\xpdf-chinese-simplified ";

  以上完成关于字符集乱码的配置。

增加完成后执行命令可以看到adding命令

以上不能全部解决字符集乱码的问题可能还会缺少字符

可以看缺少什么字符集就加什么字符集

displayCIDFontTT Adobe-GB1 C:\WINDOWS\Fonts\你的字符集

附件xpf.rar为我的配置可以参考

posted on 2011-11-24 17:18  肖秋峰  阅读(911)  评论(0编辑  收藏  举报

导航