【JAVA】doc,excel,等转pdf,swf
下面是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 connectionconnection.disconnect();System.out.println("****pdf轉換成功,PDF輸出:" + pdfFile.getPath()+ "****");} catch (java.net.ConnectException e) { // ToDo Auto-generated// catch blocke.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格式。
總結
以上是生活随笔為你收集整理的【JAVA】doc,excel,等转pdf,swf的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [Linux] linux命令总结之di
- 下一篇: 20200726 plecs 元件显示变