|
@@ -12,6 +12,7 @@ import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
|
|
+import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
|
|
|
|
@@ -27,28 +28,44 @@ public class ElectronUtils {
|
|
/**
|
|
/**
|
|
* 将URL响应内容转为PDF文件
|
|
* 将URL响应内容转为PDF文件
|
|
*/
|
|
*/
|
|
- public static boolean toPdf(String profile, String cmdDir, String url, String path) {
|
|
|
|
|
|
+ public static boolean toPdf(String profile, String cmdDir, String targetUrl, String pdfPath) {
|
|
if (StringUtils.isBlank(profile)) {
|
|
if (StringUtils.isBlank(profile)) {
|
|
- log.warn("spring.profiles.active must be not empty.");
|
|
|
|
|
|
+ log.warn("[toPdf] spring.profiles.active must be not empty.");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- if (StringUtils.isBlank(url) || StringUtils.isBlank(path)) {
|
|
|
|
- log.warn("Url or Path must be not empty.");
|
|
|
|
|
|
+ if (StringUtils.isBlank(targetUrl)) {
|
|
|
|
+ log.warn("[toPdf] targetUrl must be not empty.");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (StringUtils.isBlank(pdfPath)) {
|
|
|
|
+ log.warn("[toPdf] pdfPath must be not empty.");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isBlank(cmdDir)) {
|
|
|
|
+ log.warn("[toPdf] cmdDir must be not empty.");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ File dir = new File(cmdDir);
|
|
|
|
+ if (!dir.exists()) {
|
|
|
|
+ FileUtils.makeDirs(cmdDir);
|
|
|
|
+ }
|
|
|
|
+ final String parentDir = dir.getParent();
|
|
|
|
+
|
|
if (isWindows()) {
|
|
if (isWindows()) {
|
|
//Windows带盘符路径,去掉首个"/"字符
|
|
//Windows带盘符路径,去掉首个"/"字符
|
|
- if (path.indexOf(":") > 0 && path.startsWith("/")) {
|
|
|
|
- path = path.replaceFirst("/", "");
|
|
|
|
|
|
+ if (pdfPath.indexOf(":") > 0 && pdfPath.startsWith("/")) {
|
|
|
|
+ pdfPath = pdfPath.replaceFirst("/", "");
|
|
}
|
|
}
|
|
|
|
|
|
- String command = String.format("cmd /c electron-pdf %s %s -p A3 -l true -e view-ready", url, path);
|
|
|
|
|
|
+ String command = String.format("cmd /c electron-pdf %s %s -p A3 -l true -e view-ready", targetUrl, pdfPath);
|
|
return executeCommand(command, "GBK");
|
|
return executeCommand(command, "GBK");
|
|
} else {
|
|
} else {
|
|
//Linux
|
|
//Linux
|
|
- String command = String.format("%s/electron-pdf-%s.sh %s %s", cmdDir, profile, url, path);
|
|
|
|
|
|
+ String command = String.format("%s/electron-pdf-%s.sh %s %s", parentDir, profile, targetUrl, pdfPath);
|
|
return executeCommand(command, "UTF-8");
|
|
return executeCommand(command, "UTF-8");
|
|
}
|
|
}
|
|
}
|
|
}
|