summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/oberdiek/test/ExtractRotate.java
blob: 0151be2363dea4c64d2ba9ed790f32442a4f106c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * ExtractRotate.java
 *
 * Copyright (C) 2007 by Heiko Oberdiek <heiko.oberdiek at googlemail.com>
 *
 * Requires: PDFBox (http://www.pdfbox.org/)
 *
 * Syntax: java ExtractRotate <pdffile> <textfile>
 *
 * The <pdffile> is analyzed and for each page its rotation
 * setting is printed in the <textfile>. Example:
 *   /Page 1 /Rotate 0
 *   /Page 2 /Rotate 90
 */
import java.io.FileInputStream;
import java.io.FileWriter;
import org.pdfbox.pdfparser.PDFParser;
import org.pdfbox.pdmodel.PDDocument;
import org.pdfbox.pdmodel.PDDocumentCatalog;
import org.pdfbox.pdmodel.PDPage;

public class ExtractRotate {

    public static void main(String[] args) {
        try {
            String infile = args[0];
            String outfile = args[1];
            FileWriter out = new FileWriter(outfile);
            PDFParser parser =
                    new PDFParser(new FileInputStream(infile));
            parser.parse();
            PDDocument document = parser.getPDDocument();
            PDDocumentCatalog catalog = document.getDocumentCatalog();
            int i = 0;
            for (Object page: catalog.getAllPages()) {
                i++;
                out.write("/Page " + i + " " + "/Rotate "
                        + ((PDPage)page).findRotation() + "\n");
            }
            document.close();
            out.close();
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}