下面是java下如何利用FlashPaper将doc等文件转化为swf文件-->
@param swfName 指定生成的swf文件名
@param documentName 需要转换为swf的文档名
String converter = "C:\\Program Files\\Macromedia\\FlashPaper 2\\FlashPrinter.exe -o C:\\struts\\swf\\"
+ swfName + ".swf C:\\struts\\document\\" + documentName;
上述代码实际上就是调用FlashPrinter.exe实现转换功能。
用过FlashPaper的朋友可能会发现FlashPaper生成的swf文件左上角有Adobe的商标,非常不雅观,而且swf还可以下载,当然这就和百度文库的在线阅读相悖了。如何隐藏商标和取消打印按钮哪?更有甚,如何定制自己的FlashPaper swf文件哪?这才是本文着重要讲的地方。
首先展示下我自己定制的swf文件:
下面将讲述如何定制swf文件:
1:下载 http://download.csdn.net/source/3439538的DefaultViewer2.swf文件(PS:这里有点推荐自己资源的意思,请不要鄙视我,O(∩_∩)O哈哈~),在此swf文件的基础上实现自己的修改。
2:利用swf反编译工具,这里推荐 硕思闪客精灵(SWFDecompiler),这个朋友们可以自己去Google下,如何需要破解版的可以和我联系,当然不用破解版的也能完成反编译。保存SWFDecompiler反编译过的.fla文件。
3:利用falsh制作工具(如Adobe Flash Professional CS5),打开此fla文件,找到第3个帧,添加下列代码即可实现定制(具体说明可以参加我的上一篇文章 FlashPaper组件__API ,隐藏即false,显示即true,请根据需要自行修改):
gMainView.showUIElement("PrevNext", true);
gMainView.showUIElement("Print", false);
gMainView.showUIElement("Find", true);
gMainView.showUIElement("Tool", false);
gMainView.showUIElement("Pop", false);
gMainView.showUIElement("Zoom", true);
gMainView.showUIElement("Page", true);
gMainView.showUIElement("Overflow", true);
4:将修改过的fla导出为swf文件,命名为DefaultViewer2.swf,找到FlashPaper的安装路径X:\Program Files\Macromedia\FlashPaper 2\Interface,覆盖下面的swf文件即可。
即完成swf的自定制。
页面展示部分:
如果直接在页面上展示swf文件,那么有点IT常识的人依旧可以在客户端通过迅雷等软件捕获swf文件,然后下载下来,这样依旧不能保护swf文件。在这里我的解决方法是利用一个空swf文件来加载你需要展示的swf文件,这样即使swf被捕获也只能捕获到这个空swf文件。而且,切记空swf需要加密的,否则被反编译后依旧很容易找到你的展示文件。PS:如果朋友们有更好的展示swf的解决办法欢迎留言探讨。
------------------上面事转的利用FlashPaper转swf,转的时候若文件过大会话费很长时间,excel转的时候列太多的话转折行,这些问题在研究。。。。
package com.zssoft.mis.test;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
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;
public class DocConverter {
private static final int environment = 1;// 环境1:windows
// 2:linux(涉及pdf2swf路径问题)
private String fileString;
private String outputPath = "";// 输入路径,如果不设置就输出在默认位置
private String fileName;
private File pdfFile;
private File swfFile;
private File docFile;
public DocConverter(String fileString) {
ini(fileString);
}
public void setFile(String fileString) {
ini(fileString);
}
private void ini(String fileString) {
this.fileString = fileString;
fileName = fileString.substring(0, fileString.lastIndexOf("."));
docFile = new File(fileString);
pdfFile = new File(fileName + ".pdf");
swfFile = new File(fileName + ".swf");
}
private void doc2pdf() throws Exception {
if (docFile.exists()) {
if (!pdfFile.exists()) {
OpenOfficeConnection connection = new SocketOpenOfficeConnection(
8100);
try {
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(
connection);
converter.convert(docFile, pdfFile);
// close the connection
connection.disconnect();
System.out.println("****pdf转换成功,PDF输出:" + pdfFile.getPath()
+ "****");
} catch (java.net.ConnectException e) { // ToDo Auto-generated
// catch block
e.printStackTrace();
System.out.println("****swf转换异常,openoffice服务未启动!****");
throw e;
} catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) {
e.printStackTrace();
System.out.println("****swf转换器异常,读取转换文件失败****");
throw e;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} else {
System.out.println("****已经转换为pdf,不需要再进行转化****");
}
} else {
System.out.println("****swf转换器异常,需要转换的文档不存在,无法转换****");
}
}
private void pdf2swf() throws Exception {
Runtime r = Runtime.getRuntime();
if (!swfFile.exists()) {
if (pdfFile.exists()) {
if (environment == 1) {// windows环境处理
try {
// Process p = r
// .exec("C:/Program Files/SWFTools/pdf2swf.exe "
// + pdfFile.getPath() + " -o "
// + swfFile.getPath() + " -T 9");
System.out.print(loadStream(p.getInputStream()));
System.err.print(loadStream(p.getErrorStream()));
System.out.print(loadStream(p.getInputStream()));
System.err.println("****swf转换成功,文件输出:"
+ swfFile.getPath() + "****");
if (pdfFile.exists()) {
pdfFile.delete();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} else if (environment == 2) {// linux环境处理
try {
Process p = r.exec("pdf2swf " + pdfFile.getPath()
+ " -o " + swfFile.getPath() + " -T 9");
System.out.print(loadStream(p.getInputStream()));
System.err.print(loadStream(p.getErrorStream()));
System.err.println("****swf转换成功,文件输出:"
+ swfFile.getPath() + "****");
if (pdfFile.exists()) {
pdfFile.delete();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
} else {
System.out.println("****pdf不存在,无法转换****");
}
} else {
System.out.println("****swf已存在不需要转换****");
}
}
static String loadStream(InputStream in) throws IOException {
int ptr = 0;
in = new BufferedInputStream(in);
StringBuffer buffer = new StringBuffer();
while ((ptr = in.read()) != -1) {
buffer.append((char) ptr);
}
return buffer.toString();
}
public boolean conver() {
if (swfFile.exists()) {
System.out.println("****swf转换器开始工作,该文件已经转换为swf****");
return true;
}
if (environment == 1) {
System.out.println("****swf转换器开始工作,当前设置运行环境windows****");
} else {
System.out.println("****swf转换器开始工作,当前设置运行环境linux****");
}
try {
doc2pdf();
pdf2swf();
} catch (Exception e) {
e.printStackTrace();
return false;
}
if (swfFile.exists()) {
return true;
} else {
return false;
}
}
// /* * 返回文件路径 * @param s */
public String getswfPath() {
if (swfFile.exists()) {
String tempString = swfFile.getPath();
tempString = tempString.replaceAll("\\\\", "/");
return tempString;
} else {
return "";
}
}
// /* * 设置输出路径 */
public void setOutputPath(String outputPath) {
this.outputPath = outputPath;
if (!outputPath.equals("")) {
String realName = fileName.substring(fileName.lastIndexOf("/"),
fileName.lastIndexOf("."));
if (outputPath.charAt(outputPath.length()) == '/') {
swfFile = new File(outputPath + realName + ".swf");
} else {
swfFile = new File(outputPath + realName + ".swf");
}
}
}
public static void main(String s[]) {
DocConverter d = new DocConverter("e:\\abc.doc");
d.conver();
}
}
------上述转pdf格式。