Skip to content

Commit adf9bca

Browse files
committed
Merge branch 'master' of github.com:liumapp/workable-converter
2 parents 180cd7d + b76f072 commit adf9bca

File tree

6 files changed

+43
-13
lines changed

6 files changed

+43
-13
lines changed

pom.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.liumapp.workable.converter</groupId>
66
<artifactId>workable-converter</artifactId>
7-
<version>v1.2.0</version>
7+
<version>v1.3.0</version>
88
<packaging>jar</packaging>
99

1010
<properties>
@@ -88,15 +88,13 @@
8888
<artifactId>pdfbox-tools</artifactId>
8989
<version>2.0.12</version>
9090
</dependency>
91-
92-
<!--itext require-->
9391
<dependency>
9492
<groupId>com.itextpdf</groupId>
9593
<artifactId>itext7-core</artifactId>
9694
<version>7.1.0</version>
9795
<type>pom</type>
9896
</dependency>
99-
97+
10098
<!-- helper -->
10199
<dependency>
102100
<groupId>org.projectlombok</groupId>
@@ -280,5 +278,4 @@
280278
</repository>
281279
</distributionManagement>
282280

283-
284281
</project>

src/main/java/com/liumapp/workable/converter/config/PdfEditDTO.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import com.liumapp.workable.converter.enums.FontType;
44
import lombok.Data;
55

6+
import java.util.Arrays;
7+
import java.util.List;
8+
69
@Data
710
public class PdfEditDTO {
811

@@ -14,12 +17,12 @@ public class PdfEditDTO {
1417
/**
1518
* 内容宽
1619
*/
17-
private Integer width;
20+
private Float width;
1821

1922
/**
2023
* 内容高
2124
*/
22-
private Integer heitht;
25+
private Float heitht;
2326

2427
/**
2528
* 占位符别名
@@ -47,8 +50,19 @@ public class PdfEditDTO {
4750
private String text;
4851

4952
/**
50-
* 字体类型(枚举)
53+
* 字体类型(枚举) 默认宋体
5154
*/
52-
private FontType fontType;
55+
private FontType fontType = FontType.SIMHEI;
56+
57+
private Integer fontTypeNum = 0;
58+
5359

60+
public FontType getFontType() {
61+
List<FontType> fontTypeList =
62+
Arrays.asList(FontType.SIMSUN,FontType.SIMKAI, FontType.SIMHEI,FontType.SIMYOU,FontType.STKAITI);
63+
if (this.fontTypeNum >= fontTypeList.size()) {
64+
return fontTypeList.get(0);
65+
}
66+
return fontTypeList.get(this.fontTypeNum);
67+
}
5468
}

src/main/java/com/liumapp/workable/converter/enums/FontType.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,31 @@
88
public enum FontType {
99

1010
/**
11-
* 华文幼圆
11+
* 宋体
1212
*/
13-
SIMYOU(1,"SIMYOU.TTF"),
13+
SIMSUN(0,"SIMSUN.TTF"),
1414

1515
/**
1616
* 楷体
1717
*/
18-
STKAITI(2,"STKAITI.TTF")
18+
SIMKAI(1,"SIMKAI.TTF"),
19+
20+
/**
21+
* 黑体
22+
*/
23+
SIMHEI(2,"SIMHEI.TTF"),
24+
25+
/**
26+
* 华文幼圆
27+
*/
28+
SIMYOU(3,"SIMYOU.TTF"),
29+
30+
/**
31+
* 华文楷体
32+
*/
33+
STKAITI(4,"STKAITI.TTF"),
34+
35+
1936

2037
;
2138

src/main/java/com/liumapp/workable/converter/strategies/TextConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ protected boolean byFilePath(ConvertRequire require) throws ConvertFailedExcepti
4040
//font
4141
Rectangle rectangle;
4242
for (PdfEditDTO editDTO : require.getTextRequire().getPdfEditDTOList()) {
43-
String ttfPath = this.getClass().getClassLoader().getResource("./font/"+editDTO.getFontType().getFont()).getPath();
43+
ClassLoader classLoader = this.getClass().getClassLoader();
44+
System.out.println(editDTO.getFontType().getType());
45+
String ttfPath = classLoader.getResource("./font/"+editDTO.getFontType().getFont()).getPath();
4446
PdfTextFormField pdfTextFormField;
4547
// 读取ttf字体文件
4648
FontProgram fontProgram = FontProgramFactory.createFont(ttfPath);

src/main/resources/font/SIMKAI.TTF

11.2 MB
Binary file not shown.

src/main/resources/font/SIMSUN.TTF

14.6 MB
Binary file not shown.

0 commit comments

Comments
 (0)