openOffice+pdf2swf类百度文库):pdf转swf(Linux,window)

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为乱码。
出现的错误如下。

openOffice+pdf2swf类百度文库):pdf转swf(Linux,window)_第1张图片

 

错误的原因是缺少中文字符集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指令时要指定到当前目录】。

       openOffice+pdf2swf类百度文库):pdf转swf(Linux,window)_第2张图片

 

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

     openOffice+pdf2swf类百度文库):pdf转swf(Linux,window)_第3张图片

       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为我的配置可以参考

你可能感兴趣的:(linux,FlexPaper,pdf,OpenOffice,pdf2swf)