gpt4 book ai didi

java - AFP 查看器 TLE 浏览器中的组编号在 AFP 合并后不会按顺序增加

转载 作者:行者123 更新时间:2023-12-01 21:27:52 25 4
gpt4 key购买 nike

我使用 java 实用程序合并了三个 AFP 文件,该实用程序从文件中读取字节并使用 FileOutputStream Java 类写入输出流。合并的 AFP 文件看起来不错,但是打开 AFP 文件后,在强制代码 AFPViewer(在 TLE 浏览器中)中检查 TLE(标签逻辑元素)信息时,所有合并到 GRP 的文件的组编号保持相同: PGP00001

请告诉我如何合并文件,以便 GRP 编号在 AFP 合并后开始按顺序增加。结果应为 GRP:PGP00001、GRP:PGP00002 和 GRP:PGP00003

使用以下代码合并使用 Apache FOP XSL-FO 生成的每个 AFP 文件:

public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);

// Get the size of the file
long length = file.length();

// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];

// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}

// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}

// Close the input stream and return bytes
is.close();
return bytes;
}

主要功能:

public static void main(String[] args) {
try {
FileOutputStream fos = new FileOutputStream("C:\\dev\\harry\\ETCC_data\\output.afp");
byte[] bytes1 = getBytesFromFile(new File(filePath1));
byte[] bytes2 = getBytesFromFile(new File(filePath2));
fos.write(bytes1);
fos.write(bytes2);
fos.flush();
fos.close();
}
catch(FileNotFoundException ex) { System.out.println("FileNotFoundException : " + ex); }
catch(IOException ioe) { System.out.println("IOException : " + ioe); }
}

最佳答案

afplib 确实有一些关于如何正确地将多个 AFP 文件合并为一个的示例代码:

https://github.com/yan74/afplib/wiki/Samples#afpcombinejava https://github.com/yan74/afplib/blob/master/org.afplib.samples/src/main/java/org/afplib/samples/AfpCombine.java

package org.afplib.samples;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;

import org.junit.Test;

public class AfpCombineTest {

@Test
public void testRun() throws IOException {
new File("tmp").mkdirs();
AfpCombine combine = new AfpCombine("tmp/out.afp", new String[] { "testdata/start.afp", "testdata/start.afp" , "testdata/ende.afp" , "testdata/ende.afp"});
combine.run();
}

}

关于java - AFP 查看器 TLE 浏览器中的组编号在 AFP 合并后不会按顺序增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37809969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com