|
@@ -14,7 +14,6 @@ import org.slf4j.LoggerFactory;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
-import java.util.Arrays;
|
|
|
|
|
|
/**
|
|
|
* @author: fengdesheng
|
|
@@ -28,37 +27,35 @@ public class ElectronUtils {
|
|
|
/**
|
|
|
* 将URL响应内容转为PDF文件
|
|
|
*/
|
|
|
- public static boolean toPdf(String url, String path) {
|
|
|
+ public static boolean toPdf(String cmdDir, String url, String path) {
|
|
|
if (StringUtils.isBlank(url) || StringUtils.isBlank(path)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- final String script = "electron-pdf %s %s -p A3 -l true -e view-ready";
|
|
|
if (isWindows()) {
|
|
|
//Windows带盘符路径,去掉首个"/"字符
|
|
|
if (path.indexOf(":") > 0 && path.startsWith("/")) {
|
|
|
path = path.replaceFirst("/", "");
|
|
|
}
|
|
|
- String cmd = WIN_PREFIX + String.format(script, url, path);
|
|
|
- return executeCommand(new String[]{cmd}, "GBK");
|
|
|
+ final String script = "electron-pdf %s %s -p A3 -l true -e view-ready";
|
|
|
+ String command = WIN_PREFIX + String.format(script, url, path);
|
|
|
+ return executeCommand(command, "GBK");
|
|
|
} else {
|
|
|
- String prefix = "export DISPLAY=':99.0' && Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &";
|
|
|
- String cdDir = "cd /usr/local/nodejs/node_global/bin";
|
|
|
- String cmd = LINUX_PREFIX + String.format(script, url, path);
|
|
|
- String[] commands = new String[]{"/bin/sh", "-c", cdDir + " && " + cmd};
|
|
|
- log.debug(Arrays.toString(commands));
|
|
|
- return executeCommand(commands, "UTF-8");
|
|
|
+ //Linux
|
|
|
+ final String script = "%s/electron-pdf-A3.sh %s %s";
|
|
|
+ String command = String.format(script, cmdDir, url, path);
|
|
|
+ return executeCommand(command, "UTF-8");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 执行命令
|
|
|
*/
|
|
|
- private static boolean executeCommand(String[] commands, String charsetName) {
|
|
|
+ private static boolean executeCommand(String command, String charsetName) {
|
|
|
Process process;
|
|
|
|
|
|
try {
|
|
|
- process = Runtime.getRuntime().exec(commands);
|
|
|
+ process = Runtime.getRuntime().exec(command);
|
|
|
} catch (IOException e) {
|
|
|
log.error(e.getMessage());
|
|
|
return false;
|