Skip to content

Commit edd71cd

Browse files
authored
Merge pull request liumapp#6 from niezhiliang/master
pdf编辑jar找不到字体目录bug修复
2 parents 3e76c8a + eb547bd commit edd71cd

19 files changed

+193
-65
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ windows跟Mac同样可以在上述文章中拿到下载链接
7676
<dependency>
7777
<groupId>com.liumapp.workable.converter</groupId>
7878
<artifactId>workable-converter</artifactId>
79-
<version>v1.2.0</version>
79+
<version>v1.4.2</version>
8080
</dependency>
8181
````
8282
* Gradle
@@ -320,6 +320,8 @@ itext7编辑pdf策略为TextConverter
320320

321321
编辑pdf注意事项
322322

323+
* 请在配置文件添加 com.liumapp.workable-converter=fontsPath: 字体文件目录,resources文件下有所需字体文件
324+
323325
* 请确保输入源文件后缀为PDF,输出源文件后缀也为PDF
324326

325327
* 编辑pdf参数需要new一个TextRequire来设置

data/txt2.pdf

-138 KB
Binary file not shown.

pom.xml

Lines changed: 15 additions & 15 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.4.1</version>
7+
<version>v1.4.2</version>
88
<packaging>jar</packaging>
99

1010
<properties>
@@ -195,20 +195,20 @@
195195
<stagingProgressTimeoutMinutes>20</stagingProgressTimeoutMinutes>
196196
</configuration>
197197
</plugin>
198-
<plugin>
199-
<groupId>org.apache.maven.plugins</groupId>
200-
<artifactId>maven-gpg-plugin</artifactId>
201-
<version>1.6</version>
202-
<executions>
203-
<execution>
204-
<id>sign-artifacts</id>
205-
<phase>verify</phase>
206-
<goals>
207-
<goal>sign</goal>
208-
</goals>
209-
</execution>
210-
</executions>
211-
</plugin>
198+
<!-- <plugin>-->
199+
<!-- <groupId>org.apache.maven.plugins</groupId>-->
200+
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
201+
<!-- <version>1.6</version>-->
202+
<!-- <executions>-->
203+
<!-- <execution>-->
204+
<!-- <id>sign-artifacts</id>-->
205+
<!-- <phase>verify</phase>-->
206+
<!-- <goals>-->
207+
<!-- <goal>sign</goal>-->
208+
<!-- </goals>-->
209+
<!-- </execution>-->
210+
<!-- </executions>-->
211+
<!-- </plugin>-->
212212
<plugin>
213213
<groupId>org.apache.maven.plugins</groupId>
214214
<artifactId>maven-javadoc-plugin</artifactId>

src/main/java/com/liumapp/workable/converter/WorkableConverter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import com.liumapp.workable.converter.core.Converter;
66
import com.liumapp.workable.converter.core.Parameter;
77
import com.liumapp.workable.converter.decorators.CheckPrefixFormatDecorator;
8+
import com.liumapp.workable.converter.decorators.CheckingParamsForTextConverterDecorator;
89
import com.liumapp.workable.converter.decorators.ConnectAndStartLocalLibreOfficeDecorator;
910
import com.liumapp.workable.converter.exceptions.ConvertFailedException;
1011
import com.liumapp.workable.converter.factory.ConverterConfigManager;
12+
import com.liumapp.workable.converter.strategies.TextConverter;
1113
import lombok.Getter;
1214
import lombok.Setter;
1315

@@ -36,7 +38,12 @@ public WorkableConverter() {
3638
*/
3739
@Override
3840
public boolean convert(Parameter require) throws ConvertFailedException {
39-
Converter converter = new ConnectAndStartLocalLibreOfficeDecorator(new CheckPrefixFormatDecorator(converterType));
41+
Converter converter;
42+
if (converterType instanceof TextConverter) {
43+
converter = new ConnectAndStartLocalLibreOfficeDecorator(new CheckPrefixFormatDecorator(new CheckingParamsForTextConverterDecorator(converterType)));
44+
} else {
45+
converter = new ConnectAndStartLocalLibreOfficeDecorator(new CheckPrefixFormatDecorator(converterType));
46+
}
4047
return converter.convert(require);
4148
}
4249
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public ConverterConfig loadConfig(ConfigurationNode node) throws NullPointerExce
4141
ConverterConfig converterConfig = new ConverterConfig(
4242
node.getNode("com", "liumapp", "workable-converter", "libreofficePath").getString(),
4343
node.getNode("com", "liumapp", "workable-converter", "libreofficePort").getInt(),
44-
node.getNode("com", "liumapp", "workable-converter", "tmpPath").getString()
44+
node.getNode("com", "liumapp", "workable-converter", "tmpPath").getString(),
45+
node.getNode("com","liumapp","workable-converter","fontsPath").getString()
4546
);
4647
return converterConfig;
4748
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public class TextRequire implements Parameter, Serializable {
1313
* pdf模板表单数据
1414
*/
1515
private List<PdfEditDTO> pdfEditDTOList;
16+
17+
/**
18+
* 字体文件路径
19+
*/
20+
private String fontsPath;
1621
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.liumapp.workable.converter.decorators;
2+
3+
import com.liumapp.workable.converter.config.ConvertRequire;
4+
import com.liumapp.workable.converter.core.Converter;
5+
import com.liumapp.workable.converter.core.Parameter;
6+
import com.liumapp.workable.converter.exceptions.ConvertFailedException;
7+
import com.liumapp.workable.converter.factory.ConverterConfigManager;
8+
import com.liumapp.workable.converter.templates.ConverterStrategyTemplates;
9+
10+
import java.io.IOException;
11+
12+
/**
13+
* file CheckingParamsForTextConverterDecorator.java
14+
* author liumapp
15+
* github https://github.com/liumapp
16+
17+
* homepage http://www.liumapp.com
18+
* date 2019/5/9
19+
*/
20+
public class CheckingParamsForTextConverterDecorator extends ConverterStrategyTemplates {
21+
22+
23+
public CheckingParamsForTextConverterDecorator(Converter converterStrategy) {
24+
super(converterStrategy);
25+
}
26+
27+
@Override
28+
protected boolean accordingRequire(ConvertRequire require) throws ConvertFailedException {
29+
return super.accordingRequire(require);
30+
}
31+
32+
@Override
33+
public boolean byFilePath(ConvertRequire require) throws ConvertFailedException {
34+
return false;
35+
}
36+
37+
38+
@Override
39+
public boolean byFileFolder(ConvertRequire require) throws ConvertFailedException {
40+
return false;
41+
}
42+
43+
@Override
44+
public boolean byStream(ConvertRequire require) throws ConvertFailedException {
45+
return false;
46+
}
47+
48+
@Override
49+
public boolean byBase64(ConvertRequire require) throws ConvertFailedException {
50+
return false;
51+
}
52+
53+
@Override
54+
protected String saveTmpFileByBase64(String fileBase64, String prefix) throws IOException {
55+
return super.saveTmpFileByBase64(fileBase64, prefix);
56+
}
57+
58+
@Override
59+
protected String saveTmpFileByBytes(byte[] fileBytes, String prefix) throws IOException {
60+
return super.saveTmpFileByBytes(fileBytes, prefix);
61+
}
62+
63+
@Override
64+
public boolean convert(Parameter require) throws ConvertFailedException {
65+
String ttfPath = ConverterConfigManager.getInstance().getParams().getFontPath();
66+
67+
if (ttfPath == null) {
68+
throw new ConvertFailedException("fonts path must need");
69+
}
70+
return super.convert(require);
71+
}
72+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public boolean convert(Parameter require) throws ConvertFailedException {
3838
}
3939

4040
@Override
41-
protected boolean byFilePath (ConvertRequire require) throws ConvertFailedException {
41+
public boolean byFilePath (ConvertRequire require) throws ConvertFailedException {
4242
logger.info("input file path is : " + require.getWaitingFilePath());
4343
logger.info("output file path is : " + require.getResultFilePath());
4444
File inputFile = new File(require.getWaitingFilePath());
@@ -54,12 +54,12 @@ protected boolean byFilePath (ConvertRequire require) throws ConvertFailedExcept
5454

5555
// todo
5656
@Override
57-
protected boolean byFileFolder(ConvertRequire require) throws ConvertFailedException {
57+
public boolean byFileFolder(ConvertRequire require) throws ConvertFailedException {
5858
throw new ConvertFailedException("common converter do not support convert by file to folder pattern right now");
5959
}
6060

6161
@Override
62-
protected boolean byStream (ConvertRequire require) throws ConvertFailedException {
62+
public boolean byStream (ConvertRequire require) throws ConvertFailedException {
6363
try {
6464
JodConverter.convert(require.getSrcStream()).as(require.getSrcFormat())
6565
.to(require.getDestStream()).as(require.getDestFormat()).execute();
@@ -73,7 +73,7 @@ protected boolean byStream (ConvertRequire require) throws ConvertFailedExceptio
7373
}
7474

7575
@Override
76-
protected boolean byBase64 (ConvertRequire require) throws ConvertFailedException {
76+
public boolean byBase64 (ConvertRequire require) throws ConvertFailedException {
7777
ByteArrayInputStream inputStream = null;
7878
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
7979
try {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ protected boolean accordingRequire(ConvertRequire require) throws ConvertFailedE
3333
throw new ConvertFailedException("can not found convert patterns .");
3434
};
3535

36-
protected abstract boolean byFilePath (ConvertRequire require) throws ConvertFailedException;
36+
public abstract boolean byFilePath (ConvertRequire require) throws ConvertFailedException;
3737

38-
protected abstract boolean byFileFolder (ConvertRequire require) throws ConvertFailedException;
38+
public abstract boolean byFileFolder (ConvertRequire require) throws ConvertFailedException;
3939

40-
protected abstract boolean byStream (ConvertRequire require) throws ConvertFailedException;
40+
public abstract boolean byStream (ConvertRequire require) throws ConvertFailedException;
4141

42-
protected abstract boolean byBase64 (ConvertRequire require) throws ConvertFailedException;
42+
public abstract boolean byBase64 (ConvertRequire require) throws ConvertFailedException;
4343

4444

4545
protected String saveTmpFileByBase64 (String fileBase64, String prefix) throws IOException {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected boolean accordingRequire(ConvertRequire require) throws ConvertFailedE
4343
}
4444

4545
@Override
46-
protected boolean byFilePath(ConvertRequire require) throws ConvertFailedException {
46+
public boolean byFilePath(ConvertRequire require) throws ConvertFailedException {
4747
logger.info("get waiting convert file : " + require.getWaitingFilePath());
4848
logger.info("get result file path : " + require.getResultFilePath());
4949
File inputFile = new File(require.getWaitingFilePath());
@@ -57,17 +57,17 @@ protected boolean byFilePath(ConvertRequire require) throws ConvertFailedExcepti
5757
}
5858

5959
@Override
60-
protected boolean byFileFolder(ConvertRequire require) throws ConvertFailedException {
60+
public boolean byFileFolder(ConvertRequire require) throws ConvertFailedException {
6161
return false;
6262
}
6363

6464
@Override
65-
protected boolean byStream(ConvertRequire require) throws ConvertFailedException {
65+
public boolean byStream(ConvertRequire require) throws ConvertFailedException {
6666
return false;
6767
}
6868

6969
@Override
70-
protected boolean byBase64(ConvertRequire require) throws ConvertFailedException {
70+
public boolean byBase64(ConvertRequire require) throws ConvertFailedException {
7171
return false;
7272
}
7373
}

0 commit comments

Comments
 (0)