pdf에서 swf 파일로 전환

3394 단어 pdf
1. pdf2swf가 필요합니다.exe 서비스
2. 코드는 다음과 같다.

package com.converter;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.Properties;

public class PDF2SWF {
	public void converter(String name){
		//      
		Properties props = System.getProperties();
		//     Linux,Window XP,Window 7
		String os_name = props.getProperty("os.name");
		String os_flag = "";
		if (os_name.indexOf("Linux") == 0) {
			os_flag = "linux";
		} else if (os_name.indexOf("Windows") == 0) {
			os_flag = "window";
		}
		//  PDF  
		File pdfFile = new File("D:/test/" + name);
		String fname = name.substring(0,name.lastIndexOf("."));
		//      SWF  
		File swfFile = new File("D:/test/" + fname  + ".swf");
		
		Runtime rt = Runtime.getRuntime();
			//   PDF     SWF    
			// linux  : pdf2swf
			// -slanguagedir=/usr/local/xpdf-chinese-simplified-T
			// 9 -s poly2bitmap -s zoom=150
			// -sflashversion=9"/home/s.pdf" -o "/home/%.swf"
			Process p = null;
			try {
				if (os_flag.equals("window")) {
					p = rt.exec("D:/swftool/" + "pdf2swf.exe  "+ pdfFile.getPath() + " -o "+ swfFile.getPath() + " -T 9 -G -s poly2bitmap");
				} else {
					p = rt.exec("pdf2swf -s languagedir=/usr/local/xpdf-chinese-simplified -T 9 -spoly2bitmap -s zoom=150 -s flashversion=9 "+ pdfFile.getPath()+ " -o "+ swfFile.getPath());
				}
				
				//        
				if (os_flag.equals("window")) {
					clearCache(p.getInputStream(), p.getErrorStream());
				} else if (os_flag.equals("linux")) {
					InputStreamReader ir = new InputStreamReader(p.getInputStream());
					LineNumberReader input = new LineNumberReader(ir);
					String line;
					while ((line = input.readLine()) != null) {
					}
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
	}
	
	
	 //     
	public void clearCache(InputStream isi, InputStream ise) {
		try {
			final InputStream is1 = isi;
			//         InputStream   
			new Thread(new Runnable() {
				public void run() {
					BufferedReader br = new BufferedReader(new InputStreamReader(is1));
					try {
						while (br.readLine() != null);
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}).start();
			//   ErrorStream  
			BufferedReader br = new BufferedReader(new InputStreamReader(ise));
			//         
			StringBuilder buf = new StringBuilder();
			String line = null;
			try {
				line = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			//         
			while (line != null)
			buf.append(line);
			is1.close();
			ise.close();
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}


좋은 웹페이지 즐겨찾기