zoukankan      html  css  js  c++  java
  • swftools 中文乱码

    通过代码将PDF转换成SWF来说,现在比较常用的一种方式就是利用SWFTools工具中的pdf2swf(http://www.swftools.org/

    /**

    Java代码  收藏代码
    1.  * PDF转SWF工具  
    2.  * @author tangs  
    3.  *  
    4.  */  
    5. public class Converter {  
    6.     public static int convertPDF2SWF(String sourcePath, String destPath, String fileName) throws IOException {  
    7.         //目标路径不存在则建立目标路径  
    8.         File dest = new File(destPath);  
    9.         if (!dest.exists()) dest.mkdirs();  
    10.           
    11.         //源文件不存在则返回  
    12.         File source = new File(sourcePath);  
    13.         if (!source.exists()) return 0;  
    14.           
    15.         //调用pdf2swf命令进行转换  
    16.         String command = "D:\\Program Files\\SWFTools\\pdf2swf.exe" + " -o \"" + destPath + "\\" + fileName + "\"  <span style="color: #ff0000;">-s languagedir=D:\\xpdf\\xpdf-chinese-simplified</span> -s flashversion=9 \"" + sourcePath + "\"";  
    17.           
    18.         Process pro = Runtime.getRuntime().exec(command);  
    19.           
    20.         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(pro.getInputStream()));  
    21.         while (bufferedReader.readLine() != null);   
    22.           
    23.         try {  
    24.             pro.waitFor();  
    25.         } catch (InterruptedException e) {  
    26.             // TODO Auto-generated catch block  
    27.             e.printStackTrace();  
    28.         }  
    29.           
    30.         return pro.exitValue();  
    31.           
    32.     }  
    33.       
    34.     public static void main(String []args) throws IOException {  
    35.         String sourcePath = "c:\\test.pdf";  
    36.         String destPath = "c:\\";  
    37.         String fileName = "test.swf";  
    38.         Converter.convertPDF2SWF(sourcePath, destPath, fileName);  
    39.     }  
    40. }  

       就这么简单的几行代码就可以了。但是在程序中遇到中文就会出现意想不到的情况,这个也不例外。在转换中,我发现有些中文PDF文件转换后会出现乱码的现象,因此这里还要处理一下乱码的问题。看到上面代码中红色的一段了吗?这就是解决乱码的方法。这个方法是参考了http://hi.baidu.com/xwx520/blog/item/1d0c423885b392fab311c72e.html这篇文章,感谢作者。

    1.下载XPDF:ftp://ftp.foolabs.com/pub/xpdf/xpdf-chinese-simplified.tar.gz,并解压到xpdf-chinese-simplified目录下。

    2.下载字体:http://blog.pjoke.com/wp-content/uploads/2009/02/font.zip,并解压到xpdf-chinese-simplified/CMap目录下。

    3.修改xpdf-chinese-simplified目录下的add-to-xpdfrc文件。将里面的路径设为自己的路径:

    4.参照上面的代码,在调用pdf2swf命令中加入“ -s languagedir=D:\\xpdf\\xpdf-chinese-simplified ”参数。

    这样乱码的问题就解决了。

  • 相关阅读:
    把IDEA中新建的项目提交到Github仓库中
    在IDEA中设置方法自动注释(带参数和返回值)
    如何在 Maven 工程中引入其他jar包 并生效?(以 Netty 为例)
    在 IDEA 中 配置 Maven
    Visio中锁定元件
    DevExpress中 TreeList控件的常规配置
    从SuperSocket的App.config中读取配置,并修改保存,再重启服务
    devexpress 中 XtraTabcontrol 改变BackColor 的方法
    DevExpress 中 GridControl 的数据源DataTable 内容改变后 重新绑定
    如何在linux中设置tab键长度
  • 原文地址:https://www.cnblogs.com/weipeng/p/3114823.html
Copyright © 2011-2022 走看看