我有一个法新社文件,我需要使用c#.Based获取文件中存在的页数,我必须为法新社文件创建一个打印队列,所以可以使用c#或java吗?我没有在互联网上找到任何用于获取计数的支持代码。
发布于 2019-01-11 06:21:37
afplib有一些示例代码可以做到这一点。基本上,您需要迭代AFP中的所有结构化字段,并计算BPG (Begin Page)的数量。此代码片段摘自here
try (AfpInputStream in = new AfpInputStream(
new BufferedInputStream(new FileInputStream(s)))) {
int pages = 0;
int resources = 0;
SF sf;
while((sf = in.readStructuredField()) != null) {
log.trace("{}", sf);
switch(sf.getId()) {
case SFName.BPG_VALUE:
pages++;
if(progress && pages % 1000 == 0)
System.out.print(String.format("\r%06d %04d %s", pages, resources, s));
break;
case SFName.BRS_VALUE:
resources++;
if(progress && resources % 1000 == 0)
System.out.print(String.format("\r%06d %04d %s", pages, resources, s));
break;
}
}
if(progress)
System.out.print("\r");
System.out.println(String.format("%06d %04d %s", pages, resources, s));
} catch (Exception e) {
}https://stackoverflow.com/questions/54131318
复制相似问题