Commit 1606ba4f authored by ZWT's avatar ZWT

都删了

parent 6b9652f7
package pps.core.common.pdf;
import com.itextpdf.text.pdf.BaseFont;
import org.apache.commons.codec.binary.Base64;
import org.xhtmlrenderer.pdf.ITextFontResolver;
import org.xhtmlrenderer.pdf.ITextRenderer;
import sun.misc.BASE64Decoder;
import java.io.*;
import java.util.Map;
public class Html2Pdf {
public static String htmlTopdf(String htmlContent, String fontPath) throws Exception {
ByteArrayOutputStream byteArrayOutputStream = null;
InputStream sbs = null;
try {
byteArrayOutputStream = new ByteArrayOutputStream();
ITextRenderer renderer = new ITextRenderer();
ITextFontResolver font = renderer.getFontResolver();
font.addFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//添加中文识别,这里是设置的宋体,Linux下要换成对应的字体
renderer.setDocumentFromString(htmlContent);
renderer.layout();
renderer.createPDF(byteArrayOutputStream);
renderer.finishPDF();
byte[] buffer = byteArrayOutputStream.toByteArray();
sbs = new ByteArrayInputStream(buffer);
return getBase64FromInputStream(sbs);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (byteArrayOutputStream != null) {
try {
byteArrayOutputStream.close();
} catch (IOException e) {
}
}
if (sbs != null) {
try {
sbs.close();
} catch (IOException e) {
}
}
}
return null;
}
public static byte[] htmlToPdfByte(String htmlContent, String fontPath) {
ByteArrayOutputStream byteArrayOutputStream = null;
try {
byteArrayOutputStream = new ByteArrayOutputStream();
ITextRenderer renderer = new ITextRenderer();
ITextFontResolver font = renderer.getFontResolver();
font.addFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//添加中文识别,这里是设置的宋体,Linux下要换成对应的字体
renderer.setDocumentFromString(htmlContent);
renderer.layout();
renderer.createPDF(byteArrayOutputStream);
renderer.finishPDF();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (byteArrayOutputStream != null) {
try {
byteArrayOutputStream.close();
} catch (IOException e) {
}
}
}
return byteArrayOutputStream.toByteArray();
}
public static String getBase64FromInputStream(InputStream in) {
// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
byte[] data = null;
// 读取图片字节数组
try {
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100];
int rc = 0;
while ((rc = in.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
data = swapStream.toByteArray();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return new String(Base64.encodeBase64(data));
}
public static void saveBase64strToFile(String base64str, String outPath) {
createFile(new File(outPath));
if (base64str == null) {
return;
}
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(base64str);
for (int i = 0; i < b.length; ++i) {
if (b[i] < 0) {
b[i] += 256;
}
}
OutputStream out = new FileOutputStream(outPath);
out.write(b);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static String replaceContent(String htmlContent, Map<String, String> map) {
for (Map.Entry<String, String> entry : map.entrySet()) {
htmlContent = htmlContent.replaceAll(entry.getKey(), entry.getValue());
}
return htmlContent;
}
public static void createFile(File file) {
if (file.exists()) {
System.out.println("File exists");
} else {
System.out.println("File not exists, create it ...");
//getParentFile() 获取上级目录(包含文件名时无法直接创建目录的)
if (!file.getParentFile().exists()) {
System.out.println("not exists");
//创建上级目录
file.getParentFile().mkdirs();
}
try {
//在上级目录里创建文件
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void outFile(InputStream input, String outPath) {
createFile(new File(outPath));
BufferedInputStream in = null;
BufferedOutputStream out = null;
try {
in = new BufferedInputStream(input);
out = new BufferedOutputStream(new FileOutputStream(outPath));
int len = -1;
byte[] b = new byte[1024];
while ((len = in.read(b)) != -1) {
out.write(b, 0, len);
}
in.close();
out.close();
} catch (Exception e) {
}
}
}
package pps.core.common.pdf;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.*;
import sun.misc.BASE64Decoder;
import java.io.*;
public class UpdatePdfUtil {
/**
*
* @param bytes 数组
* @param contentText 添加的文字
* @return
* @throws Exception
*/
public static InputStream addText(byte[] bytes, String contentText)
throws Exception {
ByteArrayOutputStream byteArrayOutputStream = null;
PdfReader pdfReader = null;
PdfStamper stamper = null;
try {
byteArrayOutputStream = new ByteArrayOutputStream();
pdfReader = new PdfReader(bytes);
Rectangle rectangle = pdfReader.getPageSize(1);
stamper = new PdfStamper(pdfReader, byteArrayOutputStream);
PdfContentByte canvas = stamper.getUnderContent(1);
//替换关键字
canvas.beginText();
BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
canvas.setFontAndSize(bf, 13);
canvas.showTextAligned(Element.ALIGN_CENTER, contentText, rectangle.getWidth()-50, rectangle.getHeight()-20, 0);/*修正背景与文本的相对位置*/
canvas.endText();
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
} finally {
if (byteArrayOutputStream != null) {
try {
byteArrayOutputStream.close();
} catch (IOException e) {
}
}
if (stamper != null)
try {
stamper.close();
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (pdfReader != null) {
pdfReader.close();
}
}
return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
}
public static void main(String[] args) throws Exception {
File pdfFile = new File("D:\\pdf\\test1664334027252.pdf");
//2.定义一个byte数组,长度为文件的长度
byte[] pdfData = new byte[(int) pdfFile.length()];
//3.IO流读取文件内容到byte数组
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(pdfFile);
inputStream.read(pdfData);
addText(pdfData,"dasfad");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
}
}
}
}
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>xstartup-cloud</groupId> <groupId>xstartup-cloud</groupId>
<artifactId>xstartup-cloud-parent-gateway</artifactId> <artifactId>xstartup-cloud-parent-gateway</artifactId>
<version>1.15.169-xstartup-cloud</version> <version>1.16.69-xstartup-v3-cloud</version>
<relativePath/> <relativePath/>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -14,9 +14,17 @@ ...@@ -14,9 +14,17 @@
<artifactId>deploy-pps-gateway</artifactId> <artifactId>deploy-pps-gateway</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>xstartup-cloud</groupId> <groupId>xstartup-cloud</groupId>
<artifactId>xstartup-cloud-feature-huawei-cse-gateway</artifactId> <artifactId>xstartup-cloud-feature-alibaba</artifactId>
<version>1.16.69-xstartup-v3-cloud</version>
</dependency>
<dependency>
<groupId>xstartup</groupId>
<artifactId>xstartup-feature-cors</artifactId>
<version>1.16.69-xstartup-v3</version>
<scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<profiles> <profiles>
......
...@@ -3,7 +3,7 @@ package app; ...@@ -3,7 +3,7 @@ package app;
import xstartup.base.XStartup; import xstartup.base.XStartup;
import xstartup.base.conf.XServerConf; import xstartup.base.conf.XServerConf;
import xstartup.boot.XStartupApplication; import xstartup.boot.XStartupApplication;
import xstartup.feature.cloud.XCloudHuaweiCseGatewayFeature; import xstartup.feature.cloud.XCloudAlibabaFeature;
/** /**
* 网关模块启动程序 * 网关模块启动程序
...@@ -15,7 +15,7 @@ public class DeployPpsGatewayApplication { ...@@ -15,7 +15,7 @@ public class DeployPpsGatewayApplication {
public static void main(String... args) { public static void main(String... args) {
XStartup startup = new XStartupApplication("pps"); XStartup startup = new XStartupApplication("pps");
startup.config(new XServerConf(22068).naming("pps-gateway")); startup.config(new XServerConf(22068).naming("pps-gateway"));
startup.enable(XCloudHuaweiCseGatewayFeature.class); startup.enable(XCloudAlibabaFeature.class);
startup.run(args); startup.run(args);
} }
} }
...@@ -20,11 +20,18 @@ x.db.password=@x.db.password@ ...@@ -20,11 +20,18 @@ x.db.password=@x.db.password@
x.db.naming=@x.db.naming@ x.db.naming=@x.db.naming@
#cors #cors
x.cors.origin-pattern=* x.cors.origin-pattern=*
#\u6CE8\u518C\u4E2D\u5FC3\u5730\u5740 x.cors.exposed-headers=*
x.cloud.discovery.server-addr=@spring.cloud.servicecomb.discovery.address@ spring.autoconfigure.exclude=*
#\u6CE8\u518C\u7684\u5E94\u7528\u540D\u79F0\uFF08\u975E\u5FAE\u670D\u52A1\u540D\u79F0\uFF0C\u5FAE\u670D\u52A1\u540D\u79F0\u5728\u4EE3\u7801\u91CC\u8BBE\u7F6E\u4E86\uFF09 #\u6CE8\u518C\u4E2D\u5FC3
x.cloud.discovery.app-name=pps-application x.cloud.discovery.server-addr=@x.cloud.discovery.server-addr@
#\u7528\u6237\u540D x.cloud.discovery.namespace=@x.cloud.discovery.namespace@
x.cloud.discovery.username=@spring.cloud.servicecomb.credentials.account.name@ x.cloud.discovery.group=@x.cloud.discovery.group@
#\u5BC6\u7801 x.cloud.discovery.username=@x.cloud.discovery.username@
x.cloud.discovery.password=@spring.cloud.servicecomb.credentials.account.password@ x.cloud.discovery.password=@x.cloud.discovery.password@
\ No newline at end of file #\u914D\u7F6E\u4E2D\u5FC3
x.cloud.config.server-addr=@x.cloud.config.server-addr@
x.cloud.config.namespace=@x.cloud.config.namespace@
x.cloud.config.group=@x.cloud.config.group@
x.cloud.config.file-extension=@x.cloud.config.file-extension@
x.cloud.config.username=@x.cloud.config.username@
x.cloud.config.password=@x.cloud.config.password@
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>xstartup-cloud</groupId> <groupId>xstartup-cloud</groupId>
<artifactId>xstartup-cloud-parent-app</artifactId> <artifactId>xstartup-cloud-parent-app</artifactId>
<version>1.15.169-xstartup-cloud</version> <version>1.16.69-xstartup-v3-cloud</version>
<relativePath/> <relativePath/>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -29,10 +29,6 @@ ...@@ -29,10 +29,6 @@
<groupId>xstartup</groupId> <groupId>xstartup</groupId>
<artifactId>xstartup-feature-mybatis</artifactId> <artifactId>xstartup-feature-mybatis</artifactId>
</dependency> </dependency>
<dependency>
<groupId>xstartup-cloud</groupId>
<artifactId>xstartup-cloud-feature-huawei-cse</artifactId>
</dependency>
<dependency> <dependency>
<groupId>xstartup</groupId> <groupId>xstartup</groupId>
<artifactId>xstartup-feature-swagger-doc</artifactId> <artifactId>xstartup-feature-swagger-doc</artifactId>
...@@ -42,6 +38,11 @@ ...@@ -42,6 +38,11 @@
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version> <version>8.0.33</version>
</dependency> </dependency>
<dependency>
<groupId>xstartup-cloud</groupId>
<artifactId>xstartup-cloud-feature-alibaba</artifactId>
<version>1.16.69-xstartup-v3-cloud</version>
</dependency>
</dependencies> </dependencies>
<profiles> <profiles>
......
...@@ -9,7 +9,7 @@ import xstartup.boot.XStartupApplication; ...@@ -9,7 +9,7 @@ import xstartup.boot.XStartupApplication;
import xstartup.feature.XSwaggerDocFeature; import xstartup.feature.XSwaggerDocFeature;
import xstartup.feature.api.XApiFeature; import xstartup.feature.api.XApiFeature;
import xstartup.feature.api.conf.XApiCookieConf; import xstartup.feature.api.conf.XApiCookieConf;
import xstartup.feature.cloud.XCloudHuaweiCseFeature; import xstartup.feature.cloud.XCloudAlibabaFeature;
import xstartup.feature.mybatis.XMybatisFeature; import xstartup.feature.mybatis.XMybatisFeature;
import xstartup.feature.rpc.XRpcFeature; import xstartup.feature.rpc.XRpcFeature;
...@@ -27,7 +27,7 @@ public class DeployPpsSystemApplication { ...@@ -27,7 +27,7 @@ public class DeployPpsSystemApplication {
.config(new XServiceConf("pps")); .config(new XServiceConf("pps"));
startup.enable(XApiFeature.class) startup.enable(XApiFeature.class)
.config(new XApiCookieConf("%4bH8s9&", 43200)); .config(new XApiCookieConf("%4bH8s9&", 43200));
startup.enable(XCloudHuaweiCseFeature.class); startup.enable(XCloudAlibabaFeature.class);
startup.enable(XSwaggerDocFeature.class); startup.enable(XSwaggerDocFeature.class);
startup.enable(XMybatisFeature.class); startup.enable(XMybatisFeature.class);
startup.enable(XRpcFeature.class); startup.enable(XRpcFeature.class);
......
...@@ -33,11 +33,16 @@ x.db.pps.core.system.user=@x.db.pps.core.system.user@ ...@@ -33,11 +33,16 @@ x.db.pps.core.system.user=@x.db.pps.core.system.user@
x.db.pps.core.system.password=@x.db.pps.core.system.password@ x.db.pps.core.system.password=@x.db.pps.core.system.password@
x.db.pps.core.system.naming=@x.db.pps.core.system.naming@ x.db.pps.core.system.naming=@x.db.pps.core.system.naming@
pps.core.common.trace-log-config.enabletracelog=true pps.core.common.trace-log-config.enabletracelog=true
#\u6CE8\u518C\u4E2D\u5FC3\u5730\u5740 #\u6CE8\u518C\u4E2D\u5FC3
x.cloud.discovery.server-addr=@spring.cloud.servicecomb.discovery.address@ x.cloud.discovery.server-addr=@x.cloud.discovery.server-addr@
#\u6CE8\u518C\u7684\u5E94\u7528\u540D\u79F0\uFF08\u975E\u5FAE\u670D\u52A1\u540D\u79F0\uFF0C\u5FAE\u670D\u52A1\u540D\u79F0\u5728\u4EE3\u7801\u91CC\u8BBE\u7F6E\u4E86\uFF09 x.cloud.discovery.namespace=@x.cloud.discovery.namespace@
x.cloud.discovery.app-name=pps-application x.cloud.discovery.group=@x.cloud.discovery.group@
#\u7528\u6237\u540D x.cloud.discovery.username=@x.cloud.discovery.username@
x.cloud.discovery.username=@spring.cloud.servicecomb.credentials.account.name@ x.cloud.discovery.password=@x.cloud.discovery.password@
#\u5BC6\u7801 #\u914D\u7F6E\u4E2D\u5FC3
x.cloud.discovery.password=@spring.cloud.servicecomb.credentials.account.password@ x.cloud.config.server-addr=@x.cloud.config.server-addr@
x.cloud.config.namespace=@x.cloud.config.namespace@
x.cloud.config.group=@x.cloud.config.group@
x.cloud.config.file-extension=@x.cloud.config.file-extension@
x.cloud.config.username=@x.cloud.config.username@
x.cloud.config.password=@x.cloud.config.password@
...@@ -74,13 +74,20 @@ x.db.pps.core.system.user=root ...@@ -74,13 +74,20 @@ x.db.pps.core.system.user=root
x.db.pps.core.system.password=vwy69PQDfShqozf4ISXEoQ== x.db.pps.core.system.password=vwy69PQDfShqozf4ISXEoQ==
x.db.pps.core.system.naming=snake-case x.db.pps.core.system.naming=snake-case
#huawei-cse config \u4E50\u5F3A\uFF1A10.12.1.98 \u5B66\u71D5\uFF1A10.12.4.102 10.12.0.205 \u5218\u5F3A:10.12.6.213\u4E13\u7EBFcse\u5730\u5740:11.0.25.197 #nacos-\u6CE8\u518C\u4E2D\u5FC3
spring.cloud.servicecomb.discovery.address=http://127.0.0.1:30100 x.cloud.discovery.server-addr=192.168.0.128:8848
spring.cloud.servicecomb.config.serverType=kie x.cloud.discovery.namespace=public
spring.cloud.servicecomb.config.serverAddr=http://127.0.0.1:30110 x.cloud.discovery.group=DEFAULT_GROUP
spring.cloud.servicecomb.credentials.account.name= x.cloud.discovery.username=nacos
spring.cloud.servicecomb.credentials.account.password= x.cloud.discovery.password=nacos
spring.cloud.servicecomb.credentials.account.cipher=
#nacos-\u914D\u7F6E\u4E2D\u5FC3
x.cloud.config.server-addr=192.168.0.128:8848
x.cloud.config.namespace=piublic
x.cloud.config.group=DEFAULT_GROUP
x.cloud.config.file-extension=properties
x.cloud.config.username=nacos
x.cloud.config.password=nacos
# \u81EA\u5B9A\u4E49\u914D\u7F6E # \u81EA\u5B9A\u4E49\u914D\u7F6E
#weather.file.temp.path=D:/home/weather/temp/receive #weather.file.temp.path=D:/home/weather/temp/receive
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment