Skip to content

Commit

Permalink
1.19.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Trisia committed Aug 22, 2022
1 parent 0ac827c commit 4e987cf
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ OFD Reader & Writer 开源的OFD处理库,支持文档生成、数字签名、
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-full</artifactId>
<version>1.19.0</version>
<version>1.19.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion ofdrw-converter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pom引入相关模块
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-converter</artifactId>
<version>1.19.0</version>
<version>1.19.1</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>1.19.0</version>
<version>1.19.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,20 @@ public PdfPage makePage(PdfDocument pdf, PageInfo pageInfo) throws IOException {
/**
* 添加附件
*
* @param pdf
* @param ofdReader
* @throws IOException
* @param pdf PDF文档对象
* @param ofdReader OFD解析器
* @throws IOException IO异常
*/
public void addAttachments(PdfDocument pdf, OFDReader ofdReader) throws IOException {
// 获取OFD中所有附件
List<CT_Attachment> attachmentList = ofdReader.getAttachmentList();
for (CT_Attachment attachment : attachmentList) {
Path attFile = ofdReader.getAttachmentFile(attachment);
byte[] fileBytes = Files.readAllBytes(attFile);
String fileName = attFile.getFileName().toString();
String displayFileName = StringUtils.isBlank(attachment.getAttachmentName()) ? fileName :
attachment.getAttachmentName().concat(fileName.contains(".") ?
final String attachmentName = attachment.getAttachmentName();
String displayFileName = StringUtils.isBlank(attachmentName) ? fileName :
attachmentName.concat(fileName.contains(".") ?
fileName.substring(fileName.lastIndexOf(".")) : "");
PdfFileSpec fs = PdfFileSpec.createEmbeddedFileSpec(pdf, fileBytes, null, displayFileName,
null);
Expand Down Expand Up @@ -545,7 +547,7 @@ private void path(PdfCanvas pdfCanvas, ST_Box box, ST_Box sealBox, ST_Box annotB

private void writeImage(ResourceManage resMgt, PdfCanvas pdfCanvas, ST_Box box, ImageObject imageObject, ST_Box annotBox, Integer compositeObjectAlpha, ST_Box compositeObjectBoundary, ST_Array compositeObjectCTM) throws IOException {
final ST_RefID resourceID = imageObject.getResourceID();
if (resourceID == null){
if (resourceID == null) {
return;
}
byte[] imageByteArray = resMgt.getImageByteArray(resourceID.toString());
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>1.19.0</version>
<version>1.19.1</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>1.19.0</version>
<version>1.19.1</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>1.19.0</version>
<version>1.19.1</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>1.19.0</version>
<version>1.19.1</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>1.19.0</version>
<version>1.19.1</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>1.19.0</version>
<version>1.19.1</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 = "1.19.0";
public static final String Version = "1.19.1";
}
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>1.19.0</version>
<version>1.19.1</version>
</parent>
<artifactId>ofdrw-layout</artifactId>

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>1.19.0</version>
<version>1.19.1</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>1.19.0</version>
<version>1.19.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
113 changes: 93 additions & 20 deletions ofdrw-reader/src/main/java/org/ofdrw/reader/OFDReader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.ofdrw.reader;

import org.apache.commons.compress.utils.Lists;
import org.apache.commons.io.FileUtils;
import org.dom4j.DocumentException;
import org.ofdrw.core.OFDElement;
Expand Down Expand Up @@ -564,8 +563,10 @@ public ResourceLocator getResourceLocator() {

/**
* 获取所有附件对象
* <p>
* 注意该对象均为只读
*
* @return 如果附件或附件记录不存在,那么返还null
* @return 附件数组,如果没有附件返还空数组
* @throws BadOFDException 文档结构损坏
*/
public List<CT_Attachment> getAttachmentList() {
Expand All @@ -582,23 +583,29 @@ public List<CT_Attachment> getAttachmentList() {
}
ST_Loc attachmentsLoc = document.getAttachments();
if (attachmentsLoc == null || (!rl.exist(attachmentsLoc.toString()))) {
// 文档中没有附件目录文件
return Lists.newArrayList();
return new ArrayList<>();
}
try {
// 获取附件目录
attachments = rl.get(attachmentsLoc, Attachments::new);
} catch (FileNotFoundException | DocumentException e) {
System.err.println(">> 无法获取或解析Attachments.xml: " + e.getMessage());
return Lists.newArrayList();
return new ArrayList<>();
}

String parent = attachmentsLoc.parent();
if (parent != null) {
rl.cd(parent);
}

return attachments.getAttachments();
List<CT_Attachment> res = attachments.getAttachments();
if (!res.isEmpty()) {
// 设置文件为绝对路径,外部读取时工作路径不正确导致的文件不存在。
for (CT_Attachment item : res) {
item.setFileLoc(rl.getAbsTo(item.getFileLoc()));
}
}
return res;
} finally {
rl.restore();
}
Expand All @@ -609,34 +616,73 @@ public List<CT_Attachment> getAttachmentList() {
* <p>
* 注意:该文件会在Close Reader时候被删除,请在之前复制到其他地方
*
* @param name 附件名称
* @return 附件文件路径
*/
public Path getAttachmentFile(String name) {
public Path getAttachmentFile(CT_Attachment attachment) {
if (attachment == null) {
return null;
}
ST_Loc fileLoc = attachment.getFileLoc();
try {
return rl.getFile(fileLoc);
} catch (FileNotFoundException e) {
System.err.println(">> 无法根据附件对象的描述获取到附件: " + fileLoc.toString());
return null;
}
}

/**
* 获取附件对象
* <p>
* 该方法不会恢复资源定位器
*
* @param name 附件名称
* @return 附件对象
*/
public CT_Attachment getAttachment(String name) {
if (name == null || name.trim().length() == 0) {
return null;
}
CT_Attachment attachment = getAttachment(name);
return getAttachmentFile(attachment);

List<CT_Attachment> attachmentList = this.getAttachmentList();

for (CT_Attachment attachment : attachmentList) {
// 寻找匹配名称的附件
if (attachment.getAttachmentName().equals(name)) {
return attachment;
}
}
return null;
}


/**
* 获取附件文件
* <p>
* 注意:该文件会在Close Reader时候被删除,请在之前复制到其他地方
*
* @param name 附件名称
* @return 附件文件路径
*/
public Path getAttachmentFile(CT_Attachment attachment) {
if (attachment == null) {
public Path getAttachmentFile(String name) {
if (name == null || name.trim().length() == 0) {
return null;
}
ST_Loc fileLoc = attachment.getFileLoc();
rl.save();
try {
return rl.getFile(fileLoc);
} catch (FileNotFoundException e) {
System.err.println(">> 无法根据附件对象的描述获取到附件: " + fileLoc.toString());
return null;
CT_Attachment attachment = getAttachment(name, rl);
if (attachment == null) {
return null;
}
ST_Loc fileLoc = attachment.getFileLoc();
try {
return rl.getFile(fileLoc);
} catch (FileNotFoundException e) {
System.err.println(">> 无法根据附件对象的描述获取到附件: " + fileLoc.toString());
return null;
}
} finally {
rl.restore();
}
}

Expand All @@ -646,16 +692,42 @@ public Path getAttachmentFile(CT_Attachment attachment) {
* 该方法不会恢复资源定位器
*
* @param name 附件名称
* @param rl 资源定位器
* @return 附件对象
*/
public CT_Attachment getAttachment(String name) {
private CT_Attachment getAttachment(String name, ResourceLocator rl) {
if (name == null || name.trim().length() == 0) {
return null;
}

List<CT_Attachment> attachmentList = this.getAttachmentList();
DocDir docDir = ofdDir.obtainDocDefault();
rl.cd(docDir);
Document document = null;
Attachments attachments = null;
try {
document = docDir.getDocument();
} catch (FileNotFoundException | DocumentException e) {
throw new BadOFDException(e);
}
ST_Loc attachmentsLoc = document.getAttachments();
if (attachmentsLoc == null || (!rl.exist(attachmentsLoc.toString()))) {
// 文档中没有附件目录文件
return null;
}
try {
// 获取附件目录
attachments = rl.get(attachmentsLoc, Attachments::new);
} catch (FileNotFoundException | DocumentException e) {
System.err.println(">> 无法获取或解析Attachments.xml: " + e.getMessage());
return null;
}

for (CT_Attachment attachment : attachmentList) {
String parent = attachmentsLoc.parent();
if (parent != null) {
rl.cd(parent);
}

for (CT_Attachment attachment : attachments.getAttachments()) {
// 寻找匹配名称的附件
if (attachment.getAttachmentName().equals(name)) {
return attachment;
Expand All @@ -664,6 +736,7 @@ public CT_Attachment getAttachment(String name) {
return null;
}


/**
* 获取默认文档中的签章信息
*
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>1.19.0</version>
<version>1.19.1</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>1.19.0</version>
<version>1.19.1</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 @@ -9,7 +9,7 @@
<dependency>
<groupId>org.ofdrw</groupId>
<artifactId>ofdrw-tool</artifactId>
<version>1.19.0</version>
<version>1.19.1</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>1.19.0</version>
<version>1.19.1</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>1.19.0</version>
<version>1.19.1</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
Loading

0 comments on commit 4e987cf

Please sign in to comment.