java txt转pdf之后转swf文件内容空白?

我我我爱学理论 2017-11-29 05:50:35
因为项目需要要实现文档上传之后转成swf放到flash中播放
现在遇到问题吧txt转pdf后继续转swf的时候.swf文件的内容为空白
但是直接上传pdf或者ppt文件最后转换成swf都成功了,唯独txt转swf的时候输出的文件内容为空
txt转pdf代码:
public static void makePDF(String fileName,String name) {
try {
// 首先创建一个字体
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
Font FontChinese = new Font(bfChinese, 10, Font.NORMAL);
String line = null;
Document document;
document = new Document(PageSize.A4, 80, 80, 80, 80);
BufferedReader in = new BufferedReader(new FileReader(fileName));
PdfWriter.getInstance(
document,
new FileOutputStream(name));
document.open();
while ((line = in.readLine()) != null)
document.add(new Paragraph(22, line, FontChinese));
document.close();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
pdf转swf代码:
public static boolean convert(File sourceFile, File targetFile) {
try {
/**
* SWFTools_HOME在系统中的安装目录
* 1:window需要指定到 pdf2swf.exe 文件
* 2:linux则xxx/xxx/xxx/pdf2swf即可
*/
String SWFTools_HOME ="D:\\SwfTools\\pdf2swf.exe";
String[] cmd = new String[5];
cmd[0] = SWFTools_HOME;
cmd[1] = "-i";
cmd[2] = sourceFile.getAbsolutePath();
cmd[3] = "-o";
cmd[4] = targetFile.getAbsolutePath();
Process pro =Runtime.getRuntime().exec(cmd);
//获取进程的标准输入流
final InputStream is1 = pro.getInputStream();
//获取进城的错误流
final InputStream is2 = pro.getErrorStream();
// 如果不读取流则targetFile.exists() 文件不存在,但是程序没有问题
new Thread(new Runnable() {
@Override
public void run() {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is1));
while (bufferedReader.readLine() != null);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
is1.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}

}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is2));
while (bufferedReader.readLine() != null);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
is1.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}

}
}).start();
pro.waitFor();
pro.exitValue();
} catch (Exception e) {
log.error("pdf转swf失败:",e);
return false;
}
return true;
}

输出结果图片
...全文
171 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧