|
@@ -7,6 +7,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
|
|
|
/**
|
|
|
* @Description: htmltopdf
|
|
@@ -26,12 +27,11 @@ public class HtmlToPdfUtil {
|
|
|
* @param pageSizeEnum
|
|
|
* @return
|
|
|
*/
|
|
|
- public static boolean convert(String srcPath, String destPath, PageSizeEnum pageSizeEnum) {
|
|
|
+ public static boolean convert(String srcPath, String destPath, PageSizeEnum pageSizeEnum) throws IOException {
|
|
|
File file = new File(destPath);
|
|
|
- File parent = file.getParentFile();
|
|
|
- // 如果pdf保存路径不存在,则创建路径
|
|
|
- if (!parent.exists()) {
|
|
|
- parent.mkdirs();
|
|
|
+ if (!file.getParentFile().exists()) {
|
|
|
+ file.getParentFile().mkdirs();
|
|
|
+ file.createNewFile();
|
|
|
}
|
|
|
StringBuilder cmd = new StringBuilder();
|
|
|
// if (System.getProperty("os.name").indexOf("Windows") == -1) {
|
|
@@ -43,10 +43,11 @@ public class HtmlToPdfUtil {
|
|
|
cmd.append(" ");
|
|
|
cmd.append(" --page-size ").append(pageSizeEnum.name()).append(" ");
|
|
|
cmd.append(" --disable-smart-shrinking ");
|
|
|
- cmd.append(" --orientation Landscape ");
|
|
|
+ if (pageSizeEnum == PageSizeEnum.A3) {
|
|
|
+ cmd.append(" --orientation Landscape ");
|
|
|
+ }
|
|
|
// cmd.append(" --page-width 1200px ");
|
|
|
// cmd.append(" --page-width 1200px ");
|
|
|
-// cmd.append(" --dpi 1191*842 ");
|
|
|
cmd.append(" --margin-top 0 ");
|
|
|
cmd.append(" --margin-bottom 0 ");
|
|
|
cmd.append(" --margin-left 0 ");
|