I have an AFP file for which i need to get the count of the page present in the file using c#.Based on the file count i have to create a print queue for AFP file so is it possible using c# or java ?. I didn't find any support code for getting the count in internet.
Asked
Active
Viewed 787 times
1 Answers
1
afplib has some sample code to do this. Basically you need to iterate over all structured fields in your AFP and count the number of BPG (Begin Page). This snippet is taken from 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) {
}

Yan Hackl-Feldbusch
- 111
- 2