Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFP in Java Eclipse

Tags:

java

eclipse

afp

I've been looking for days to find a way how to read in an Advanced Function Presentation file in so that it writes out on the console some information about the file (e.g. how many documents, how many pages a document has...).

I have successfully read in the number of byte of the AFP file.

public static void main(String[] args) {
  String filename = "xxx.afp";
  try {
    DataInputStream in = new DataInputStream(
                           new BufferedInputStream(
                             new FileInputStream(filename))))
    System.out.println(in.read());
  }
}

Thanks in advance!

like image 398
user2902426 Avatar asked Sep 25 '26 06:09

user2902426


2 Answers

Have you looked at AFP Renderer?

If this doesn't do what you want, then I am afraid that you are going to need to read the specifications, which you can get by following these instructions.

like image 83
Paul Wagland Avatar answered Sep 27 '26 18:09

Paul Wagland


The objects in an AFP file are tagged by so called triplets. You can think of them like 3-letter mnemonics. Typically they have a "begin" and "end" delimiter for the respective objects. The triplets are introduced by an eye-catcher byte sequence, 0x5A if I remember correctly (to be checked).

So, to count the pages you should go through your DataInputStream and count the occurrences of the "begin page" triplet. If you want to be very accurate you can try to match them with an "end page" triplet. The triplet specific hex values is something to check in the specification.

There are also commercial SDKs available.

like image 39
Jörg Palmer Avatar answered Sep 27 '26 19:09

Jörg Palmer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!