麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

pdf2swf

2019-11-11 04:47:37
字體:
來源:轉載
供稿:網友
import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;import java.io.InputStreamReader;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 String SWFTools_Windows = "C:/SWFTools/pdf2swf.exe ";	private int environment;// 環境1:windows,2:linux(涉及pdf2swf路徑問題)	public int getEnvironment() {		return environment;	}	public void setEnvironment(int environment) {		this.environment = environment;	}	private String fileName;	private File pdfFile;	private File swfFile;	private File docFile;	private File odtFile;	public DocConverter(String fileString) {		ini(fileString);	}	public DocConverter(String fileString, int environment) {		this.environment = environment;		ini(fileString);	}	/*	 * 初始化 @param fileString	 */	private void ini(String fileString) {		try {			fileName = fileString.substring(0, fileString.lastIndexOf("/"));			docFile = new File(fileString);			String s = fileString.substring(fileString.lastIndexOf("/") + 1, fileString.lastIndexOf("."));			fileName = fileName + "/" + s;			// 用于處理TXT文檔轉化為PDF格式亂碼,獲取上傳文件的名稱(不需要后面的格式)			String txtName = fileString.substring(fileString.lastIndexOf("."));			// 判斷上傳的文件是否是TXT文件			if (txtName.equalsIgnoreCase(".txt")) {				// 定義相應的ODT格式文件名稱				odtFile = new File(fileName + ".odt");				// 將上傳的文檔重新copy一份,并且修改為ODT格式,然后有ODT格式轉化為PDF格式				this.copyFile(docFile, odtFile);				pdfFile = new File(fileName + ".pdf"); // 用于處理PDF文檔			} else if (txtName.equals(".pdf") || txtName.equals(".PDF")) {				pdfFile = new File(fileName + ".pdf");				// this.copyFile(docFile, pdfFile);			} else {				pdfFile = new File(fileName + ".pdf");			}			swfFile = new File(fileName + ".swf");		} catch (Exception e) {			e.printStackTrace();		}	}	/**	 * @Title: copyFile @Description: docFile2 @param: @param odtFile2 @return:	 *         void @author: hl @time: 2014-4-17 下午9:41:52 @throws	 */	private void copyFile(File sourceFile, File targetFile) throws Exception {		// 新建文件輸入流并對它進行緩沖 		FileInputStream input = new FileInputStream(sourceFile);		BufferedInputStream inBuff = new BufferedInputStream(input);		//  新建文件輸出流并對它進行緩沖		FileOutputStream output = new FileOutputStream(targetFile);		BufferedOutputStream outBuff = new BufferedOutputStream(output);		//  緩沖數組 		byte[] b = new byte[1024 * 5];		int len;		while ((len = inBuff.read(b)) != -1) {			outBuff.write(b, 0, len);		}		//  刷新此緩沖的輸出流		outBuff.flush();		//  關閉流		inBuff.close();		outBuff.close();		output.close();		input.close();	}	/*	 * 轉為PDF @param file	 */	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();				} catch (java.net.ConnectException e) {					// ToDo Auto-generated catch block					e.printStackTrace();					throw e;				} catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) {					e.printStackTrace();					throw e;				} catch (Exception e) {					e.printStackTrace();					throw e;				}			}		}	}	/*	 * 轉換成swf	 */	private void pdf2swf() throws Exception {		if (!swfFile.exists()) {			if (pdfFile.exists()) {				Runtime r = Runtime.getRuntime();				if (environment == 1) {// windows環境處理					Process p = null;					try {						String[] cmd = new String[7];						cmd[0] = SWFTools_Windows;						cmd[1] = "-i";						cmd[2] = pdfFile.getPath().trim();						cmd[3] = "-o";						cmd[4] = swfFile.getPath().trim();						cmd[5] = "-s";						cmd[6] = "languagedir=C://xpdf";						p = Runtime.getRuntime().exec(cmd);						InputStream is2 = p.getErrorStream();						BufferedReader br2 = new BufferedReader(new InputStreamReader(is2));						while (br2.readLine() != null)							;						p.waitFor();						p.exitValue();						// // 如果不讀取流則targetFile.exists() 文件不存在,但是程序沒有問題						if (pdfFile.exists()) {							pdfFile.delete();						}					} catch (Exception e) {						e.printStackTrace();						throw e;					} finally {						if (p != null) {							p.destroy();						}						p = null;					}				} else if (environment == 2) {// linux環境處理					try {						r.exec("pdf2swf " + pdfFile.getPath() + " -o " + swfFile.getPath() + " -T 9");					} catch (Exception e) {						e.printStackTrace();						throw new RuntimeException();					}				}			}		}	}	/*	 * 轉換主方法	 */	public boolean conver() {		if (swfFile.exists()) {			return true;		}		try {			doc2pdf();			pdf2swf();		} catch (Exception e) {			return false;		}		if (swfFile.exists()) {			return true;		} else {			return false;		}	}	/*	 * 返回文件路徑 @param s	 */	public String getswfPath() {		if (swfFile.exists()) {			return swfFile.getPath();		} else {			return "";		}	}	/*	 * 設置輸出路徑	 */	public void setOutputPath(String 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");			}		}	}}

中文可能會出現亂碼:

解決方案下載:

http://download.csdn.net/detail/anshichuxuezhe/9748124

放到C盤根目錄下


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产黄色一级大片 | 九色免费视频 | 国产精品自拍啪啪 | 久久九九热re6这里有精品 | 色偷偷欧美 | 国产午夜精品一区二区三区四区 | 久久精品一级片 | 超碰在线97国产 | 国产高潮好爽好大受不了了 | 成年人免费视频播放 | 一级黄色免费电影 | 一级毛片免费观看在线 | 国产成人精品区一区二区不卡 | 午夜a狂野欧美一区二区 | 黄色毛片观看 | 97干色| 亚洲一区二区三区高清 | 激情宗合| 黄色一级片免费在线观看 | 欧美日韩一 | 伊人久久国产精品 | 久久久久电影网站 | 黄色免费小网站 | 露脸各种姿势啪啪的清纯美女 | av在线免费电影 | 国产亚洲精品久久久久久大师 | 最新中文字幕第一页视频 | 宅男噜噜噜66国产免费观看 | 亚洲特黄 | 亚洲一区二区中文字幕在线观看 | 久久99久久99免费视频 | 毛片一级网站 | 精品一区二区三区日本 | 久久777国产线看观看精品 | 欧美人的天堂一区二区三区 | 92自拍视频 | 天天夜天天操 | 欧美性受xxxxxx黑人xyx性爽 | av色偷偷| 成人一区二区在线观看视频 | 久久久久久久久久久影视 |