Browse Source

Merge remote-tracking branch 'origin/master'

周箭河 5 năm trước cách đây
mục cha
commit
805e1ac5ae

+ 8 - 8
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ContractServiceImpl.java

@@ -211,7 +211,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 		// 生成借款协议PDF
 		try {
 			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath,
-					"config/fonts/simsun.ttc");
+					"simsun.ttc");
 		} catch (IOException e) {
 			throw new BizException("生成pdf协议失败", e);
 		}
@@ -221,7 +221,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 		Date date = new Date();
 		// 上传到oss
 		String dateStrOss = dateFormatOss.format(date);
-		dateStrOss = dateStrOss + "/" + DateUtil.getHour(date);
+		dateStrOss = "courses/" + dateStrOss + "/" + DateUtil.getHour(date);
 		String pdfFilePath = storagePlugin.uploadFile(dateStrOss, srcFile);
 
 		SysUserContracts sysUserContracts = new SysUserContracts();
@@ -344,7 +344,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 		// 生成借款协议PDF
 		try {
 			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath,
-					"config/fonts/simsun.ttc");
+					"simsun.ttc");
 		} catch (IOException e) {
 			throw new BizException("生成pdf协议失败", e);
 		}
@@ -364,7 +364,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 
 		// 上传到oss
 		String dateStrOss = dateFormatOss.format(date);
-		dateStrOss = dateStrOss + "/" + DateUtil.getHour(date);
+		dateStrOss = "courses/" + dateStrOss + "/" + DateUtil.getHour(date);
 		String pdfFilePath = storagePlugin.uploadFile(dateStrOss, srcFile);
 
 		SysUserContracts sysUserContracts = new SysUserContracts();
@@ -509,7 +509,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 		// 生成借款协议PDF
 		try {
 			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath,
-					"config/fonts/simsun.ttc");
+					"simsun.ttc");
 		} catch (IOException e) {
 			throw new BizException("生成pdf协议失败", e);
 		}
@@ -525,7 +525,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 
 		// 上传到oss
 		String dateStrOss = dateFormatOss.format(date);
-		dateStrOss = dateStrOss + "/" + DateUtil.getHour(date);
+		dateStrOss = "courses/" + dateStrOss + "/" + DateUtil.getHour(date);
 		String pdfFilePath = storagePlugin.uploadFile(dateStrOss, srcFile);
 
 		SysUserContracts sysUserContracts = new SysUserContracts();
@@ -669,7 +669,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 		// 生成借款协议PDF
 		try {
 			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath,
-					"config/fonts/simsun.ttc");
+					"simsun.ttc");
 		} catch (IOException e) {
 			throw new BizException("生成pdf协议失败", e);
 		}
@@ -690,7 +690,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 
 		// 上传到oss
 		String dateStrOss = dateFormatOss.format(date);
-		dateStrOss = dateStrOss + "/" + DateUtil.getHour(date);
+		dateStrOss = "courses/" + dateStrOss + "/" + DateUtil.getHour(date);
 		String pdfFilePath = storagePlugin.uploadFile(dateStrOss, srcFile);
 
 		SysUserContracts sysUserContracts = new SysUserContracts();

+ 8 - 7
mec-util/src/main/java/com/ym/mec/util/pdf/PDFUtil.java

@@ -11,7 +11,6 @@ import java.net.URL;
 
 import org.xhtmlrenderer.pdf.ITextRenderer;
 
-import com.google.zxing.client.result.BizcardResultParser;
 import com.lowagie.text.DocumentException;
 import com.lowagie.text.pdf.BaseFont;
 import com.ym.mec.util.exception.UtilException;
@@ -315,12 +314,14 @@ public class PDFUtil {
 	private static ITextRenderer getRendererByData(String baseUrl, String data, String fontFamily) throws DocumentException, IOException {
 		ITextRenderer renderer = new ITextRenderer();
 
-		File fontFamilyFile = new File(baseUrl, fontFamily);
-		if (fontFamilyFile.exists()) {
-			renderer.getFontResolver().addFont(fontFamilyFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
-		} else {
-			throw new FileNotFoundException("字体文件找不到:" + fontFamilyFile.getPath());
-		}
+		String windir = System.getenv("windir");
+        String fileSeparator = System.getProperty("file.separator");
+        if (windir != null && fileSeparator != null) {
+            renderer.getFontResolver().addFont(windir + fileSeparator + "fonts" + fileSeparator + fontFamily, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
+        }else{
+        	renderer.getFontResolver().addFont("/usr/share/fonts" + fileSeparator + fontFamily, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
+        }
+        
 		renderer.setDocumentFromString(data);
 		renderer.getSharedContext().setBaseURL(baseUrl);
 		renderer.layout();