|
@@ -27,8 +27,14 @@ public class ElectronUtils {
|
|
/**
|
|
/**
|
|
* 将URL响应内容转为PDF文件
|
|
* 将URL响应内容转为PDF文件
|
|
*/
|
|
*/
|
|
- public static boolean toPdf(String cmdDir, String url, String path) {
|
|
|
|
|
|
+ public static boolean toPdf(String profile, String cmdDir, String url, String path) {
|
|
|
|
+ if (StringUtils.isBlank(profile)) {
|
|
|
|
+ log.warn("spring.profiles.active must be not empty.");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (StringUtils.isBlank(url) || StringUtils.isBlank(path)) {
|
|
if (StringUtils.isBlank(url) || StringUtils.isBlank(path)) {
|
|
|
|
+ log.warn("Url or Path must be not empty.");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -37,13 +43,12 @@ public class ElectronUtils {
|
|
if (path.indexOf(":") > 0 && path.startsWith("/")) {
|
|
if (path.indexOf(":") > 0 && path.startsWith("/")) {
|
|
path = path.replaceFirst("/", "");
|
|
path = path.replaceFirst("/", "");
|
|
}
|
|
}
|
|
- final String script = "electron-pdf %s %s -p A3 -l true -e view-ready";
|
|
|
|
- String command = WIN_PREFIX + String.format(script, url, path);
|
|
|
|
|
|
+
|
|
|
|
+ String command = String.format("cmd /c electron-pdf %s %s -p A3 -l true -e view-ready", url, path);
|
|
return executeCommand(command, "GBK");
|
|
return executeCommand(command, "GBK");
|
|
} else {
|
|
} else {
|
|
//Linux
|
|
//Linux
|
|
- final String script = "%s/electron-pdf-A3.sh %s %s";
|
|
|
|
- String command = String.format(script, cmdDir, url, path);
|
|
|
|
|
|
+ String command = String.format("%s/electron-pdf-%s.sh %s %s", cmdDir, profile, url, path);
|
|
return executeCommand(command, "UTF-8");
|
|
return executeCommand(command, "UTF-8");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -52,8 +57,9 @@ public class ElectronUtils {
|
|
* 执行命令
|
|
* 执行命令
|
|
*/
|
|
*/
|
|
private static boolean executeCommand(String command, String charsetName) {
|
|
private static boolean executeCommand(String command, String charsetName) {
|
|
- Process process;
|
|
|
|
|
|
+ log.debug("Execute Command:" + command);
|
|
|
|
|
|
|
|
+ Process process;
|
|
try {
|
|
try {
|
|
process = Runtime.getRuntime().exec(command);
|
|
process = Runtime.getRuntime().exec(command);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|