pdf에서 swf 파일로 전환
3394 단어 pdf
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();
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
React 및 Puppeteer: PDF 생성(프로젝트 설정)서버와 React를 템플릿 엔진으로 사용하여 PDF 문서를 생성하는 방법을 자세히 설명하는 실험입니다. 나는 과거에 @react-pdf/renderer를 사용했으며 이것은 내가 가진 몇 가지 문제를 해결하는 것을 목...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.