Skip to content

Commit

Permalink
添加事件处理文档
Browse files Browse the repository at this point in the history
2.2.6
  • Loading branch information
Trisia committed Jan 11, 2024
1 parent 26f08ba commit 001673b
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 26 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Maven项目引入依赖
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-full</artifactId>
<version>2.2.5</version>
<version>2.2.6</version>
</dependency>
```

Expand Down Expand Up @@ -96,8 +96,9 @@ public class HelloWorld {
- [OFD R&W 转换OFD/OFD导出 ](./ofdrw-converter/README.md)
- [OFD R&W 字形数据解析](./ofdrw-converter/src/main/java/org/ofdrw/converter/font/README.md)
- [OFD R&W 文档合并](./ofdrw-tool/README.md)
- [OFD R&W 区域占位区块(类表单效果) ***New***](./ofdrw-layout/doc/areaholderblock/README.md)
- [OFD R&W 单元格元素 使用指南 ***New***](./ofdrw-layout/doc/cell/README.md)
- [OFD R&W 区域占位区块(类表单效果)](./ofdrw-layout/doc/areaholderblock/README.md)
- [OFD R&W 单元格元素 使用指南](./ofdrw-layout/doc/cell/README.md)
- [OFD R&W 内容生成 事件处理 ***New***](./ofdrw-layout/doc/onpage/README.md)

### 相关解决方案

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-converter/doc/CONVERTER.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ OFDRW提供了将其它类型媒体文件或文档转换成OFD文档内容功能
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-converter</artifactId>
<version>2.2.5</version>
<version>2.2.6</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-converter/doc/EXPORTER.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ OFDRW提供了将OFD文档导出为其他格式文档的能力,如导出为图
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-converter</artifactId>
<version>2.2.5</version>
<version>2.2.6</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-crypto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-font/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-full/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-gm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-graphics2d/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ OFDRW已经有Canvas元素了为什么要实现`Graphics2D`接口?
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-graphics2d</artifactId>
<version>2.2.5</version>
<version>2.2.6</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-graphics2d/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-gv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ofdrw-gv</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ofdrw-gv/src/main/java/org/ofdrw/gv/GlobalVar.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ final public class GlobalVar {
/**
* OFD Reader and Writer 版本号
*/
public static final String Version = "2.2.5";
public static final String Version = "2.2.6";
}
60 changes: 60 additions & 0 deletions ofdrw-layout/doc/onpage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# OFDRW 内容生成 事件处理

为了帮助开发者对OFD内容生成的不同阶段对文档进行干预,OFDRW提供了系列事件处理接口。

包括以下事件:

- **页事件(onPage)**:在每个页面内容生成之前触发。
- **渲染完成事件(onRenderFinish)**:在所有页面生成完成之后触发。

## 页事件

在每个页面内容生成之前触发,通过对该事件的处理可以在虚拟页面中的内容生成OFD Content.xml 前对页面进行干预,例如:向页面中添加页头、页脚、水印等。

事件处理方式如下:

1. 实现 `VPageHandler` 接口。
2. 注册 事件处理器。

```java
class Main {
public static void main(String[] args) {
try (OFDDoc ofdDoc = new OFDDoc(path)) {
// 1. 使用匿名类实现 VPageHandler 接口
// 2. 注册事件处理器
ofdDoc.onPage((page) -> {
// 对 page 追加内容
});
// ...
}
}
}
```

完整示例代码见:[OFDDocTest.java #setOnPage](../../src/test/java/org/ofdrw/layout/OFDDocTest.java)

## 渲染完成事件

在所有页面生成完成之后触发,通过对该事件的处理可以在所有页面生成OFD Content.xml 后对文档进行干预,例如:添加动作点、添加扩展内容等。

事件处理方式如下:

1. 实现 `RenderFinishHandler` 接口。
2. 注册 事件处理器。

```java
class Main {
public static void main(String[] args) {
try (OFDDoc ofdDoc = new OFDDoc(path)) {
// 1. 使用匿名类实现 RenderFinishHandler 接口
// 2. 注册事件处理器
ofdDoc.onRenderFinish((doc) -> {
// 对 doc 追加内容
});
// ...
}
}
}
```

完整示例代码见:[OFDDocTest.java #onRenderFinished](../../src/test/java/org/ofdrw/layout/OFDDocTest.java)
2 changes: 1 addition & 1 deletion ofdrw-layout/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<artifactId>ofdrw-layout</artifactId>

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-layout/src/main/java/org/ofdrw/layout/OFDDoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public VPageHandler getOnPage() {
* @param handler 页面解析前处理器
* @return this
*/
public OFDDoc setOnPage(VPageHandler handler) {
public OFDDoc onPage(VPageHandler handler) {
this.onPageHandler = handler;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @author 权观宇
* @since 2024-1-11 18:43:55
*/
@FunctionalInterface
public interface VPageHandler {
/**
* 执行处理
Expand Down
4 changes: 2 additions & 2 deletions ofdrw-layout/src/test/java/org/ofdrw/layout/OFDDocTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ void setOnPage() throws Exception {
Path path = Paths.get("target/auto-page-number.ofd");
try (OFDDoc ofdDoc = new OFDDoc(path)) {
// 添加页码
ofdDoc.setOnPage((page) -> {
ofdDoc.onPage((page) -> {
System.out.println("第 " + page.getPageNum() + " 页");

// 210mm x 297mm
Expand Down Expand Up @@ -795,7 +795,7 @@ void setOnPage2() throws Exception {
Path path = Paths.get("target/auto-page-number-2.ofd");
try (OFDDoc ofdDoc = new OFDDoc(path)) {
// 添加页码
ofdDoc.setOnPage((page) -> {
ofdDoc.onPage((page) -> {
System.out.println("第 " + page.getPageNum() + " 页");
PageLayout style = page.getStyle();
Canvas canvas = new Canvas(0, 0, style.getWidth(), style.getHeight());
Expand Down
2 changes: 1 addition & 1 deletion ofdrw-pkg/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<description>OFD文件的容器以及用于文档的打包</description>
Expand Down
2 changes: 1 addition & 1 deletion ofdrw-reader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-sign/doc/quickstart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-sign</artifactId>
<version>2.2.5</version>
<version>2.2.6</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-sign/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-tool</artifactId>
<version>2.2.5</version>
<version>2.2.6</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ofdrw</artifactId>
<groupId>org.ofdrw</groupId>
<version>2.2.5</version>
<version>2.2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw</artifactId>
<packaging>pom</packaging>
<version>2.2.5</version>
<version>2.2.6</version>

<url>https://github.com/ofdrw/ofdrw</url>
<description>Open Fixed layout Document Reader And Writer Libary(OFD-RW) provider developers to generate ofd
Expand Down

0 comments on commit 001673b

Please sign in to comment.